diff --git a/apps/misc.c b/apps/misc.c index 85ab396754..a85169598f 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1120,3 +1120,22 @@ bool dir_exists(const char *path) closedir(d); return true; } + +/* + * removes the extension of filename (if it doesn't start with a .) + * puts the result in buffer + */ +char *strip_extension(const char *filename, char *buffer) +{ + int dotpos; + char *dot = strrchr(filename, '.'); + if (dot != 0 && filename[0] != '.') + { + dotpos = dot - filename; + strncpy(buffer, filename, dotpos); + buffer[dotpos] = '\0'; + } + else + strcpy(buffer, filename); + return buffer; +} diff --git a/apps/misc.h b/apps/misc.h index 590ccf013f..99eadc443a 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -118,5 +118,10 @@ char* strrsplt(char* str, int c); bool file_exists(const char *file); bool dir_exists(const char *path); +/* + * removes the extension of filename (if it doesn't start with a .) + * puts the result in buffer + */ +char *strip_extension(const char *filename, char *buffer); #endif /* MISC_H */ diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index 6761cfc67a..0e45d9a935 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c @@ -62,34 +62,6 @@ static char* strip_filename(char* buf, int buf_size, const char* fullpath) return (sep + 1); } -/* Strip extension from a filename. - * - * buf - buffer to output the result to. - * buf_size - size of the output buffer buffer. - * file - filename to strip extension from. - * - * Return value is a pointer to buf, which contains the result. - */ -static char* strip_extension(char* buf, int buf_size, const char* file) -{ - char* sep; - int len; - - if (!buf || buf_size <= 0 || !file) - return NULL; - - buf[0] = 0; - - sep = strrchr(file,'.'); - if (sep == NULL) - return NULL; - - len = MIN(sep - file, buf_size - 1); - strncpy(buf, file, len); - buf[len] = 0; - return buf; -} - /* Make sure part of path only contain chars valid for a FAT32 long name. * Double quotes are replaced with single quotes, other unsupported chars * are replaced with an underscore. @@ -144,7 +116,7 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, albumlen = id3->album ? strlen(id3->album) : 0; /* the first file we look for is one specific to the track playing */ - strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname); + strip_extension(trackname, path); strcat(path, size_string); strcat(path, ".bmp"); found = file_exists(path); diff --git a/apps/tree.c b/apps/tree.c index 09c70f0684..6ee242ba38 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -115,25 +115,6 @@ static int ft_play_dirname(char* name); static void ft_play_filename(char *dir, char *file); static void say_filetype(int attr); -/* - * removes the extension of filename (if it doesn't start with a .) - * puts the result in buffer - */ -static char * strip_extension(char * filename, char * buffer) -{ - int dotpos; - char * dot=strrchr(filename, '.'); - if(dot!=0 && filename[0]!='.') - { - dotpos = dot-filename; - strncpy(buffer, filename, dotpos); - buffer[dotpos]='\0'; - return(buffer); - } - else - return(filename); -} - static char * tree_get_filename(int selected_item, void * data, char *buffer) { struct tree_context * local_tc=(struct tree_context *)data;