summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Peskett <rockbox@peskett.co.uk>2011-12-20 08:15:36 +0000
committerNick Peskett <rockbox@peskett.co.uk>2011-12-20 08:15:36 +0000
commit1b781df59c1b61009f36b64876372a00411b8be0 (patch)
treedf4b5cceeadf560f084d43d683ebaab689fa805e
parentc24a36dd9d54f4f77fb40b63fba1c76bac764aa6 (diff)
downloadrockbox-1b781df59c1b61009f36b64876372a00411b8be0.tar.gz
rockbox-1b781df59c1b61009f36b64876372a00411b8be0.zip
Convert hard-coded unicode byte order mark values to constants.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31374 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/cuesheet.c16
-rw-r--r--apps/metadata/id3tags.c8
-rw-r--r--apps/misc.c10
-rw-r--r--apps/misc.h7
4 files changed, 25 insertions, 16 deletions
diff --git a/apps/cuesheet.c b/apps/cuesheet.c
index ab4063a66a..2c2567b391 100644
--- a/apps/cuesheet.c
+++ b/apps/cuesheet.c
@@ -127,23 +127,23 @@ bool parse_cuesheet(struct cuesheet_file *cue_file, struct cuesheet *cue)
127 127
128 /* Look for a Unicode BOM */ 128 /* Look for a Unicode BOM */
129 unsigned char bom_read = 0; 129 unsigned char bom_read = 0;
130 read(fd, line, 3); 130 read(fd, line, BOM_UTF_8_SIZE);
131 if(!memcmp(line, "\xef\xbb\xbf", 3)) 131 if(!memcmp(line, BOM_UTF_8, BOM_UTF_8_SIZE))
132 { 132 {
133 char_enc = CHAR_ENC_UTF_8; 133 char_enc = CHAR_ENC_UTF_8;
134 bom_read = 3; 134 bom_read = BOM_UTF_8_SIZE;
135 } 135 }
136 else if(!memcmp(line, "\xff\xfe", 2)) 136 else if(!memcmp(line, BOM_UTF_16_LE, BOM_UTF_16_SIZE))
137 { 137 {
138 char_enc = CHAR_ENC_UTF_16_LE; 138 char_enc = CHAR_ENC_UTF_16_LE;
139 bom_read = 2; 139 bom_read = BOM_UTF_16_SIZE;
140 } 140 }
141 else if(!memcmp(line, "\xfe\xff", 2)) 141 else if(!memcmp(line, BOM_UTF_16_BE, BOM_UTF_16_SIZE))
142 { 142 {
143 char_enc = CHAR_ENC_UTF_16_BE; 143 char_enc = CHAR_ENC_UTF_16_BE;
144 bom_read = 2; 144 bom_read = BOM_UTF_16_SIZE;
145 } 145 }
146 if (bom_read < 3 ) 146 if (bom_read < BOM_UTF_8_SIZE)
147 lseek(fd, cue_file->pos + bom_read, SEEK_SET); 147 lseek(fd, cue_file->pos + bom_read, SEEK_SET);
148 if (is_embedded) 148 if (is_embedded)
149 { 149 {
diff --git a/apps/metadata/id3tags.c b/apps/metadata/id3tags.c
index edd58da3f5..dcb80347db 100644
--- a/apps/metadata/id3tags.c
+++ b/apps/metadata/id3tags.c
@@ -49,6 +49,7 @@
49#include "metadata_common.h" 49#include "metadata_common.h"
50#endif 50#endif
51#include "metadata_parsers.h" 51#include "metadata_parsers.h"
52#include "misc.h"
52 53
53static unsigned long unsync(unsigned long b0, 54static unsigned long unsync(unsigned long b0,
54 unsigned long b1, 55 unsigned long b1,
@@ -1008,10 +1009,13 @@ void setid3v2title(int fd, struct mp3entry *entry)
1008 break; 1009 break;
1009 case 0x01: 1010 case 0x01:
1010 tag++; 1011 tag++;
1011 if (!memcmp(tag, "\xfe\xff", 2)) 1012 if (!memcmp(tag,
1013 BOM_UTF_16_BE, BOM_UTF_16_SIZE)) {
1012 char_enc = CHAR_ENC_UTF_16_BE; 1014 char_enc = CHAR_ENC_UTF_16_BE;
1013 else if (!memcmp(tag, "\xff\xfe", 2)) 1015 } else if (!memcmp(tag,
1016 BOM_UTF_16_LE, BOM_UTF_16_SIZE)) {
1014 char_enc = CHAR_ENC_UTF_16_LE; 1017 char_enc = CHAR_ENC_UTF_16_LE;
1018 }
1015 /* \1 + BOM(2) + C0U0E0S0H0E0E0T000 = 21 */ 1019 /* \1 + BOM(2) + C0U0E0S0H0E0E0T000 = 21 */
1016 cuesheet_offset = 21; 1020 cuesheet_offset = 21;
1017 break; 1021 break;
diff --git a/apps/misc.c b/apps/misc.c
index 407a26c90f..b1def596ab 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1011,13 +1011,11 @@ void format_time(char* buf, int buf_size, long t)
1011 * If the file is opened for writing and O_TRUNC is set, write a BOM to 1011 * If the file is opened for writing and O_TRUNC is set, write a BOM to
1012 * the opened file and leave the file pointer set after the BOM. 1012 * the opened file and leave the file pointer set after the BOM.
1013 */ 1013 */
1014#define BOM "\xef\xbb\xbf"
1015#define BOM_SIZE 3
1016 1014
1017int open_utf8(const char* pathname, int flags) 1015int open_utf8(const char* pathname, int flags)
1018{ 1016{
1019 int fd; 1017 int fd;
1020 unsigned char bom[BOM_SIZE]; 1018 unsigned char bom[BOM_UTF_8_SIZE];
1021 1019
1022 fd = open(pathname, flags, 0666); 1020 fd = open(pathname, flags, 0666);
1023 if(fd < 0) 1021 if(fd < 0)
@@ -1025,13 +1023,13 @@ int open_utf8(const char* pathname, int flags)
1025 1023
1026 if(flags & (O_TRUNC | O_WRONLY)) 1024 if(flags & (O_TRUNC | O_WRONLY))
1027 { 1025 {
1028 write(fd, BOM, BOM_SIZE); 1026 write(fd, BOM_UTF_8, BOM_UTF_8_SIZE);
1029 } 1027 }
1030 else 1028 else
1031 { 1029 {
1032 read(fd, bom, BOM_SIZE); 1030 read(fd, bom, BOM_UTF_8_SIZE);
1033 /* check for BOM */ 1031 /* check for BOM */
1034 if(memcmp(bom, BOM, BOM_SIZE)) 1032 if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE))
1035 lseek(fd, 0, SEEK_SET); 1033 lseek(fd, 0, SEEK_SET);
1036 } 1034 }
1037 return fd; 1035 return fd;
diff --git a/apps/misc.h b/apps/misc.h
index 6305bcad62..2206894304 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -66,6 +66,13 @@ bool list_stop_handler(void);
66void car_adapter_mode_init(void) INIT_ATTR; 66void car_adapter_mode_init(void) INIT_ATTR;
67extern int show_logo(void); 67extern int show_logo(void);
68 68
69/* Unicode byte order mark sequences and lengths */
70#define BOM_UTF_8 "\xef\xbb\xbf"
71#define BOM_UTF_8_SIZE 3
72#define BOM_UTF_16_LE "\xff\xfe"
73#define BOM_UTF_16_BE "\xfe\xff"
74#define BOM_UTF_16_SIZE 2
75
69int open_utf8(const char* pathname, int flags); 76int open_utf8(const char* pathname, int flags);
70 77
71#ifdef BOOTFILE 78#ifdef BOOTFILE