diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-09-02 16:50:51 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-09-02 16:50:51 +0000 |
commit | ac50839423d12432f68b041c52deaa579c25d5c2 (patch) | |
tree | 08b8302ba15cfed841fdc40d8a26bab89eea40af /apps | |
parent | 70542d7a0ccddc9d8c3af002fda9dddb0edb9c41 (diff) | |
download | rockbox-ac50839423d12432f68b041c52deaa579c25d5c2.tar.gz rockbox-ac50839423d12432f68b041c52deaa579c25d5c2.zip |
Optimised new file association handling. Fixed NULL pointer accesses. Const policed.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7459 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/filetypes.c | 12 | ||||
-rw-r--r-- | apps/filetypes.h | 2 | ||||
-rw-r--r-- | apps/tree.c | 61 |
3 files changed, 40 insertions, 35 deletions
diff --git a/apps/filetypes.c b/apps/filetypes.c index 30ab2c34e5..721d5326ea 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -209,18 +209,20 @@ bool filetype_supported(int attr) } /* get the "dynamic" attribute for an extension */ -int filetype_get_attr(char* name) +int filetype_get_attr(const char* name) { int i; - char *cp; + const char *cp = strrchr(name,'.'); + + if (!cp) /* no extension? -> can't be a supported type */ + return 0; + cp++; for (i=0; i < cnt_exttypes; i++) { if (exttypes[i].extension) { - cp=strrchr(name,'.'); - if (cp) cp++; - if ((!strcasecmp(cp,exttypes[i].extension)) && (cp)) + if (!strcasecmp(cp,exttypes[i].extension)) { return ((((unsigned long)exttypes[i].type - (unsigned long)&filetypes[0]) / diff --git a/apps/filetypes.h b/apps/filetypes.h index 200d338039..e72dd6ffd3 100644 --- a/apps/filetypes.h +++ b/apps/filetypes.h @@ -23,7 +23,7 @@ #include <tree.h> #include <menu.h> -int filetype_get_attr(char*); +int filetype_get_attr(const char*); #ifdef HAVE_LCD_BITMAP const char* filetype_get_icon(int); #else diff --git a/apps/tree.c b/apps/tree.c index eec71aeb93..a88d58b165 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -1376,40 +1376,43 @@ static bool add_dir(char* dirname, int len, int fd) else { int x = strlen(entry->d_name); unsigned int i; - char *cp; - - /* add all supported audio files to playlists */ - for (i=0; i < sizeof(filetypes); i++) { - if (filetypes[i].tree_attr == TREE_ATTR_MPA) { - cp=strrchr(entry->d_name,'.'); - if (cp) cp++; - if ((!strcasecmp(cp,filetypes[i].extension)) && (cp)) - { - char buf[8]; - write(fd, dirname, strlen(dirname)); - write(fd, "/", 1); - write(fd, entry->d_name, x); - write(fd, "\n", 1); - - plsize++; - snprintf(buf, sizeof buf, "%d", plsize); + char *cp = strrchr(entry->d_name,'.'); + + if (cp) { + cp++; + + /* add all supported audio files to playlists */ + for (i=0; i < sizeof(filetypes); i++) { + if (filetypes[i].tree_attr == TREE_ATTR_MPA) { + if (!strcasecmp(cp, filetypes[i].extension)) + { + char buf[8]; + write(fd, dirname, strlen(dirname)); + write(fd, "/", 1); + write(fd, entry->d_name, x); + write(fd, "\n", 1); + + plsize++; + snprintf(buf, sizeof buf, "%d", plsize); #ifdef HAVE_LCD_BITMAP - lcd_puts(0,4,buf); - lcd_update(); + lcd_puts(0,4,buf); + lcd_update(); #else - x = 10; - if (plsize > 999) - x=7; - else { - if (plsize > 99) - x=8; + x = 10; + if (plsize > 999) + x=7; else { - if (plsize > 9) - x=9; + if (plsize > 99) + x=8; + else { + if (plsize > 9) + x=9; + } } - } - lcd_puts(x,0,buf); + lcd_puts(x,0,buf); #endif + break; + } } } } |