1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <errno.h>
28#include "error.h"
29
30char *pname;
31
32void
33Warning(char *fmt, ...)
34{
35 va_list args;
36
37 fprintf(stderr, "%s: WARNING: ", pname);
38
39 va_start(args, fmt);
40 vfprintf(stderr, fmt, args);
41 va_end(args);
42
43 fprintf(stderr, "\n");
44}
45
46void
47Error(char *fmt, ...)
48{
49 va_list args;
50
51 fprintf(stderr, "%s: ERROR: ", pname);
52
53 va_start(args, fmt);
54 vfprintf(stderr, fmt, args);
55 va_end(args);
56
57 fprintf(stderr, "\n");
58
59 exit(1);
60}
61
62void
63Perror(char *fmt, ...)
64{
65 va_list args;
66 int e = errno;
67 char *p;
68
69 fprintf(stderr, "%s: ERROR: ", pname);
70
71 va_start(args, fmt);
72 vfprintf(stderr, fmt, args);
73 va_end(args);
74
75 if ((p = strerror(e)) == NULL || *p == '\0')
76 fprintf(stderr, ": Unknown Error (%d)\n", e);
77 else
78 fprintf(stderr, ": %s\n", p);
79
80 exit(1);
81}
82