aboutsummaryrefslogtreecommitdiff
path: root/src/gensvm_print.c
diff options
context:
space:
mode:
authorGertjan van den Burg <burg@ese.eur.nl>2016-09-20 16:41:52 +0200
committerGertjan van den Burg <burg@ese.eur.nl>2016-09-20 16:41:52 +0200
commit014d9b5e6b0de17a1910c32347bf86de48e06af4 (patch)
treeea87fcc0dc21b5fde4723f22e0b007870edbc348 /src/gensvm_print.c
parentFix memory leak (diff)
downloadgensvm-014d9b5e6b0de17a1910c32347bf86de48e06af4.tar.gz
gensvm-014d9b5e6b0de17a1910c32347bf86de48e06af4.zip
Use file stream for errors too
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);
+ }
}