summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 @@
28#include <string.h> 28#include <string.h>
29#include <ctype.h> 29#include <ctype.h>
30#include <unistd.h> 30#include <unistd.h>
31#include <sys/stat.h>
31 32
32#ifndef WIN32 33#ifndef WIN32
33#ifndef HAVE_IOKIT 34#ifndef HAVE_IOKIT
@@ -1637,17 +1638,19 @@ IRECV_API irecv_error_t irecv_send_file(irecv_client_t client, const char* filen
1637 return IRECV_E_FILE_NOT_FOUND; 1638 return IRECV_E_FILE_NOT_FOUND;
1638 } 1639 }
1639 1640
1640 fseeko(file, 0, SEEK_END); 1641 struct stat fst;
1641 long length = ftello(file); 1642 if (fstat(fileno(file), &fst) < 0) {
1642 fseeko(file, 0, SEEK_SET); 1643 return IRECV_E_UNKNOWN_ERROR;
1644 }
1645 size_t length = fst.st_size;
1643 1646
1644 char* buffer = (char*) malloc(length); 1647 char* buffer = (char*)malloc(length);
1645 if (buffer == NULL) { 1648 if (buffer == NULL) {
1646 fclose(file); 1649 fclose(file);
1647 return IRECV_E_OUT_OF_MEMORY; 1650 return IRECV_E_OUT_OF_MEMORY;
1648 } 1651 }
1649 1652
1650 long bytes = fread(buffer, 1, length, file); 1653 size_t bytes = fread(buffer, 1, length, file);
1651 fclose(file); 1654 fclose(file);
1652 1655
1653 if (bytes != length) { 1656 if (bytes != length) {