diff options
| author | 2017-01-04 20:10:11 +0100 | |
|---|---|---|
| committer | 2017-01-04 20:10:11 +0100 | |
| commit | f9ee735d6ef0b038e54076e3636f440cc77f19b1 (patch) | |
| tree | a3e4758e9d428a91e63c7eafd49b3c0ac437419a | |
| parent | 17307ec53908d878836853ebbdf384a195e56d0d (diff) | |
| download | libirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.gz libirecovery-f9ee735d6ef0b038e54076e3636f440cc77f19b1.tar.bz2 | |
Use fstat() instead of fseeko() and ftello()
| -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 @@ | |||
| 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) { |
