Add errc, warnc, verrc and vwarnc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
diff --git a/ChangeLog b/ChangeLog
index 374b86c..f33a120 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
+2006-02-10 Robert Millan <rmh@aybabtu.com>
+
+ Add errc, warnc, verrc and vwarnc.
+ * err.c: New.
+ * include/bsd/err.h: New.
+ * Versions: Add them.
+ * Makefile: Add err.c and include/bsd/err.h.
+
2005-12-19 Aurelien Jarno <aurel32@debian.org>
- * Added manpages
+ * Added manpages
* fmtcheck.c: new
* include/stdlib.h: added fmtcheck
* Versions: added fmtcheck
diff --git a/Makefile b/Makefile
index ddcae17..5190820 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,9 @@
# $Id$
#
-LIB_SRCS = arc4random.c fgetln.c inet_net_pton.c strlcat.c strlcpy.c md5c.c fmtcheck.c
+LIB_SRCS = arc4random.c err.c fgetln.c inet_net_pton.c strlcat.c strlcpy.c md5c.c fmtcheck.c
-LIB_INCLUDES = include/bsd/ip_icmp.h include/bsd/random.h include/bsd/queue.h include/bsd/md5.h include/bsd/string.h include/bsd/bsd.h include/bsd/stdlib.h
+LIB_INCLUDES = include/bsd/err.h include/bsd/ip_icmp.h include/bsd/random.h include/bsd/queue.h include/bsd/md5.h include/bsd/string.h include/bsd/bsd.h include/bsd/stdlib.h
LIB_MANS = man/arc4random.3 man/strlcpy.3 man/fgetln.3 man/fmtcheck.3
diff --git a/Versions b/Versions
index 23091f1..49e068c 100644
--- a/Versions
+++ b/Versions
@@ -1,6 +1,7 @@
LIBBSD_0.0 {
global:
arc4random;
+ errc; warnc; verrc; vwarnc;
fgetln;
fgetwln;
fmtcheck;
diff --git a/err.c b/err.c
new file mode 100644
index 0000000..49ea0ef
--- /dev/null
+++ b/err.c
@@ -0,0 +1,63 @@
+/* Copyright (C) 2006 Robert Millan
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#include <bsd/err.h>
+#include <errno.h>
+#include <stdarg.h>
+
+void
+warnc (int code, const char *format, ...)
+{
+ int tmp = errno;
+ va_list ap;
+ va_start (ap, format);
+
+ errno = code;
+ warn (format, ap);
+ errno = tmp;
+
+ va_end (ap);
+}
+
+void
+vwarnc (int code, const char *format, va_list ap)
+{
+ int tmp = errno;
+
+ errno = code;
+ vwarn (format, ap);
+ errno = tmp;
+}
+
+void
+errc (int status, int code, const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+
+ errno = code;
+ err (status, format, ap);
+
+ va_end (ap);
+}
+
+void
+verrc (int status, int code, const char *format, va_list ap)
+{
+ errno = code;
+ verr (status, format, ap);
+}
diff --git a/include/bsd/err.h b/include/bsd/err.h
new file mode 100644
index 0000000..ab9ac90
--- /dev/null
+++ b/include/bsd/err.h
@@ -0,0 +1,11 @@
+#ifndef LIBBSD_ERR_H
+#define LIBBSD_ERR_H
+
+#include <err.h>
+
+extern void warnc (int code, const char *format, ...);
+extern void vwarnc (int code, const char *format, va_list ap);
+extern void errc (int status, int code, const char *format, ...);
+extern void verrc (int status, int code, const char *format, va_list ap);
+
+#endif