Blame


1 9981e8e3 2023-01-19 thomas /*
2 9981e8e3 2023-01-19 thomas * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 9981e8e3 2023-01-19 thomas *
4 9981e8e3 2023-01-19 thomas * Permission to use, copy, modify, and distribute this software for any
5 9981e8e3 2023-01-19 thomas * purpose with or without fee is hereby granted, provided that the above
6 9981e8e3 2023-01-19 thomas * copyright notice and this permission notice appear in all copies.
7 9981e8e3 2023-01-19 thomas *
8 9981e8e3 2023-01-19 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 9981e8e3 2023-01-19 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 9981e8e3 2023-01-19 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 9981e8e3 2023-01-19 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 9981e8e3 2023-01-19 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 9981e8e3 2023-01-19 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 9981e8e3 2023-01-19 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 9981e8e3 2023-01-19 thomas */
16 9981e8e3 2023-01-19 thomas
17 9981e8e3 2023-01-19 thomas #include <errno.h>
18 9981e8e3 2023-01-19 thomas #include <stdarg.h>
19 9981e8e3 2023-01-19 thomas #include <stdio.h>
20 9981e8e3 2023-01-19 thomas #include <stdlib.h>
21 9981e8e3 2023-01-19 thomas #include <string.h>
22 9981e8e3 2023-01-19 thomas
23 9981e8e3 2023-01-19 thomas static void vwarn_impl(const char*, va_list);
24 9981e8e3 2023-01-19 thomas static void vwarnx_impl(const char*, va_list);
25 9981e8e3 2023-01-19 thomas
26 9981e8e3 2023-01-19 thomas static void
27 9981e8e3 2023-01-19 thomas vwarn_impl(const char *fmt, va_list ap)
28 9981e8e3 2023-01-19 thomas {
29 9981e8e3 2023-01-19 thomas fprintf(stderr, "%s: ", getprogname());
30 9981e8e3 2023-01-19 thomas vfprintf(stderr, fmt, ap);
31 9981e8e3 2023-01-19 thomas fprintf(stderr, ": %s\n", strerror(errno));
32 9981e8e3 2023-01-19 thomas }
33 9981e8e3 2023-01-19 thomas
34 9981e8e3 2023-01-19 thomas static void
35 9981e8e3 2023-01-19 thomas vwarnx_impl(const char *fmt, va_list ap)
36 9981e8e3 2023-01-19 thomas {
37 9981e8e3 2023-01-19 thomas fprintf(stderr, "%s: ", getprogname());
38 9981e8e3 2023-01-19 thomas vfprintf(stderr, fmt, ap);
39 9981e8e3 2023-01-19 thomas fprintf(stderr, "\n");
40 9981e8e3 2023-01-19 thomas }
41 9981e8e3 2023-01-19 thomas
42 9981e8e3 2023-01-19 thomas void
43 9981e8e3 2023-01-19 thomas err(int ret, const char *fmt, ...)
44 9981e8e3 2023-01-19 thomas {
45 9981e8e3 2023-01-19 thomas va_list ap;
46 9981e8e3 2023-01-19 thomas
47 9981e8e3 2023-01-19 thomas va_start(ap, fmt);
48 9981e8e3 2023-01-19 thomas vwarn_impl(fmt, ap);
49 9981e8e3 2023-01-19 thomas va_end(ap);
50 9981e8e3 2023-01-19 thomas exit(ret);
51 9981e8e3 2023-01-19 thomas }
52 9981e8e3 2023-01-19 thomas
53 9981e8e3 2023-01-19 thomas void
54 9981e8e3 2023-01-19 thomas errx(int ret, const char *fmt, ...)
55 9981e8e3 2023-01-19 thomas {
56 9981e8e3 2023-01-19 thomas va_list ap;
57 9981e8e3 2023-01-19 thomas
58 9981e8e3 2023-01-19 thomas va_start(ap, fmt);
59 9981e8e3 2023-01-19 thomas vwarnx_impl(fmt, ap);
60 9981e8e3 2023-01-19 thomas va_end(ap);
61 9981e8e3 2023-01-19 thomas exit(ret);
62 9981e8e3 2023-01-19 thomas }
63 9981e8e3 2023-01-19 thomas
64 9981e8e3 2023-01-19 thomas void
65 9981e8e3 2023-01-19 thomas warn(const char *fmt, ...)
66 9981e8e3 2023-01-19 thomas {
67 9981e8e3 2023-01-19 thomas va_list ap;
68 9981e8e3 2023-01-19 thomas
69 9981e8e3 2023-01-19 thomas va_start(ap, fmt);
70 9981e8e3 2023-01-19 thomas vwarn_impl(fmt, ap);
71 9981e8e3 2023-01-19 thomas va_end(ap);
72 9981e8e3 2023-01-19 thomas }
73 9981e8e3 2023-01-19 thomas
74 9981e8e3 2023-01-19 thomas void
75 9981e8e3 2023-01-19 thomas warnx(const char *fmt, ...)
76 9981e8e3 2023-01-19 thomas {
77 9981e8e3 2023-01-19 thomas va_list ap;
78 9981e8e3 2023-01-19 thomas
79 9981e8e3 2023-01-19 thomas va_start(ap, fmt);
80 9981e8e3 2023-01-19 thomas vwarnx_impl(fmt, ap);
81 9981e8e3 2023-01-19 thomas va_end(ap);
82 9981e8e3 2023-01-19 thomas }