1 /* 4.4BSD utility functions for error messages.
2 Copyright (C) 1995, 1996, 1998, 2001 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
);
113 vwarn (const char *format
, __gnuc_va_list ap
)
119 if (_IO_fwide (stderr
, 0) > 0)
121 __fwprintf (stderr
, L
"%s: ", __progname
);
124 convert_and_print (format
, ap
);
125 fputws_unlocked (L
": ", stderr
);
128 __fwprintf (stderr
, L
"%m\n");
133 fprintf (stderr
, "%s: ", __progname
);
136 vfprintf (stderr
, format
, ap
);
137 fputs_unlocked (": ", stderr
);
140 fprintf (stderr
, "%m\n");
142 funlockfile (stderr
);
147 warn (const char *format
, ...)
149 VA (vwarn (format
, ap
))
153 warnx (const char *format
, ...)
155 VA (vwarnx (format
, ap
))
159 verr (int status
, const char *format
, __gnuc_va_list ap
)
166 verrx (int status
, const char *format
, __gnuc_va_list ap
)
173 err (int status
, const char *format
, ...)
175 VA (verr (status
, format
, ap
))
179 errx (int status
, const char *format
, ...)
181 VA (verrx (status
, format
, ap
))