summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2012-11-07 22:11:57 +0100
committerGravatar Martin Szulecki2012-11-07 22:11:57 +0100
commit3bd16a8b8b79cd9af20260cdbd5d3ac7ee3dbd8b (patch)
tree124ea4690334903f57007fbf5efafd0730b320fb /src/common.c
parentb65a7ce7ebca6730fce5dcbfd820d8ef4124e18f (diff)
downloadidevicerestore-3bd16a8b8b79cd9af20260cdbd5d3ac7ee3dbd8b.tar.gz
idevicerestore-3bd16a8b8b79cd9af20260cdbd5d3ac7ee3dbd8b.tar.bz2
change info(), error(), and debug() into functions and allow redirecting the output
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c68
1 files changed, 68 insertions, 0 deletions
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;