2 9981e8e3 2023-01-19 thomas * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
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.
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.
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>
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);
26 9981e8e3 2023-01-19 thomas static void
27 9981e8e3 2023-01-19 thomas vwarn_impl(const char *fmt, va_list ap)
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));
34 9981e8e3 2023-01-19 thomas static void
35 9981e8e3 2023-01-19 thomas vwarnx_impl(const char *fmt, va_list ap)
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");
43 9981e8e3 2023-01-19 thomas err(int ret, const char *fmt, ...)
45 9981e8e3 2023-01-19 thomas va_list ap;
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);
54 9981e8e3 2023-01-19 thomas errx(int ret, const char *fmt, ...)
56 9981e8e3 2023-01-19 thomas va_list ap;
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);
65 9981e8e3 2023-01-19 thomas warn(const char *fmt, ...)
67 9981e8e3 2023-01-19 thomas va_list ap;
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);
75 9981e8e3 2023-01-19 thomas warnx(const char *fmt, ...)
77 9981e8e3 2023-01-19 thomas va_list ap;
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);