aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/util.c b/util.c
index 2acd726..5eebd3c 100644
--- a/util.c
+++ b/util.c
@@ -16,7 +16,7 @@
16 16
17/** 17/**
18 * @file util.c 18 * @file util.c
19 * @brief TODO 19 * @brief \todo
20 */ 20 */
21#include <stdarg.h> 21#include <stdarg.h>
22#include <stdio.h> 22#include <stdio.h>
@@ -25,63 +25,67 @@
25 25
26#include "util.h" 26#include "util.h"
27 27
28static void xvprintf (const char *, va_list);
29 28
30/** 29/**
31 * eprintf 30 * xvprintf prints a formatstring with prefix "libbrandt: ". If the format
31 * string ends with a ':', the strerror() from errno.h output will be appended.
32 * The output is always terminated with a newline.
32 * 33 *
33 * @param fmt TODO 34 * @param fmt The format string
34 * @param 35 * @param ap The inputs to the format string
35 */ 36 */
36void 37void
37eprintf (const char *fmt, ...) 38xvprintf (const char *fmt, va_list ap)
38{ 39{
39 va_list ap; 40 /**\todo: provide other logging target than stderr */
41 fputs ("libbrandt: ", stderr);
40 42
41 va_start (ap, fmt); 43 vfprintf (stderr, fmt, ap);
42 xvprintf (fmt, ap);
43 va_end (ap);
44 44
45 abort (); 45 if (fmt[0] && fmt[strlen (fmt) - 1] == ':')
46 {
47 fputc (' ', stderr);
48 perror (NULL);
49 }
50 else
51 {
52 fputc ('\n', stderr);
53 }
46} 54}
47 55
56
48/** 57/**
49 * weprintf 58 * eprintf prints an error message and then calls abort() to terminate the
59 * process.
50 * 60 *
51 * @param fmt TODO 61 * @param fmt The format string
52 * @param 62 * @param ... The inputs to the format string
53 */ 63 */
54void 64void
55weprintf (const char *fmt, ...) 65eprintf (const char *fmt, ...)
56{ 66{
57 va_list ap; 67 va_list ap;
58 68
59 va_start (ap, fmt); 69 va_start (ap, fmt);
60 xvprintf (fmt, ap); 70 xvprintf (fmt, ap);
61 va_end (ap); 71 va_end (ap);
72
73 abort ();
62} 74}
63 75
76
64/** 77/**
65 * xvprintf 78 * weprintf prints a warning message
66 * 79 *
67 * @param fmt TODO 80 * @param fmt The format string
68 * @param ap TODO 81 * @param ... The inputs to the format string
69 */ 82 */
70void 83void
71xvprintf (const char *fmt, va_list ap) 84weprintf (const char *fmt, ...)
72{ 85{
73 /**TODO: provide other logging target than stderr */ 86 va_list ap;
74 fputs ("libbrandt: ", stderr);
75
76 vfprintf (stderr, fmt, ap);
77 87
78 if (fmt[0] && fmt[strlen (fmt) - 1] == ':') 88 va_start (ap, fmt);
79 { 89 xvprintf (fmt, ap);
80 fputc (' ', stderr); 90 va_end (ap);
81 perror (NULL);
82 }
83 else
84 {
85 fputc ('\n', stderr);
86 }
87} 91}