diff options
Diffstat (limited to 'src/input/input_file.c')
-rw-r--r-- | src/input/input_file.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/src/input/input_file.c b/src/input/input_file.c index fd2b0e733..91513194c 100644 --- a/src/input/input_file.c +++ b/src/input/input_file.c @@ -82,8 +82,8 @@ typedef struct { int fh; #ifdef HAVE_MMAP int mmap_on; - void *mmap_base; - void *mmap_curr; + uint8_t *mmap_base; + uint8_t *mmap_curr; off_t mmap_len; #endif char *mrl; @@ -144,7 +144,7 @@ static int check_mmap_file(file_input_plugin_t *this) { } #endif -static off_t file_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) { +static off_t file_plugin_read (input_plugin_t *this_gen, void *buf, off_t len) { file_input_plugin_t *this = (file_input_plugin_t *) this_gen; #ifdef HAVE_MMAP @@ -223,7 +223,7 @@ static off_t file_plugin_seek (input_plugin_t *this_gen, off_t offset, int origi #ifdef HAVE_MMAP /* Simulate f*() library calls */ if ( check_mmap_file(this) ) { - void *new_point = this->mmap_curr; + uint8_t *new_point = this->mmap_curr; switch(origin) { case SEEK_SET: new_point = this->mmap_base + offset; break; case SEEK_CUR: new_point = this->mmap_curr + offset; break; @@ -327,31 +327,8 @@ static void file_plugin_dispose (input_plugin_t *this_gen ) { } static char *decode_uri (char *uri) { - - int len = strlen (uri); - int i; - uri = strdup(uri); - - for (i=0; i<len; i++) { - - if ( (uri[i]=='%') && (i<(len-2)) ) { - - int c; - - if ( sscanf (&uri[i+1], "%02x", &c) == 1) { - - uri[i]= (char) c; - - memmove (uri+i+1, uri+i+3, len-i-3); - - len-=2; - } - } - } - - uri[len] = 0; - + _x_mrl_unescape (uri); return uri; } @@ -423,10 +400,16 @@ static int file_plugin_open (input_plugin_t *this_gen ) { } #ifdef HAVE_MMAP - if ( (this->mmap_base = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, this->fh, 0)) != (void*)-1 ) { - this->mmap_on = 1; - this->mmap_curr = this->mmap_base; - this->mmap_len = sbuf.st_size; + { + size_t tmp_size = sbuf.st_size; /* may cause truncation - if it does, DON'T mmap! */ + if ((tmp_size == sbuf.st_size) && + ( (this->mmap_base = mmap(NULL, tmp_size, PROT_READ, MAP_SHARED, this->fh, 0)) != (void*)-1 )) { + this->mmap_on = 1; + this->mmap_curr = this->mmap_base; + this->mmap_len = sbuf.st_size; + } else { + this->mmap_base = NULL; + } } #endif @@ -723,9 +706,9 @@ static xine_mrl_t **file_class_get_dir (input_class_t *this_gen, return NULL; } - dir_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES); - hide_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES); - norm_files = (xine_mrl_t *) xine_xmalloc(sizeof(xine_mrl_t) * MAXFILES); + dir_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t)); + hide_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t)); + norm_files = (xine_mrl_t *) xine_xcalloc(MAXFILES, sizeof(xine_mrl_t)); while((pdirent = readdir(pdir)) != NULL) { |