summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-06-29 12:23:48 +0200
committerThomas Martitz <kugel@rockbox.org>2014-06-29 12:25:01 +0200
commit5877f7b5c077df92983553d455318b26096e8bf0 (patch)
tree284d4d0b3108c7ffc1e10dcb47e71d6ca6add57b /apps
parent7b377d29fbdc32d0e413614370b00f21cd22049b (diff)
open_utf8: Actually use the result of read/write.
This silences warnings on some compilers but is anyway a good idea. Change-Id: Ib566ab59a5d1cb433da466f3ce0c32ff150eb52e
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
int open_utf8(const char* pathname, int flags)
{
+ ssize_t ret;
int fd;
unsigned char bom[BOM_UTF_8_SIZE];
@@ -1120,16 +1121,23 @@ int open_utf8(const char* pathname, int flags)
if(flags & (O_TRUNC | O_WRONLY))
{
- write(fd, BOM_UTF_8, BOM_UTF_8_SIZE);
+ ret = write(fd, BOM_UTF_8, BOM_UTF_8_SIZE);
}
else
{
- read(fd, bom, BOM_UTF_8_SIZE);
+ ret = read(fd, bom, BOM_UTF_8_SIZE);
/* check for BOM */
- if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE))
- lseek(fd, 0, SEEK_SET);
+ if (ret == BOM_UTF_8_SIZE)
+ {
+ if(memcmp(bom, BOM_UTF_8, BOM_UTF_8_SIZE))
+ lseek(fd, 0, SEEK_SET);
+ }
}
- return fd;
+ /* read or write failure, do not continue */
+ if (ret < 0)
+ close(fd);
+
+ return ret >= 0 ? fd : -1;
}