eprintf.c - smdev - suckless mdev
(HTM) git clone git://git.suckless.org/smdev
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
eprintf.c (869B)
---
1 /* See LICENSE file for copyright and license details. */
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "../util.h"
8
9 char *argv0;
10
11 static void venprintf(int, const char *, va_list);
12
13 void
14 eprintf(const char *fmt, ...)
15 {
16 va_list ap;
17
18 va_start(ap, fmt);
19 venprintf(EXIT_FAILURE, fmt, ap);
20 va_end(ap);
21 }
22
23 void
24 enprintf(int status, const char *fmt, ...)
25 {
26 va_list ap;
27
28 va_start(ap, fmt);
29 venprintf(status, fmt, ap);
30 va_end(ap);
31 }
32
33 void
34 venprintf(int status, const char *fmt, va_list ap)
35 {
36 vfprintf(stderr, fmt, ap);
37
38 if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
39 fputc(' ', stderr);
40 perror(NULL);
41 }
42
43 exit(status);
44 }
45
46 void
47 weprintf(const char *fmt, ...)
48 {
49 va_list ap;
50
51 va_start(ap, fmt);
52 vfprintf(stderr, fmt, ap);
53 va_end(ap);
54
55 if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
56 fputc(' ', stderr);
57 perror(NULL);
58 }
59 }