diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-07-17 18:03:19 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-07-17 18:07:25 +0200 |
commit | 14109f76e449eff09a61537de8baefc256b23ead (patch) | |
tree | 093b7cae0174b8054ce63648511a87c10c0c46e4 | |
parent | 1bf2e98f26a4346f50d266bba220faa1ce2212f2 (diff) | |
download | hardware_replicant_libsamsung-ipc-14109f76e449eff09a61537de8baefc256b23ead.tar.gz hardware_replicant_libsamsung-ipc-14109f76e449eff09a61537de8baefc256b23ead.tar.bz2 hardware_replicant_libsamsung-ipc-14109f76e449eff09a61537de8baefc256b23ead.zip |
sync file_data_write with file_data_read
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r-- | include/samsung-ipc.h | 5 | ||||
-rw-r--r-- | samsung-ipc/utils.c | 41 |
2 files changed, 34 insertions, 12 deletions
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h index 0b255b1..e3e6c4a 100644 --- a/include/samsung-ipc.h +++ b/include/samsung-ipc.h @@ -137,8 +137,9 @@ int ipc_rfs_message_setup(const struct ipc_rfs_header *header, void *file_data_read(struct ipc_client *client, const char *path, size_t size, size_t chunk_size, unsigned int offset); -int file_data_write(const char *path, const void *data, size_t size, - size_t chunk_size, unsigned int offset); +int file_data_write(struct ipc_client *client, + const char *path, const void *data, size_t size, + size_t chunk_size, unsigned int offset); int network_iface_up(const char *iface, int domain, int type); int network_iface_down(const char *iface, int domain, int type); int sysfs_value_read(const char *path); diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c index bd1a55d..bca847d 100644 --- a/samsung-ipc/utils.c +++ b/samsung-ipc/utils.c @@ -32,6 +32,7 @@ #include <linux/netlink.h> #include <net/if.h> +#include <samsung-ipc.h> void *file_data_read(struct ipc_client *client, const char *path, size_t size, size_t chunk_size, unsigned int offset) @@ -103,8 +104,9 @@ complete: return data; } -int file_data_write(const char *path, const void *data, size_t size, - size_t chunk_size, unsigned int offset) +int file_data_write(struct ipc_client *client, + const char *path, const void *data, size_t size, + size_t chunk_size, unsigned int offset) { int fd = -1; size_t count; @@ -112,24 +114,43 @@ int file_data_write(const char *path, const void *data, size_t size, unsigned char *p; int rc; - if (path == NULL || data == NULL || size == 0 || chunk_size == 0 || chunk_size > size) - return -1; + if (path == NULL || data == NULL || size == 0 || chunk_size == 0 || chunk_size > size) { + if (path == NULL) { + ipc_client_log(client, "%s: Failed: path is NULL", __FUNCTION__); + } + if (size == 0) { + ipc_client_log(client, "%s: Failed: size is 0", __FUNCTION__); + } + if (chunk_size == 0) { + ipc_client_log(client, "%s: Failed: chunk_size is 0", __FUNCTION__); + } + if (chunk_size > size) { + ipc_client_log(client, "%s: Failed: chunk_size > size ", __FUNCTION__); + } + return -1; + } fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (fd < 0) - goto error; + if (fd < 0) { + ipc_client_log(client, "%s: Error: fd: %d ", __FUNCTION__, fd); + goto error; + } seek = lseek(fd, (off_t) offset, SEEK_SET); - if (seek < (off_t) offset) - goto error; + if (seek < (off_t) offset) { + ipc_client_log(client, "%s: Error: seek < (off_t) offset", __FUNCTION__); + goto error; + } p = (unsigned char *) data; count = 0; while (count < size) { rc = write(fd, p, size - count > chunk_size ? chunk_size : size - count); - if (rc <= 0) - goto error; + if (rc <= 0) { + ipc_client_log(client, "%s: Error: rc < 0", __FUNCTION__); + goto error; + } p += rc; count += rc; |