diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-07-17 17:58:02 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2019-09-12 20:37:33 +0200 |
commit | f06d71be8fc4ae9d9faf13717418986ef5891038 (patch) | |
tree | 8d724249d6f147d1d391ea03e38fbb24b83189a6 /samsung-ipc/utils.c | |
parent | 43d6c4d3d6d4219b7da5c6aabb0eee926461a11f (diff) | |
download | hardware_replicant_libsamsung-ipc-f06d71be8fc4ae9d9faf13717418986ef5891038.tar.gz hardware_replicant_libsamsung-ipc-f06d71be8fc4ae9d9faf13717418986ef5891038.tar.bz2 hardware_replicant_libsamsung-ipc-f06d71be8fc4ae9d9faf13717418986ef5891038.zip |
file_data_read: add logging
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'samsung-ipc/utils.c')
-rw-r--r-- | samsung-ipc/utils.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c index 756d191..bd1a55d 100644 --- a/samsung-ipc/utils.c +++ b/samsung-ipc/utils.c @@ -33,8 +33,8 @@ #include <net/if.h> -void *file_data_read(const char *path, size_t size, size_t chunk_size, - unsigned int offset) +void *file_data_read(struct ipc_client *client, const char *path, size_t size, + size_t chunk_size, unsigned int offset) { void *data = NULL; int fd = -1; @@ -43,16 +43,34 @@ void *file_data_read(const char *path, size_t size, size_t chunk_size, unsigned char *p; int rc; - if (path == NULL || size == 0 || chunk_size == 0 || chunk_size > size) - return NULL; + if (path == 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 NULL; + } fd = open(path, O_RDONLY); - 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; + } data = calloc(1, size); @@ -61,8 +79,10 @@ void *file_data_read(const char *path, size_t size, size_t chunk_size, count = 0; while (count < size) { rc = read(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; |