diff options
| author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-08-02 20:39:03 +0000 |
|---|---|---|
| committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-08-02 20:39:03 +0000 |
| commit | 02103a2fa701954e42c8081fccf75eea26f52ce8 (patch) | |
| tree | 8055c7c0b7e3fa710e07a19928ec8c46d6a08d1d /apps/playlist.c | |
| parent | 6485d6d3ba999e8cacde267a30c8415959fcfc79 (diff) | |
| download | rockbox-02103a2fa701954e42c8081fccf75eea26f52ce8.zip rockbox-02103a2fa701954e42c8081fccf75eea26f52ce8.tar.gz rockbox-02103a2fa701954e42c8081fccf75eea26f52ce8.tar.bz2 rockbox-02103a2fa701954e42c8081fccf75eea26f52ce8.tar.xz | |
Unify opening of utf-8 files (FS#6203). This also adds ignoring the BOM in several places it has been missing (as FS#6071).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18185 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playlist.c')
| -rw-r--r-- | apps/playlist.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index f6d536f..b42ecb5 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -200,9 +200,6 @@ static long playlist_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)]; static const char playlist_thread_name[] = "playlist cachectrl"; #endif -#define BOM "\xef\xbb\xbf" -#define BOM_SIZE 3 - /* Check if the filename suggests M3U or M3U8 format. */ static bool is_m3u8(const char* filename) { @@ -212,11 +209,6 @@ static bool is_m3u8(const char* filename) return !(len > 4 && strcasecmp(&filename[len - 4], ".m3u") == 0); } -/* Check if a strings starts with an UTF-8 byte-order mark. */ -static bool is_utf8_bom(const char* str, int len) -{ - return len >= BOM_SIZE && memcmp(str, BOM, BOM_SIZE) == 0; -} /* Convert a filename in an M3U playlist to UTF-8. * @@ -538,9 +530,11 @@ static int add_indices_to_playlist(struct playlist_info* playlist, int result = 0; if(-1 == playlist->fd) - playlist->fd = open(playlist->filename, O_RDONLY); + playlist->fd = open_utf8(playlist->filename, O_RDONLY); if(playlist->fd < 0) return -1; /* failure */ + if(lseek(playlist->fd, 0, SEEK_CUR) > 0) + playlist->utf8 = true; /* Override any earlier indication. */ gui_syncsplash(0, ID2P(LANG_WAIT)); @@ -568,14 +562,6 @@ static int add_indices_to_playlist(struct playlist_info* playlist, p = (unsigned char *)buffer; - /* utf8 BOM at beginning of file? */ - if(i == 0 && is_utf8_bom(p, nread)) { - nread -= BOM_SIZE; - p += BOM_SIZE; - i += BOM_SIZE; - playlist->utf8 = true; /* Override any earlier indication. */ - } - for(count=0; count < nread; count++,p++) { /* Are we on a new line? */ @@ -2972,7 +2958,7 @@ int playlist_insert_playlist(struct playlist_info* playlist, const char *filenam return -1; } - fd = open(filename, O_RDONLY); + fd = open_utf8(filename, O_RDONLY); if (fd < 0) { gui_syncsplash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR)); @@ -3010,12 +2996,6 @@ int playlist_insert_playlist(struct playlist_info* playlist, const char *filenam if (action_userabort(TIMEOUT_NOBLOCK)) break; - if (count == 0 && is_utf8_bom(temp_buf, max)) - { - max -= BOM_SIZE; - memmove(temp_buf, temp_buf + BOM_SIZE, max); - } - if (temp_buf[0] != '#' && temp_buf[0] != '\0') { int insert_pos; @@ -3413,7 +3393,15 @@ int playlist_save(struct playlist_info* playlist, char *filename) overwrite_current = true; } - fd = open(path, O_CREAT|O_WRONLY|O_TRUNC); + if (is_m3u8(path)) + { + fd = open_utf8(path, O_CREAT|O_WRONLY|O_TRUNC); + } + else + { + /* some applications require a BOM to read the file properly */ + fd = open(path, O_CREAT|O_WRONLY|O_TRUNC); + } if (fd < 0) { gui_syncsplash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR)); @@ -3423,12 +3411,6 @@ int playlist_save(struct playlist_info* playlist, char *filename) display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), false); cpu_boost(true); - - if (is_m3u8(path)) - { - /* some applications require a BOM to read the file properly */ - write(fd, BOM, BOM_SIZE); - } index = playlist->first_index; for (i=0; i<playlist->amount; i++) @@ -3496,7 +3478,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) { if (rename(path, playlist->filename) >= 0) { - playlist->fd = open(playlist->filename, O_RDONLY); + playlist->fd = open_utf8(playlist->filename, O_RDONLY); if (playlist->fd >= 0) { index = playlist->first_index; |