1 /* 4.4BSD utility functions for error messages.
2 Copyright (C) 1995,96,98,2001,02 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 # define flockfile(s) _IO_flockfile (s)
30 # define funlockfile(s) _IO_funlockfile (s)
33 extern char *__progname
;
38 va_start (ap, format); \
45 convert_and_print (const char *format
, __gnuc_va_list ap
)
47 # define ALLOCA_LIMIT 2000
49 wchar_t *wformat
= NULL
;
57 len
= strlen (format
) + 1;
61 if (len
< ALLOCA_LIMIT
)
62 wformat
= (wchar_t *) alloca (len
* sizeof (wchar_t));
65 if (wformat
!= NULL
&& len
/ 2 < ALLOCA_LIMIT
)
68 wformat
= (wchar_t *) realloc (wformat
, len
* sizeof (wchar_t));
72 fputws_unlocked (L
"out of memory\n", stderr
);
77 memset (&st
, '\0', sizeof (st
));
80 while ((res
= __mbsrtowcs (wformat
, &tmp
, len
, &st
)) == len
);
82 if (res
== (size_t) -1)
83 /* The string cannot be converted. */
84 wformat
= (wchar_t *) L
"???";
86 __vfwprintf (stderr
, wformat
, ap
);
91 vwarnx (const char *format
, __gnuc_va_list ap
)
95 if (_IO_fwide (stderr
, 0) > 0)
97 __fwprintf (stderr
, L
"%s: ", __progname
);
98 convert_and_print (format
, ap
);
99 putwc_unlocked (L
'\n', stderr
);
104 fprintf (stderr
, "%s: ", __progname
);
106 vfprintf (stderr
, format
, ap
);
107 putc_unlocked ('\n', stderr
);
109 funlockfile (stderr
);
111 libc_hidden_def (vwarnx
)
114 vwarn (const char *format
, __gnuc_va_list ap
)
120 if (_IO_fwide (stderr
, 0) > 0)
122 __fwprintf (stderr
, L
"%s: ", __progname
);
125 convert_and_print (format
, ap
);
126 fputws_unlocked (L
": ", stderr
);
129 __fwprintf (stderr
, L
"%m\n");
134 fprintf (stderr
, "%s: ", __progname
);
137 vfprintf (stderr
, format
, ap
);
138 fputs_unlocked (": ", stderr
);
141 fprintf (stderr
, "%m\n");
143 funlockfile (stderr
);
145 libc_hidden_def (vwarn
)
149 warn (const char *format
, ...)
151 VA (vwarn (format
, ap
))
153 libc_hidden_def (warn
)
156 warnx (const char *format
, ...)
158 VA (vwarnx (format
, ap
))
160 libc_hidden_def (warnx
)
163 verr (int status
, const char *format
, __gnuc_va_list ap
)
168 libc_hidden_def (verr
)
171 verrx (int status
, const char *format
, __gnuc_va_list ap
)
176 libc_hidden_def (verrx
)
179 err (int status
, const char *format
, ...)
181 VA (verr (status
, format
, ap
))
185 errx (int status
, const char *format
, ...)
187 VA (verrx (status
, format
, ap
))