From 3bd16a8b8b79cd9af20260cdbd5d3ac7ee3dbd8b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 7 Nov 2012 22:11:57 +0100 Subject: change info(), error(), and debug() into functions and allow redirecting the output --- src/common.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 2b364cb..a250a40 100644 --- a/src/common.c +++ b/src/common.c @@ -29,6 +29,74 @@ int idevicerestore_debug = 0; +static FILE* info_stream = NULL; +static FILE* error_stream = NULL; +static FILE* debug_stream = NULL; + +static int info_disabled = 0; +static int error_disabled = 0; +static int debug_disabled = 0; + +void info(const char* format, ...) +{ + if (info_disabled) return; + va_list vargs; + va_start(vargs, format); + vfprintf((info_stream) ? info_stream : stdout, format, vargs); + va_end(vargs); +} + +void error(const char* format, ...) +{ + if (error_disabled) return; + va_list vargs; + va_start(vargs, format); + vfprintf((error_stream) ? error_stream : stderr, format, vargs); + va_end(vargs); +} + +void debug(const char* format, ...) +{ + if (debug_disabled) return; + if (!idevicerestore_debug) { + return; + } + va_list vargs; + va_start(vargs, format); + vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); + va_end(vargs); +} + +void idevicerestore_set_info_stream(FILE* strm) +{ + if (strm) { + info_disabled = 0; + info_stream = strm; + } else { + info_disabled = 1; + } +} + +void idevicerestore_set_error_stream(FILE* strm) +{ + if (strm) { + error_disabled = 0; + error_stream = strm; + } else { + error_disabled = 1; + } +} + +void idevicerestore_set_debug_stream(FILE* strm) +{ + if (strm) { + debug_disabled = 0; + debug_stream = strm; + } else { + debug_disabled = 1; + } +} + int write_file(const char* filename, const void* data, size_t size) { size_t bytes = 0; FILE* file = NULL; -- cgit v1.1-32-gdbae