[Replicant] [libsamsung-ipc] [PATCH 09/11] samsung-ipc/utils: file_data_write: return more precise errors
Denis 'GNUtoo' Carikli
GNUtoo at cyberdimension.org
Sun Oct 11 22:22:20 UTC 2020
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 at cyberdimension.org>
---
samsung-ipc/utils.c | 14 ++++++++------
1 file 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)
--
2.28.0
More information about the Replicant
mailing list