diff options
author | Nikias Bassen | 2017-01-04 20:10:11 +0100 |
---|---|---|
committer | Nikias Bassen | 2017-01-04 20:10:11 +0100 |
commit | f9ee735d6ef0b038e54076e3636f440cc77f19b1 (patch) | |
tree | a3e4758e9d428a91e63c7eafd49b3c0ac437419a /src | |
parent | 17307ec53908d878836853ebbdf384a195e56d0d (diff) | |
download | libirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.gz libirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.bz2 |
Use fstat() instead of fseeko() and ftello()
Diffstat (limited to 'src')
-rw-r--r-- | src/libirecovery.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index cd9b81e..fa4230f 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -28,6 +28,7 @@ #include <string.h> #include <ctype.h> #include <unistd.h> +#include <sys/stat.h> #ifndef WIN32 #ifndef HAVE_IOKIT @@ -1637,17 +1638,19 @@ IRECV_API irecv_error_t irecv_send_file(irecv_client_t client, const char* filen return IRECV_E_FILE_NOT_FOUND; } - fseeko(file, 0, SEEK_END); - long length = ftello(file); - fseeko(file, 0, SEEK_SET); + struct stat fst; + if (fstat(fileno(file), &fst) < 0) { + return IRECV_E_UNKNOWN_ERROR; + } + size_t length = fst.st_size; - char* buffer = (char*) malloc(length); + char* buffer = (char*)malloc(length); if (buffer == NULL) { fclose(file); return IRECV_E_OUT_OF_MEMORY; } - long bytes = fread(buffer, 1, length, file); + size_t bytes = fread(buffer, 1, length, file); fclose(file); if (bytes != length) { |