modprobe: pull underscores() out of do_modprobe()
[mit.git] / logging.h
blobfb11df028af4c6ae4ff4ccf453f86f57dc3d90ff
1 #ifndef MODINITTOOLS_LOGGING_H
2 #define MODINITTOOLS_LOGGING_H
4 /* Do we use syslog for messages or stderr? */
5 extern int logging;
7 /* Do we want to silently drop all warnings? */
8 extern int quiet;
10 /* Do we want informative messages as well as errors? */
11 extern int verbose;
13 #ifdef __GNUC__
14 #define _printf __attribute__((format(printf, 1, 2)))
15 #else
16 #define _printf
17 #endif
19 extern void _printf fatal(const char *fmt, ...);
20 extern void _printf error(const char *fmt, ...);
21 extern void _printf warn(const char *fmt, ...);
22 extern void _printf info(const char *fmt, ...);
24 typedef void _printf (*errfn_t)(const char *fmt, ...);
26 static inline void grammar(const char *cmd,
27 const char *filename, unsigned int line)
29 warn("%s line %u: ignoring bad line starting with '%s'\n",
30 filename, line, cmd);
33 #define NOFAIL(ptr) do_nofail((ptr), __FILE__, __LINE__, #ptr)
35 #define nofail_asprintf(ptr, ...) \
36 do { if (asprintf((ptr), __VA_ARGS__) < 0) \
37 do_nofail(NULL, __FILE__, __LINE__, #ptr); \
38 } while(0)
40 static inline void *do_nofail(void *ptr, const char *file, int line, const char *expr)
42 if (!ptr) {
43 fatal("Memory allocation failure %s line %d: %s.\n",
44 file, line, expr);
46 return ptr;
49 #endif /* MODINITTOOLS_LOGGING_H */