diff options
author | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2008-05-09 18:15:17 +0200 |
---|---|---|
committer | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2008-05-09 18:15:17 +0200 |
commit | 706317bb88fef28abbcb875a266608e44e56048c (patch) | |
tree | 77a312f96b2e9dd62568a3979a971ff6adfd207e | |
parent | 902d66eb8304ccffdb683b7130e9f548011b8d30 (diff) | |
download | xine-lib-706317bb88fef28abbcb875a266608e44e56048c.tar.gz xine-lib-706317bb88fef28abbcb875a266608e44e56048c.tar.bz2 |
Use size_t rather than int to store the return value of strlen().
Also, don't reset buffers when we're just going to run a snprintf()
call, and avoid multiple calls to strlen() when we're appending to it.
-rw-r--r-- | src/input/input_cdda.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 047916a07..990f4d8b0 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1307,20 +1307,17 @@ static void _cdda_mkdir_recursive_safe(xine_t *xine, char *path) { if(p && strlen(p)) { #ifdef WIN32 - if (*buf2 != '\0') { + if (*buf2 != '\0') { #endif - - int size = strlen(buf2); - snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); - + size_t size = strlen(buf2); + snprintf(buf2 + size, sizeof(buf2) - size, "/%s", p); #ifdef WIN32 - } - else { - snprintf(buf2, sizeof(buf2), "%s", p); - } - + } + else { + snprintf(buf2, sizeof(buf2), "%s", p); + } #endif /* WIN32 */ - + _cdda_mkdir_safe(xine, buf2); } } @@ -1438,13 +1435,13 @@ static int _cdda_cddb_handle_code(char *buf) { */ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) { char cdir[XINE_PATH_MAX + XINE_NAME_MAX + 1]; + size_t cdir_size = 0; DIR *dir; if(this == NULL) return 0; - memset(&cdir, 0, sizeof(cdir)); - snprintf(cdir, sizeof(cdir), "%s", this->cddb.cache_dir); + cdir_size = snprintf(cdir, sizeof(cdir), "%s", this->cddb.cache_dir); if((dir = opendir(cdir)) != NULL) { struct dirent *pdir; @@ -1452,14 +1449,12 @@ static int _cdda_load_cached_cddb_infos(cdda_input_plugin_t *this) { while((pdir = readdir(dir)) != NULL) { char discid[9]; - memset(&discid, 0, sizeof(discid)); snprintf(discid, sizeof(discid), "%08lx", this->cddb.disc_id); if(!strcasecmp(pdir->d_name, discid)) { FILE *fd; - int size = strlen(cdir); - snprintf(cdir + size, sizeof(cdir) - size, "/%s", discid); + cdir_size += snprintf(cdir + cdir_size, sizeof(cdir) - cdir_size, "/%s", discid); if((fd = fopen(cdir, "r")) == NULL) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_cdda: fopen(%s) failed: %s.\n", cdir, strerror(errno)); @@ -1812,7 +1807,7 @@ static int _cdda_cddb_retrieve(cdda_input_plugin_t *this) { while (strcmp(buffer, ".")) { char buf[2048]; int tnum; - int bufsize = strlen(buffercache); + size_t bufsize = strlen(buffercache); memset(&buffer, 0, sizeof(buffer)); _cdda_cddb_socket_read(this, buffer, sizeof(buffer) - 1); |