aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-09-17 00:34:51 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-10-06 18:19:02 +0200
commit3a8f3819647d061603ffd82aa0f354019dc7cb2e (patch)
tree6402f39ab7d248245ff12272301e57e57bb6e419
parentfdc396fdbb67f461e55858d4235518382df2ceb7 (diff)
downloadhardware_replicant_libsamsung-ipc-3a8f3819647d061603ffd82aa0f354019dc7cb2e.tar.gz
hardware_replicant_libsamsung-ipc-3a8f3819647d061603ffd82aa0f354019dc7cb2e.tar.bz2
hardware_replicant_libsamsung-ipc-3a8f3819647d061603ffd82aa0f354019dc7cb2e.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)