diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-09-09 23:03:08 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-10-06 18:19:02 +0200 |
commit | fdc396fdbb67f461e55858d4235518382df2ceb7 (patch) | |
tree | 733ceff12e10cc835b174fef3e4ae53e113688c3 | |
parent | ebc240735fdd8811ff601d02c1360b98a5b817b0 (diff) | |
download | hardware_replicant_libsamsung-ipc-fdc396fdbb67f461e55858d4235518382df2ceb7.tar.gz hardware_replicant_libsamsung-ipc-fdc396fdbb67f461e55858d4235518382df2ceb7.tar.bz2 hardware_replicant_libsamsung-ipc-fdc396fdbb67f461e55858d4235518382df2ceb7.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; |