summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-11-19 10:01:49 +0100
committerGravatar Nikias Bassen2021-11-19 10:01:49 +0100
commitedda59e031862e189532c516fa7d40345b89f4f6 (patch)
tree083a56e2415d88711dbdd4a4f9b7f2ecae63f693
parent7fdd29bb8c779a66d2ea74694a08c48b81c076ec (diff)
downloadidevicerestore-edda59e031862e189532c516fa7d40345b89f4f6.tar.gz
idevicerestore-edda59e031862e189532c516fa7d40345b89f4f6.tar.bz2
Fix compilation on Windows
-rw-r--r--src/common.h7
-rw-r--r--src/ipsw.c18
-rw-r--r--src/restore.c4
3 files changed, 24 insertions, 5 deletions
diff --git a/src/common.h b/src/common.h
index 40112dc..1828476 100644
--- a/src/common.h
+++ b/src/common.h
@@ -156,6 +156,13 @@ char *generate_guid(void);
#define __usleep(x) usleep(x)
#endif
+#ifndef S_IFLNK
+#define S_IFLNK 0120000
+#endif
+#ifndef S_ISLNK
+#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#endif
+
int mkdir_with_parents(const char *dir, int mode);
char *get_temp_filename(const char *prefix);
diff --git a/src/ipsw.c b/src/ipsw.c
index 1c1ca36..da00a6e 100644
--- a/src/ipsw.c
+++ b/src/ipsw.c
@@ -630,8 +630,12 @@ int ipsw_extract_to_memory(const char* ipsw, const char* infile, unsigned char**
} else {
char *filepath = build_path(archive->path, infile);
struct stat fst;
+#ifdef WIN32
+ if (stat(filepath, &fst) != 0) {
+#else
if (lstat(filepath, &fst) != 0) {
- error("ERROR: %s: fstat failed for %s: %s\n", __func__, filepath, strerror(errno));
+#endif
+ error("ERROR: %s: stat failed for %s: %s\n", __func__, filepath, strerror(errno));
free(filepath);
ipsw_close(archive);
return -1;
@@ -645,8 +649,9 @@ int ipsw_extract_to_memory(const char* ipsw, const char* infile, unsigned char**
return -1;
}
+#ifndef WIN32
if (S_ISLNK(fst.st_mode)) {
- if (readlink(filepath, buffer, size) < 0) {
+ if (readlink(filepath, (char*)buffer, size) < 0) {
error("ERROR: %s: readlink failed for %s: %s\n", __func__, filepath, strerror(errno));
free(filepath);
free(buffer);
@@ -654,6 +659,7 @@ int ipsw_extract_to_memory(const char* ipsw, const char* infile, unsigned char**
return -1;
}
} else {
+#endif
FILE *f = fopen(filepath, "rb");
if (!f) {
error("ERROR: %s: fopen failed for %s: %s\n", __func__, filepath, strerror(errno));
@@ -671,7 +677,9 @@ int ipsw_extract_to_memory(const char* ipsw, const char* infile, unsigned char**
return -1;
}
fclose(f);
+#ifndef WIN32
}
+#endif
buffer[size] = '\0';
free(filepath);
@@ -756,9 +764,13 @@ static int ipsw_list_contents_recurse(ipsw_archive *archive, const char *path, i
subpath = strdup(dir->d_name);
struct stat st;
+#ifdef WIN32
+ ret = stat(fpath, &st);
+#else
ret = lstat(fpath, &st);
+#endif
if (ret != 0) {
- error("ERROR: failed to stat %s\n", fpath);
+ error("ERROR: %s: stat failed for %s: %s\n", __func__, fpath, strerror(errno));
free(fpath);
free(subpath);
break;
diff --git a/src/restore.c b/src/restore.c
index ff1e43e..13c3625 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -2878,7 +2878,7 @@ static int restore_bootability_send_one(void *ctx, const char *ipsw, const char
subpath = name + strlen(prefix);
}
- debug("DEBUG: BootabilityBundle send m=%07o s=%10ld %s\n", stat->st_mode, stat->st_size, subpath);
+ debug("DEBUG: BootabilityBundle send m=%07o s=%10ld %s\n", stat->st_mode, (long)stat->st_size, subpath);
unsigned char *buf = NULL;
unsigned int size = 0;
@@ -2886,7 +2886,7 @@ static int restore_bootability_send_one(void *ctx, const char *ipsw, const char
if ((S_ISLNK(stat->st_mode) || S_ISREG(stat->st_mode)) && stat->st_size != 0) {
ipsw_extract_to_memory(ipsw, name, &buf, &size);
if (size != stat->st_size) {
- error("ERROR: expected %ld bytes but got %d for file %s\n", stat->st_size, size, name);
+ error("ERROR: expected %ld bytes but got %d for file %s\n", (long)stat->st_size, size, name);
free(buf);
return -1;
}