1 /* 4.4BSD utility functions for error messages.
2 Copyright (C) 1995,1996,1998,2001,2002,2011 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
28 #define flockfile(s) _IO_flockfile (s)
29 #define funlockfile(s) _IO_funlockfile (s)
31 extern char *__progname
;
36 va_start (ap, format); \
42 convert_and_print (const char *format
, __gnuc_va_list ap
)
44 #define ALLOCA_LIMIT 2000
46 wchar_t *wformat
= NULL
;
54 len
= strlen (format
) + 1;
58 if (len
< ALLOCA_LIMIT
)
59 wformat
= (wchar_t *) alloca (len
* sizeof (wchar_t));
62 if (wformat
!= NULL
&& len
/ 2 < ALLOCA_LIMIT
)
65 wformat
= (wchar_t *) realloc (wformat
, len
* sizeof (wchar_t));
69 fputws_unlocked (L
"out of memory\n", stderr
);
74 memset (&st
, '\0', sizeof (st
));
77 while ((res
= __mbsrtowcs (wformat
, &tmp
, len
, &st
)) == len
);
79 if (res
== (size_t) -1)
80 /* The string cannot be converted. */
81 wformat
= (wchar_t *) L
"???";
83 __vfwprintf (stderr
, wformat
, ap
);
87 vwarnx (const char *format
, __gnuc_va_list ap
)
90 if (_IO_fwide (stderr
, 0) > 0)
92 __fwprintf (stderr
, L
"%s: ", __progname
);
93 convert_and_print (format
, ap
);
94 putwc_unlocked (L
'\n', stderr
);
98 fprintf (stderr
, "%s: ", __progname
);
100 vfprintf (stderr
, format
, ap
);
101 putc_unlocked ('\n', stderr
);
103 funlockfile (stderr
);
105 libc_hidden_def (vwarnx
)
108 vwarn (const char *format
, __gnuc_va_list ap
)
113 if (_IO_fwide (stderr
, 0) > 0)
115 __fwprintf (stderr
, L
"%s: ", __progname
);
118 convert_and_print (format
, ap
);
119 fputws_unlocked (L
": ", stderr
);
122 __fwprintf (stderr
, L
"%m\n");
126 fprintf (stderr
, "%s: ", __progname
);
129 vfprintf (stderr
, format
, ap
);
130 fputs_unlocked (": ", stderr
);
133 fprintf (stderr
, "%m\n");
135 funlockfile (stderr
);
137 libc_hidden_def (vwarn
)
141 warn (const char *format
, ...)
143 VA (vwarn (format
, ap
))
145 libc_hidden_def (warn
)
148 warnx (const char *format
, ...)
150 VA (vwarnx (format
, ap
))
152 libc_hidden_def (warnx
)
155 verr (int status
, const char *format
, __gnuc_va_list ap
)
160 libc_hidden_def (verr
)
163 verrx (int status
, const char *format
, __gnuc_va_list ap
)
168 libc_hidden_def (verrx
)
171 err (int status
, const char *format
, ...)
173 VA (verr (status
, format
, ap
))
177 errx (int status
, const char *format
, ...)
179 VA (verrx (status
, format
, ap
))