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); \
43 #ifndef HAVE_FPUTS_UNLOCKED
45 #ifndef HAVE_PUTWC_UNLOCKED
46 #ifdef HAVE_PUTW_UNLOCKED
47 #define putwc_unlocked putw_unlocked
49 #define putwc_unlocked putc_unlocked
50 #define putw_unlocked putc_unlocked
54 int fputs_unlocked(const char *str
, FILE *fp
)
59 if (putc_unlocked(*p
++, fp
) == EOF
)
66 int fputws_unlocked(const char *str
, FILE *fp
)
71 if (putw_unlocked(*p
++, fp
) == EOF
)
81 convert_and_print (const char *format
, __gnuc_va_list ap
)
83 # define ALLOCA_LIMIT 2000
85 wchar_t *wformat
= NULL
;
93 len
= strlen (format
) + 1;
97 if (len
< ALLOCA_LIMIT
)
98 wformat
= (wchar_t *) alloca (len
* sizeof (wchar_t));
101 if (wformat
!= NULL
&& len
/ 2 < ALLOCA_LIMIT
)
104 wformat
= (wchar_t *) realloc (wformat
, len
* sizeof (wchar_t));
108 fputws_unlocked (L
"out of memory\n", stderr
);
113 memset (&st
, '\0', sizeof (st
));
116 while ((res
= __mbsrtowcs (wformat
, &tmp
, len
, &st
)) == len
);
118 if (res
== (size_t) -1)
119 /* The string cannot be converted. */
120 wformat
= (wchar_t *) L
"???";
122 __vfwprintf (stderr
, wformat
, ap
);
127 vwarnx (const char *format
, __gnuc_va_list ap
)
131 if (_IO_fwide (stderr
, 0) > 0)
133 __fwprintf (stderr
, L
"%s: ", __progname
);
134 convert_and_print (format
, ap
);
135 putwc_unlocked (L
'\n', stderr
);
140 fprintf (stderr
, "%s: ", __progname
);
142 vfprintf (stderr
, format
, ap
);
143 putc_unlocked ('\n', stderr
);
145 funlockfile (stderr
);
147 //libc_hidden_def (vwarnx)
150 vwarn (const char *format
, __gnuc_va_list ap
)
156 if (_IO_fwide (stderr
, 0) > 0)
158 __fwprintf (stderr
, L
"%s: ", __progname
);
161 convert_and_print (format
, ap
);
162 fputws_unlocked (L
": ", stderr
);
164 //__set_errno (error);
165 __fwprintf (stderr
, L
"%s\n", strerror(error
));
170 fprintf (stderr
, "%s: ", __progname
);
173 vfprintf (stderr
, format
, ap
);
174 fputs_unlocked (": ", stderr
);
176 //__set_errno (error);
177 fprintf (stderr
, "%s\n", strerror(error
));
179 funlockfile (stderr
);
181 //libc_hidden_def (vwarn)
185 warn (const char *format
, ...)
187 VA (vwarn (format
, ap
))
189 //libc_hidden_def (warn)
192 warnx (const char *format
, ...)
194 VA (vwarnx (format
, ap
))
196 //libc_hidden_def (warnx)
199 verr (int status
, const char *format
, __gnuc_va_list ap
)
204 //libc_hidden_def (verr)
207 verrx (int status
, const char *format
, __gnuc_va_list ap
)
212 //libc_hidden_def (verrx)
215 err (int status
, const char *format
, ...)
217 VA (verr (status
, format
, ap
))
221 errx (int status
, const char *format
, ...)
223 VA (verrx (status
, format
, ap
))