author | Tero Marttila <terom@fixme.fi> |
Mon, 13 Oct 2008 02:27:59 +0300 | |
changeset 27 | 461be4cd34a3 |
parent 24 | 82cfdb6680d1 |
child 33 | c71f3053c714 |
permissions | -rw-r--r-- |
1 | 1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
|
3 |
#include <stdarg.h> |
|
4 |
#include <string.h> |
|
5 |
#include <errno.h> |
|
6 |
||
6
d2036d7799fd
new 'simple' module, plus hello_simple
Tero Marttila <terom@fixme.fi>
parents:
2
diff
changeset
|
7 |
#include "log.h" |
1 | 8 |
|
16 | 9 |
static void _generic_err_vargs (int flags, const char *func, int err, const char *fmt, va_list va) { |
10 |
FILE *stream = flags & LOG_DISPLAY_STDERR ? stderr : stdout; |
|
1 | 11 |
|
27 | 12 |
if (flags & LOG_DISPLAY_FATAL) |
13 |
fprintf(stream, "FATAL: "); |
|
14 |
||
1 | 15 |
if (func) |
16 |
fprintf(stream, "%s: ", func); |
|
17 |
||
18 |
vfprintf(stream, fmt, va); |
|
19 |
||
16 | 20 |
if (flags & LOG_DISPLAY_PERR) |
24 | 21 |
fprintf(stream, ": %s\n", strerror(err == 0 ? errno : err)); |
16 | 22 |
|
23 |
if (!(flags & LOG_DISPLAY_NONL)) |
|
24 |
fprintf(stream, "\n"); |
|
1 | 25 |
} |
26 |
||
16 | 27 |
void _generic_err (int flags, const char *func, int err, const char *fmt, ...) { |
1 | 28 |
va_list va; |
29 |
||
30 |
va_start(va, fmt); |
|
16 | 31 |
_generic_err_vargs(flags, func, err, fmt, va); |
1 | 32 |
va_end(va); |
33 |
} |
|
34 |
||
16 | 35 |
void _generic_err_exit (int flags, const char *func, int err, const char *fmt, ...) { |
1 | 36 |
va_list va; |
37 |
||
38 |
va_start(va, fmt); |
|
27 | 39 |
_generic_err_vargs(flags | LOG_DISPLAY_FATAL, func, err, fmt, va); |
1 | 40 |
va_end(va); |
41 |
||
42 |
exit(EXIT_FAILURE); |
|
43 |
} |
|
44 |