diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-10-12 00:22:19 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-11-03 17:07:22 +0100 |
commit | dd7cbaad6f008a03261411912b71011eb43cfa14 (patch) | |
tree | 8ff01aac4b0caa0679e3bbb5ebe55c9f5db254cc | |
parent | 60c99dd579c08d16e591b2701f3753b30f641693 (diff) | |
download | hardware_replicant_libsamsung-ipc-dd7cbaad6f008a03261411912b71011eb43cfa14.tar.gz hardware_replicant_libsamsung-ipc-dd7cbaad6f008a03261411912b71011eb43cfa14.tar.bz2 hardware_replicant_libsamsung-ipc-dd7cbaad6f008a03261411912b71011eb43cfa14.zip |
samsung-ipc/utils: Add file_data_size
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r-- | include/samsung-ipc.h | 1 | ||||
-rw-r--r-- | samsung-ipc/utils.c | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h index b5a8315..a03c748 100644 --- a/include/samsung-ipc.h +++ b/include/samsung-ipc.h @@ -155,6 +155,7 @@ void *file_data_read(struct ipc_client *client, const char *path, size_t size, int file_data_write(struct ipc_client *client, const char *path, const void *data, size_t size, size_t chunk_size, unsigned int offset); +off_t file_data_size(struct ipc_client *client, const char *path); 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 0e6bc2f..3fb4adc 100644 --- a/samsung-ipc/utils.c +++ b/samsung-ipc/utils.c @@ -193,6 +193,47 @@ complete: return rc; } +off_t file_data_size(struct ipc_client *client, const char *path) +{ + int fd = -1; + off_t rc = 0; + int err = 0; + + if (path == NULL) { + ipc_client_log(client, "%s: Failed: path is NULL", + __func__); + err = ENOENT; + goto error; + } + + fd = open(path, O_RDONLY); + if (fd < 0) { + err = errno; + ipc_client_log(client, "%s: open %s failed with error %d: %s", + __func__, path, err, strerror(err)); + goto error; + } + + rc = lseek(fd, 0, SEEK_END); + if (rc == -1) { + err = errno; + ipc_client_log(client, "%s: seek %s failed with error %d: %s", + __func__, path, err, strerror(err)); + goto error; + } + +error: + if (fd >= 0) + close(fd); + + if (err) { + errno = err; + return -1; + } else { + return rc; + } +} + int network_iface_up(const char *iface, int domain, int type) { struct ifreq ifr; |