From 4e347a09bfd59fcb8d32fc8f92fc47a3158b1af9 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Mon, 9 May 2016 21:10:59 +0200 Subject: Add err function to write to stderr --- include/gensvm_util.h | 1 + src/gensvm_util.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/gensvm_util.h b/include/gensvm_util.h index 18aa553..2fd60e7 100644 --- a/include/gensvm_util.h +++ b/include/gensvm_util.h @@ -23,5 +23,6 @@ int gensvm_check_argv(int argc, char **argv, char *str); int gensvm_check_argv_eq(int argc, char **argv, char *str); void note(const char *fmt,...); +void err(const char *fmt,...); #endif diff --git a/src/gensvm_util.c b/src/gensvm_util.c index db99e21..4353b40 100644 --- a/src/gensvm_util.c +++ b/src/gensvm_util.c @@ -126,3 +126,23 @@ void note(const char *fmt,...) va_end(ap); (*gensvm_print_string)(buf); } + +/** + * @brief Parse a formatted string and write it to standard error + * + * @details + * Shorthand for fprintf(stderr, ...) + * + * @param[in] fmt string format + * @param[in] ... variable argument list for the string format + */ +void err(const char *fmt, ...) +{ + char buf[BUFSIZ]; + va_list ap; + va_start(ap, fmt); + vsprintf(buf, fmt, ap); + va_end(ap); + fputs(buf, stderr); + fflush(stderr); +} -- cgit v1.2.3