diff options
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 68 |
1 files changed, 36 insertions, 32 deletions
@@ -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 | ||
28 | static 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 | */ |
36 | void | 37 | void |
37 | eprintf (const char *fmt, ...) | 38 | xvprintf (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 | */ |
54 | void | 64 | void |
55 | weprintf (const char *fmt, ...) | 65 | eprintf (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 | */ |
70 | void | 83 | void |
71 | xvprintf (const char *fmt, va_list ap) | 84 | weprintf (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 | } |