1 /* 4.4BSD utility functions for error messages.
2 Copyright (C) 1995-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
27 #define flockfile(s) _IO_flockfile (s)
28 #define funlockfile(s) _IO_funlockfile (s)
30 extern char *__progname
;
35 va_start (ap, format); \
41 convert_and_print (const char *format
, __gnuc_va_list ap
)
43 #define ALLOCA_LIMIT 2000
45 wchar_t *wformat
= NULL
;
53 len
= strlen (format
) + 1;
57 if (len
< ALLOCA_LIMIT
)
58 wformat
= (wchar_t *) alloca (len
* sizeof (wchar_t));
61 if (wformat
!= NULL
&& len
/ 2 < ALLOCA_LIMIT
)
64 wformat
= (wchar_t *) realloc (wformat
, len
* sizeof (wchar_t));
68 fputws_unlocked (L
"out of memory\n", stderr
);
73 memset (&st
, '\0', sizeof (st
));
76 while ((res
= __mbsrtowcs (wformat
, &tmp
, len
, &st
)) == len
);
78 if (res
== (size_t) -1)
79 /* The string cannot be converted. */
80 wformat
= (wchar_t *) L
"???";
82 __vfwprintf (stderr
, wformat
, ap
);
86 vwarnx (const char *format
, __gnuc_va_list ap
)
89 if (_IO_fwide (stderr
, 0) > 0)
91 __fwprintf (stderr
, L
"%s: ", __progname
);
92 convert_and_print (format
, ap
);
93 putwc_unlocked (L
'\n', stderr
);
97 fprintf (stderr
, "%s: ", __progname
);
99 vfprintf (stderr
, format
, ap
);
100 putc_unlocked ('\n', stderr
);
102 funlockfile (stderr
);
104 libc_hidden_def (vwarnx
)
107 vwarn (const char *format
, __gnuc_va_list ap
)
112 if (_IO_fwide (stderr
, 0) > 0)
114 __fwprintf (stderr
, L
"%s: ", __progname
);
117 convert_and_print (format
, ap
);
118 fputws_unlocked (L
": ", stderr
);
121 __fwprintf (stderr
, L
"%m\n");
125 fprintf (stderr
, "%s: ", __progname
);
128 vfprintf (stderr
, format
, ap
);
129 fputs_unlocked (": ", stderr
);
132 fprintf (stderr
, "%m\n");
134 funlockfile (stderr
);
136 libc_hidden_def (vwarn
)
140 warn (const char *format
, ...)
142 VA (vwarn (format
, ap
))
144 libc_hidden_def (warn
)
147 warnx (const char *format
, ...)
149 VA (vwarnx (format
, ap
))
151 libc_hidden_def (warnx
)
154 verr (int status
, const char *format
, __gnuc_va_list ap
)
159 libc_hidden_def (verr
)
162 verrx (int status
, const char *format
, __gnuc_va_list ap
)
167 libc_hidden_def (verrx
)
170 err (int status
, const char *format
, ...)
172 VA (verr (status
, format
, ap
))
176 errx (int status
, const char *format
, ...)
178 VA (verrx (status
, format
, ap
))