summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/misc.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 6c589b99e4..f847023c31 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -1111,6 +1111,7 @@ int split_string(char *str, const char split_char, char *vector[], const int vec
1111 1111
1112int open_utf8(const char* pathname, int flags) 1112int open_utf8(const char* pathname, int flags)
1113{ 1113{
1114 ssize_t ret;
1114 int fd; 1115 int fd;
1115 unsigned char bom[BOM_UTF_8_SIZE]; 1116 unsigned char bom[BOM_UTF_8_SIZE];
1116 1117
@@ -1120,16 +1121,23 @@ int open_utf8(const char* pathname, int flags)
1120 1121
1121 if(flags & (O_TRUNC | O_WRONLY)) 1122 if(flags & (O_TRUNC | O_WRONLY))
1122 { 1123 {
1123 write(fd, BOM_UTF_8, BOM_UTF_8_SIZE); 1124 ret = write(fd, BOM_UTF_8, BOM_UTF_8_SIZE);
1124 } 1125 }
1125 else 1126 else
1126 { 1127 {
1127 read(fd, bom, BOM_UTF_8_SIZE); 1128 ret = read(fd, bom, BOM_UTF_8_SIZE);
1128 /* check for BOM */ 1129 /* check for BOM */
1129 if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE)) 1130 if (ret == BOM_UTF_8_SIZE)
1130 lseek(fd, 0, SEEK_SET); 1131 {
1132 if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE))
1133 lseek(fd, 0, SEEK_SET);
1134 }
1131 } 1135 }
1132 return fd; 1136 /* read or write failure, do not continue */
1137 if (ret < 0)
1138 close(fd);
1139
1140 return ret >= 0 ? fd : -1;
1133} 1141}
1134 1142
1135 1143