-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwarnp.h
59 lines (51 loc) · 1.33 KB
/
warnp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef _WARNP_H_
#define _WARNP_H_
#include <errno.h>
/* Avoid namespace collisions with BSD <err.h>. */
#define warn libcperciva_warn
#define warnx libcperciva_warnx
/**
* warnp_setprogname(progname):
* Set the program name to be used by warn() and warnx() to ${progname}.
*/
void warnp_setprogname(const char *);
#define WARNP_INIT do { \
if (argv[0] != NULL) \
warnp_setprogname(argv[0]); \
} while (0)
/* As in BSD <err.h>. */
void warn(const char *, ...);
void warnx(const char *, ...);
/*
* If compiled with DEBUG defined, print __FILE__ and __LINE__.
*/
#ifdef DEBUG
#define warnline do { \
warnx("%s, %d", __FILE__, __LINE__); \
} while (0)
#else
#define warnline
#endif
/*
* Call warn(3) or warnx(3) depending upon whether errno == 0; and clear
* errno (so that the standard error message isn't repeated later).
*/
#define warnp(...) do { \
warnline; \
if (errno != 0) { \
warn(__VA_ARGS__); \
errno = 0; \
} else \
warnx(__VA_ARGS__); \
} while (0)
/*
* Call warnx(3) and set errno == 0. Unlike warnp, this should be used
* in cases where we're reporting a problem which we discover ourselves
* rather than one which is reported to us from a library or the kernel.
*/
#define warn0(...) do { \
warnline; \
warnx(__VA_ARGS__); \
errno = 0; \
} while (0)
#endif /* !_WARNP_H_ */