diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 22 |
1 files changed, 20 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; |