diff options
author | Martin Szulecki | 2012-11-07 22:14:42 +0100 |
---|---|---|
committer | Martin Szulecki | 2012-11-07 22:14:42 +0100 |
commit | 4d890286652dfd73169ecdbeb6e82ecc6f55079e (patch) | |
tree | bf496551ebe3bf0a03e317650c9d649a63003c03 /src | |
parent | 503f5bc5d7843b5e154d270b64a86503a632cc50 (diff) | |
download | idevicerestore-4d890286652dfd73169ecdbeb6e82ecc6f55079e.tar.gz idevicerestore-4d890286652dfd73169ecdbeb6e82ecc6f55079e.tar.bz2 |
Add error buffer and getter function to get the last error message
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 22 | ||||
-rw-r--r-- | src/idevicerestore.h | 1 |
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); |