aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-10-12 00:22:20 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-11-03 17:07:25 +0100
commit480308e794ce2d476de8b17b2dc4da9fdb79d7e5 (patch)
treee41e07c3a754e9889909a9034e3a6f79c699a8e9
parentdd7cbaad6f008a03261411912b71011eb43cfa14 (diff)
downloadhardware_replicant_libsamsung-ipc-480308e794ce2d476de8b17b2dc4da9fdb79d7e5.tar.gz
hardware_replicant_libsamsung-ipc-480308e794ce2d476de8b17b2dc4da9fdb79d7e5.tar.bz2
hardware_replicant_libsamsung-ipc-480308e794ce2d476de8b17b2dc4da9fdb79d7e5.zip
samsung-ipc/utils: file_data_write: return more precise errors
file_data_write uses open and lseek, and both can fail. In that case, it would be a good idea to be able for the caller of file_data_write to be able to retrieve the cause of the error. To do that here, we used the same way than write uses to pass on the information to the caller: On success, the number of bytes written is returned. On error, -1 is returned, and errno is set to indicate the cause of the error. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/utils.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c
index 3fb4adc..a2ef2bf 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -145,6 +145,7 @@ int file_data_write(struct ipc_client *client, const char *path,
ipc_client_log(client, "%s failed: chunk_size > size",
__func__);
}
+ errno = EINVAL;
return -1;
}
@@ -158,6 +159,7 @@ int file_data_write(struct ipc_client *client, const char *path,
seek = lseek(fd, (off_t) offset, SEEK_SET);
if (seek < (off_t) offset) {
+ rc = errno;
ipc_client_log(client, "%s failed: seek < (off_t) offset",
__func__);
goto error;
@@ -180,17 +182,17 @@ int file_data_write(struct ipc_client *client, const char *path,
count += rc;
}
- rc = 0;
- goto complete;
+ if (fd >= 0)
+ close(fd);
-error:
- rc = -1;
+ return 0;
-complete:
+error:
if (fd >= 0)
close(fd);
- return rc;
+ errno = rc;
+ return -1;
}
off_t file_data_size(struct ipc_client *client, const char *path)