summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-05-09 16:44:10 +0200
committerGravatar Nikias Bassen2019-05-09 16:44:10 +0200
commit8c1945ccd27c5069c22acd1018435dfff0d0b609 (patch)
tree7da118de21949c77ba55c50a217381339f7f1324
parent4a7f0b01483f2b1e3c11447bb4654b181deacf41 (diff)
downloadideviceinstaller-8c1945ccd27c5069c22acd1018435dfff0d0b609.tar.gz
ideviceinstaller-8c1945ccd27c5069c22acd1018435dfff0d0b609.tar.bz2
Fix compilation on win32
-rw-r--r--configure.ac2
-rw-r--r--src/ideviceinstaller.c44
2 files changed, 38 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 52d2a5d..e137301 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
-AC_CHECK_FUNCS([strcasecmp strdup strerror strndup])
+AC_CHECK_FUNCS([strdup strerror asprintf vasprintf])
# Check for lstat
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c
index 134579d..17f6966 100644
--- a/src/ideviceinstaller.c
+++ b/src/ideviceinstaller.c
@@ -51,6 +51,39 @@
#include <zip.h>
+#ifdef WIN32
+#include <windows.h>
+#define wait_ms(x) Sleep(x)
+#else
+#define wait_ms(x) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = x * 1000000; nanosleep(&ts, NULL); }
+#endif
+
+#ifndef HAVE_VASPRINTF
+static int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
+{
+ int res;
+ char buf[16];
+ res = vsnprintf(buf, 16, TEMPLATE, AP);
+ if (res > 0) {
+ *PTR = (char*)malloc(res+1);
+ res = vsnprintf(*PTR, res+1, TEMPLATE, AP);
+ }
+ return res;
+}
+#endif
+
+#ifndef HAVE_ASPRINTF
+static int asprintf(char **PTR, const char *TEMPLATE, ...)
+{
+ int res;
+ va_list AP;
+ va_start(AP, TEMPLATE);
+ res = vasprintf(PTR, TEMPLATE, AP);
+ va_end(AP);
+ return res;
+}
+#endif
+
#define ITUNES_METADATA_PLIST_FILENAME "iTunesMetadata.plist"
const char PKG_PATH[] = "PublicStaging";
@@ -323,9 +356,6 @@ static void idevice_event_callback(const idevice_event_t* event, void* userdata)
static void idevice_wait_for_command_to_complete()
{
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 50000000;
is_device_connected = 1;
/* subscribe to make sure to exit on device removal */
@@ -334,12 +364,12 @@ static void idevice_wait_for_command_to_complete()
/* wait for command to complete */
while (wait_for_command_complete && !command_completed && !err_occurred
&& is_device_connected) {
- nanosleep(&ts, NULL);
+ wait_ms(50);
}
/* wait some time if a notification is expected */
while (notification_expected && !notified && !err_occurred && is_device_connected) {
- nanosleep(&ts, NULL);
+ wait_ms(50);
}
idevice_event_unsubscribe();
@@ -530,7 +560,7 @@ static int afc_upload_file(afc_client_t afc, const char* filename, const char* d
total += written;
}
if (total != amount) {
- fprintf(stderr, "Error: wrote only %d of %zu\n", total, amount);
+ fprintf(stderr, "Error: wrote only %u of %u\n", total, (uint32_t)amount);
afc_file_close(afc, af);
fclose(f);
return -1;
@@ -943,7 +973,7 @@ run_again:
char *ibuf = malloc(filesize * sizeof(char));
size_t amount = fread(ibuf, 1, filesize, fp);
if (amount != filesize) {
- fprintf(stderr, "ERROR: could not read %ld bytes from %s\n", filesize, filename);
+ fprintf(stderr, "ERROR: could not read %u bytes from %s\n", (uint32_t)filesize, filename);
free(filename);
res = -1;
goto leave_cleanup;