aboutsummaryrefslogtreecommitdiff
path: root/src/gensvm_print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gensvm_print.c')
-rw-r--r--src/gensvm_print.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/gensvm_print.c b/src/gensvm_print.c
index 2c00512..9ac210e 100644
--- a/src/gensvm_print.c
+++ b/src/gensvm_print.c
@@ -12,7 +12,7 @@
#include "gensvm_print.h"
-FILE *GENSVM_OUTPUT_FILE; ///< The #GENSVM_OUTPUT_FILE specifies the
+FILE *GENSVM_OUTPUT_FILE = NULL; ///< The #GENSVM_OUTPUT_FILE specifies the
///< output stream to which all output is
///< written. This is done through the
///< internal (!)
@@ -23,6 +23,13 @@ FILE *GENSVM_OUTPUT_FILE; ///< The #GENSVM_OUTPUT_FILE specifies the
///< this variable through @c extern and
///< (temporarily) setting it to NULL.
+FILE *GENSVM_ERROR_FILE = NULL; ///< The #GENSVM_ERROR_FILE specifies the
+ ///< output stream to use when writing an
+ ///< error. Typically this is stderr, but
+ ///< when unit testing we can temporarily
+ ///< redirect this to check if the correct
+ ///< output is written.
+
/**
* @brief Print a given string to the specified output stream
*
@@ -71,7 +78,7 @@ void note(const char *fmt,...)
* @brief Parse a formatted string and write it to standard error
*
* @details
- * Shorthand for fprintf(stderr, ...)
+ * Shorthand for fprintf(GENSVM_ERROR_FILE, ...)
*
* @param[in] fmt string format
* @param[in] ... variable argument list for the string format
@@ -83,6 +90,8 @@ void err(const char *fmt, ...)
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
- fputs(buf, stderr);
- fflush(stderr);
+ if (GENSVM_ERROR_FILE != NULL) {
+ fputs(buf, GENSVM_ERROR_FILE);
+ fflush(GENSVM_ERROR_FILE);
+ }
}