Update.
[glibc.git] / misc / err.c
blob3482944271e1ac3d5b6c59bf217783f570c921f2
1 /* err.c --- 4.4BSD utility functions for error messages.
2 Copyright (C) 1995, 1996, 1998 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <stdarg.h>
21 #include <err.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <string.h>
25 #include <stdio.h>
27 #ifdef USE_IN_LIBIO
28 # define flockfile(s) _IO_flockfile (s)
29 # define funlockfile(s) _IO_funlockfile (s)
30 #endif
32 extern char *__progname;
34 #define VA(call) \
35 { \
36 va_list ap; \
37 va_start (ap, format); \
38 call; \
39 va_end (ap); \
42 void
43 vwarnx (const char *format, __gnuc_va_list ap)
45 flockfile (stderr);
46 if (__progname)
47 fprintf (stderr, "%s: ", __progname);
48 if (format)
49 vfprintf (stderr, format, ap);
50 putc_unlocked ('\n', stderr);
51 funlockfile (stderr);
54 void
55 vwarn (const char *format, __gnuc_va_list ap)
57 int error = errno;
59 flockfile (stderr);
60 if (__progname)
61 fprintf (stderr, "%s: ", __progname);
62 if (format)
64 vfprintf (stderr, format, ap);
65 fputs_unlocked (": ", stderr);
67 __set_errno (error);
68 fprintf (stderr, "%m\n");
69 funlockfile (stderr);
73 void
74 warn (const char *format, ...)
76 VA (vwarn (format, ap))
79 void
80 warnx (const char *format, ...)
82 VA (vwarnx (format, ap))
85 void
86 verr (int status, const char *format, __gnuc_va_list ap)
88 vwarn (format, ap);
89 exit (status);
92 void
93 verrx (int status, const char *format, __gnuc_va_list ap)
95 vwarnx (format, ap);
96 exit (status);
99 void
100 err (int status, const char *format, ...)
102 VA (verr (status, format, ap))
105 void
106 errx (int status, const char *format, ...)
108 VA (verrx (status, format, ap))