diff options
Diffstat (limited to 'apps/misc.c')
-rw-r--r-- | apps/misc.c | 10 |
1 files changed, 4 insertions, 6 deletions
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 | ||
1017 | int open_utf8(const char* pathname, int flags) | 1015 | int 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; |