Fix rpm.unregister() Lua extension
[platform/upstream/rpm.git] / misc / err.c
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.
4
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.
9
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.
14
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.  */
19
20 #include "system.h"
21
22 #ifdef HAVE_LIBIO_H
23 #define flockfile(s)            _IO_flockfile (s)
24 #define funlockfile(s)          _IO_funlockfile (s)
25 #else
26 #define flockfile(s)
27 #define funlockfile(s)
28 #define putc_unlocked(c,fp)     putc(c,fp);
29 #define fputs_unlocked(s,fp)    fputs(s,fp);
30 #define __set_errno(error)      errno = error
31 #define __ptr_t                 void *
32 #endif
33
34 #include <stdarg.h>
35 #include <err.h>
36
37 #define VA(call)                                                              \
38 {                                                                             \
39   va_list ap;                                                                 \
40   va_start (ap, format);                                                      \
41   call;                                                                       \
42   va_end (ap);                                                                \
43 }
44
45 void
46 vwarnx (const char *format, __gnuc_va_list ap)
47 {
48   flockfile (stderr);
49   if (__progname)
50     fprintf (stderr, "%s: ", __progname);
51   if (format)
52     vfprintf (stderr, format, ap);
53   putc_unlocked ('\n', stderr);
54   funlockfile (stderr);
55 }
56
57 void
58 vwarn (const char *format, __gnuc_va_list ap)
59 {
60   int error = errno;
61
62   flockfile (stderr);
63   if (__progname)
64     fprintf (stderr, "%s: ", __progname);
65   if (format)
66     {
67       vfprintf (stderr, format, ap);
68       fputs_unlocked (": ", stderr);
69     }
70   __set_errno (error);
71   fprintf (stderr, "%m\n");
72   funlockfile (stderr);
73 }
74
75
76 void
77 warn (const char *format, ...)
78 {
79   VA (vwarn (format, ap))
80 }
81
82 void
83 warnx (const char *format, ...)
84 {
85   VA (vwarnx (format, ap))
86 }
87
88 void
89 verr (int status, const char *format, __gnuc_va_list ap)
90 {
91   vwarn (format, ap);
92   exit (status);
93 }
94
95 void
96 verrx (int status, const char *format, __gnuc_va_list ap)
97 {
98   vwarnx (format, ap);
99   exit (status);
100 }
101
102 void
103 err (int status, const char *format, ...)
104 {
105   VA (verr (status, format, ap))
106 }
107
108 void
109 errx (int status, const char *format, ...)
110 {
111   VA (verrx (status, format, ap))
112 }