summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ideviceinstaller.c44
1 files changed, 37 insertions, 7 deletions
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 @@
51 51
52#include <zip.h> 52#include <zip.h>
53 53
54#ifdef WIN32
55#include <windows.h>
56#define wait_ms(x) Sleep(x)
57#else
58#define wait_ms(x) { struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = x * 1000000; nanosleep(&ts, NULL); }
59#endif
60
61#ifndef HAVE_VASPRINTF
62static int vasprintf(char **PTR, const char *TEMPLATE, va_list AP)
63{
64 int res;
65 char buf[16];
66 res = vsnprintf(buf, 16, TEMPLATE, AP);
67 if (res > 0) {
68 *PTR = (char*)malloc(res+1);
69 res = vsnprintf(*PTR, res+1, TEMPLATE, AP);
70 }
71 return res;
72}
73#endif
74
75#ifndef HAVE_ASPRINTF
76static int asprintf(char **PTR, const char *TEMPLATE, ...)
77{
78 int res;
79 va_list AP;
80 va_start(AP, TEMPLATE);
81 res = vasprintf(PTR, TEMPLATE, AP);
82 va_end(AP);
83 return res;
84}
85#endif
86
54#define ITUNES_METADATA_PLIST_FILENAME "iTunesMetadata.plist" 87#define ITUNES_METADATA_PLIST_FILENAME "iTunesMetadata.plist"
55 88
56const char PKG_PATH[] = "PublicStaging"; 89const char PKG_PATH[] = "PublicStaging";
@@ -323,9 +356,6 @@ static void idevice_event_callback(const idevice_event_t* event, void* userdata)
323 356
324static void idevice_wait_for_command_to_complete() 357static void idevice_wait_for_command_to_complete()
325{ 358{
326 struct timespec ts;
327 ts.tv_sec = 0;
328 ts.tv_nsec = 50000000;
329 is_device_connected = 1; 359 is_device_connected = 1;
330 360
331 /* subscribe to make sure to exit on device removal */ 361 /* subscribe to make sure to exit on device removal */
@@ -334,12 +364,12 @@ static void idevice_wait_for_command_to_complete()
334 /* wait for command to complete */ 364 /* wait for command to complete */
335 while (wait_for_command_complete && !command_completed && !err_occurred 365 while (wait_for_command_complete && !command_completed && !err_occurred
336 && is_device_connected) { 366 && is_device_connected) {
337 nanosleep(&ts, NULL); 367 wait_ms(50);
338 } 368 }
339 369
340 /* wait some time if a notification is expected */ 370 /* wait some time if a notification is expected */
341 while (notification_expected && !notified && !err_occurred && is_device_connected) { 371 while (notification_expected && !notified && !err_occurred && is_device_connected) {
342 nanosleep(&ts, NULL); 372 wait_ms(50);
343 } 373 }
344 374
345 idevice_event_unsubscribe(); 375 idevice_event_unsubscribe();
@@ -530,7 +560,7 @@ static int afc_upload_file(afc_client_t afc, const char* filename, const char* d
530 total += written; 560 total += written;
531 } 561 }
532 if (total != amount) { 562 if (total != amount) {
533 fprintf(stderr, "Error: wrote only %d of %zu\n", total, amount); 563 fprintf(stderr, "Error: wrote only %u of %u\n", total, (uint32_t)amount);
534 afc_file_close(afc, af); 564 afc_file_close(afc, af);
535 fclose(f); 565 fclose(f);
536 return -1; 566 return -1;
@@ -943,7 +973,7 @@ run_again:
943 char *ibuf = malloc(filesize * sizeof(char)); 973 char *ibuf = malloc(filesize * sizeof(char));
944 size_t amount = fread(ibuf, 1, filesize, fp); 974 size_t amount = fread(ibuf, 1, filesize, fp);
945 if (amount != filesize) { 975 if (amount != filesize) {
946 fprintf(stderr, "ERROR: could not read %ld bytes from %s\n", filesize, filename); 976 fprintf(stderr, "ERROR: could not read %u bytes from %s\n", (uint32_t)filesize, filename);
947 free(filename); 977 free(filename);
948 res = -1; 978 res = -1;
949 goto leave_cleanup; 979 goto leave_cleanup;