summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-01-04 20:10:11 +0100
committerGravatar Nikias Bassen2017-01-04 20:10:11 +0100
commitf9ee735d6ef0b038e54076e3636f440cc77f19b1 (patch)
treea3e4758e9d428a91e63c7eafd49b3c0ac437419a
parent17307ec53908d878836853ebbdf384a195e56d0d (diff)
downloadlibirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.gz
libirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.bz2
Use fstat() instead of fseeko() and ftello()
-rw-r--r--src/libirecovery.c13
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) {