]> git.ipfire.org Git - thirdparty/glibc.git/blame - misc/err.c
linux: Normalize and return timeout on select (BZ #27651)
[thirdparty/glibc.git] / misc / err.c
CommitLineData
a2635361 1/* 4.4BSD utility functions for error messages.
2b778ceb 2 Copyright (C) 1995-2021 Free Software Foundation, Inc.
47707456 3 This file is part of the GNU C Library.
196980f5 4
47707456 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
196980f5 9
47707456
UD
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
41bdb6e2 13 Lesser General Public License for more details.
196980f5 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
196980f5
RM
18
19#include <stdarg.h>
20#include <err.h>
21#include <stdlib.h>
755f55b0
RM
22#include <errno.h>
23#include <string.h>
196980f5
RM
24#include <stdio.h>
25
3ce1f295
UD
26#include <wchar.h>
27#define flockfile(s) _IO_flockfile (s)
28#define funlockfile(s) _IO_funlockfile (s)
50304ef0 29
196980f5
RM
30extern 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
40void
f43b8dd5
GG
41__vwarnx_internal (const char *format, __gnuc_va_list ap,
42 unsigned int mode_flags)
196980f5 43{
50304ef0 44 flockfile (stderr);
fdb16de3
FW
45 __fxprintf (stderr, "%s: ", __progname);
46 if (format != NULL)
f43b8dd5 47 __vfxprintf (stderr, format, ap, mode_flags);
fdb16de3 48 __fxprintf (stderr, "\n");
50304ef0 49 funlockfile (stderr);
196980f5
RM
50}
51
52void
f43b8dd5
GG
53__vwarn_internal (const char *format, __gnuc_va_list ap,
54 unsigned int mode_flags)
196980f5 55{
755f55b0
RM
56 int error = errno;
57
50304ef0 58 flockfile (stderr);
fdb16de3 59 if (format != NULL)
a2635361 60 {
fdb16de3 61 __fxprintf (stderr, "%s: ", __progname);
f43b8dd5 62 __vfxprintf (stderr, format, ap, mode_flags);
a2635361 63 __set_errno (error);
fdb16de3 64 __fxprintf (stderr, ": %m\n");
a2635361
UD
65 }
66 else
755f55b0 67 {
a2635361 68 __set_errno (error);
fdb16de3 69 __fxprintf (stderr, "%s: %m\n", __progname);
755f55b0 70 }
50304ef0 71 funlockfile (stderr);
196980f5 72}
f43b8dd5
GG
73
74void
75vwarn (const char *format, __gnuc_va_list ap)
76{
77 __vwarn_internal (format, ap, 0);
78}
df962917 79libc_hidden_def (vwarn)
196980f5 80
f43b8dd5
GG
81void
82vwarnx (const char *format, __gnuc_va_list ap)
83{
84 __vwarnx_internal (format, ap, 0);
85}
86libc_hidden_def (vwarnx)
196980f5
RM
87
88void
89warn (const char *format, ...)
90{
91 VA (vwarn (format, ap))
92}
a757607d 93libc_hidden_def (warn)
196980f5
RM
94
95void
96warnx (const char *format, ...)
97{
98 VA (vwarnx (format, ap))
99}
a757607d 100libc_hidden_def (warnx)
196980f5
RM
101
102void
103verr (int status, const char *format, __gnuc_va_list ap)
104{
105 vwarn (format, ap);
106 exit (status);
107}
a757607d 108libc_hidden_def (verr)
196980f5
RM
109
110void
111verrx (int status, const char *format, __gnuc_va_list ap)
112{
113 vwarnx (format, ap);
114 exit (status);
115}
a757607d 116libc_hidden_def (verrx)
196980f5
RM
117
118void
119err (int status, const char *format, ...)
120{
121 VA (verr (status, format, ap))
122}
123
124void
125errx (int status, const char *format, ...)
126{
127 VA (verrx (status, format, ap))
128}