summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/common.c22
-rw-r--r--src/idevicerestore.h1
2 files changed, 21 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c
index 01de503..0bd63be 100644
--- a/src/common.c
+++ b/src/common.c
@@ -29,6 +29,9 @@
int idevicerestore_debug = 0;
+#define idevicerestore_err_buff_size 256
+static char idevicerestore_err_buff[idevicerestore_err_buff_size] = {0, };
+
static FILE* info_stream = NULL;
static FILE* error_stream = NULL;
static FILE* debug_stream = NULL;
@@ -48,10 +51,12 @@ void info(const char* format, ...)
void error(const char* format, ...)
{
- if (error_disabled) return;
va_list vargs;
va_start(vargs, format);
- vfprintf((error_stream) ? error_stream : stderr, format, vargs);
+ vsnprintf(idevicerestore_err_buff, idevicerestore_err_buff_size, format, vargs);
+ if (!error_disabled) {
+ vfprintf((error_stream) ? error_stream : stderr, format, vargs);
+ }
va_end(vargs);
}
@@ -97,6 +102,19 @@ void idevicerestore_set_debug_stream(FILE* strm)
}
}
+const char* idevicerestore_get_error()
+{
+ if (idevicerestore_err_buff[0] == 0) {
+ return NULL;
+ } else {
+ char* p = NULL;
+ while ((strlen(idevicerestore_err_buff) > 0) && (p = strrchr(idevicerestore_err_buff, '\n'))) {
+ p[0] = '\0';
+ }
+ return (const char*)idevicerestore_err_buff;
+ }
+}
+
int write_file(const char* filename, const void* data, size_t size) {
size_t bytes = 0;
FILE* file = NULL;
diff --git a/src/idevicerestore.h b/src/idevicerestore.h
index 6f34743..5674665 100644
--- a/src/idevicerestore.h
+++ b/src/idevicerestore.h
@@ -66,6 +66,7 @@ void idevicerestore_set_error_stream(FILE* strm);
void idevicerestore_set_debug_stream(FILE* strm);
int idevicerestore_start(struct idevicerestore_client_t* client);
+const char* idevicerestore_get_error();
void usage(int argc, char* argv[]);
int check_mode(struct idevicerestore_client_t* client);