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 /samsung-ipc | |
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>
Diffstat (limited to 'samsung-ipc')
-rw-r--r-- | samsung-ipc/utils.c | 41 |
1 files changed, 41 insertions, 0 deletions
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; |