summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-01-21 18:37:59 +0100
committerGravatar Nikias Bassen2019-01-21 18:37:59 +0100
commit8d389e546563c9bd346e6f5102e0f75d546b08e8 (patch)
tree0824226dd3fceba6425d79b34a6fca6d8483038a /src/common.c
parent661efc8f3a724fdd38174f3a886fd3aeb26fde37 (diff)
downloadidevicerestore-8d389e546563c9bd346e6f5102e0f75d546b08e8.tar.gz
idevicerestore-8d389e546563c9bd346e6f5102e0f75d546b08e8.tar.bz2
common: Use fstat() instead of fseeko() and ftello()
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/common.c b/src/common.c
index 7bbe33a..c3d835f 100644
--- a/src/common.c
+++ b/src/common.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <libgen.h>
#include <time.h>
+#include <sys/stat.h>
#include "common.h"
@@ -162,6 +163,8 @@ int read_file(const char* filename, void** data, size_t* size) {
size_t length = 0;
FILE* file = NULL;
char* buffer = NULL;
+ struct stat fst;
+
debug("Reading data from %s\n", filename);
*size = 0;
@@ -169,13 +172,15 @@ int read_file(const char* filename, void** data, size_t* size) {
file = fopen(filename, "rb");
if (file == NULL) {
- error("read_file: File %s not found\n", filename);
+ error("read_file: cannot open %s: %s\n", filename, strerror(errno));
return -1;
}
- fseeko(file, 0, SEEK_END);
- length = ftello(file);
- rewind(file);
+ if (fstat(fileno(file), &fst) < 0) {
+ error("read_file: fstat: %s\n", strerror(errno));
+ return -1;
+ }
+ length = fst.st_size;
buffer = (char*) malloc(length);
if (buffer == NULL) {