]> git.ipfire.org Git - thirdparty/glibc.git/blob - misc/err.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / misc / err.c
1 /* 4.4BSD utility functions for error messages.
2 Copyright (C) 1995-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <stdarg.h>
20 #include <err.h>
21 #include <stdlib.h>
22 #include <errno.h>
23 #include <string.h>
24 #include <stdio.h>
25
26 #include <wchar.h>
27 #define flockfile(s) _IO_flockfile (s)
28 #define funlockfile(s) _IO_funlockfile (s)
29
30 extern char *__progname;
31
32 #define VA(call) \
33 { \
34 va_list ap; \
35 va_start (ap, format); \
36 call; \
37 va_end (ap); \
38 }
39
40 void
41 vwarnx (const char *format, __gnuc_va_list ap)
42 {
43 flockfile (stderr);
44 __fxprintf (stderr, "%s: ", __progname);
45 if (format != NULL)
46 __vfxprintf (stderr, format, ap);
47 __fxprintf (stderr, "\n");
48 funlockfile (stderr);
49 }
50 libc_hidden_def (vwarnx)
51
52 void
53 vwarn (const char *format, __gnuc_va_list ap)
54 {
55 int error = errno;
56
57 flockfile (stderr);
58 if (format != NULL)
59 {
60 __fxprintf (stderr, "%s: ", __progname);
61 __vfxprintf (stderr, format, ap);
62 __set_errno (error);
63 __fxprintf (stderr, ": %m\n");
64 }
65 else
66 {
67 __set_errno (error);
68 __fxprintf (stderr, "%s: %m\n", __progname);
69 }
70 funlockfile (stderr);
71 }
72 libc_hidden_def (vwarn)
73
74
75 void
76 warn (const char *format, ...)
77 {
78 VA (vwarn (format, ap))
79 }
80 libc_hidden_def (warn)
81
82 void
83 warnx (const char *format, ...)
84 {
85 VA (vwarnx (format, ap))
86 }
87 libc_hidden_def (warnx)
88
89 void
90 verr (int status, const char *format, __gnuc_va_list ap)
91 {
92 vwarn (format, ap);
93 exit (status);
94 }
95 libc_hidden_def (verr)
96
97 void
98 verrx (int status, const char *format, __gnuc_va_list ap)
99 {
100 vwarnx (format, ap);
101 exit (status);
102 }
103 libc_hidden_def (verrx)
104
105 void
106 err (int status, const char *format, ...)
107 {
108 VA (verr (status, format, ap))
109 }
110
111 void
112 errx (int status, const char *format, ...)
113 {
114 VA (verrx (status, format, ap))
115 }