summaryrefslogtreecommitdiff
path: root/lib/libwrap/percent_m.c
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1997-02-26 03:07:00 +0000
committerJason Downs <downsj@cvs.openbsd.org>1997-02-26 03:07:00 +0000
commit805f364a7afb206a7c89e333232aca351b6e19e0 (patch)
treeabb8889a3045ea5aa67c32f60cbd18196419b899 /lib/libwrap/percent_m.c
parent69b5d60558dcb932964f8d6d64517209707041b5 (diff)
Initial integration of a much cleaned up libwrap.
Diffstat (limited to 'lib/libwrap/percent_m.c')
-rw-r--r--lib/libwrap/percent_m.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/libwrap/percent_m.c b/lib/libwrap/percent_m.c
new file mode 100644
index 00000000000..86f531619ea
--- /dev/null
+++ b/lib/libwrap/percent_m.c
@@ -0,0 +1,49 @@
+/* $OpenBSD: percent_m.c,v 1.1 1997/02/26 03:06:54 downsj Exp $ */
+
+ /*
+ * Replace %m by system error message.
+ *
+ * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#) percent_m.c 1.1 94/12/28 17:42:37";
+#else
+static char rcsid[] = "$OpenBSD: percent_m.c,v 1.1 1997/02/26 03:06:54 downsj Exp $";
+#endif
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <string.h>
+
+extern int errno;
+#ifndef SYS_ERRLIST_DEFINED
+extern char *sys_errlist[];
+extern int sys_nerr;
+#endif
+
+char *percent_m(obuf, ibuf)
+char *obuf;
+char *ibuf;
+{
+ char *bp = obuf;
+ char *cp = ibuf;
+
+ while ((*bp = *cp)) {
+ if (*cp == '%' && cp[1] == 'm') {
+ if (errno < sys_nerr && errno > 0) {
+ strcpy(bp, sys_errlist[errno]);
+ } else {
+ sprintf(bp, "Unknown error %d", errno);
+ }
+ bp += strlen(bp);
+ cp += 2;
+ } else {
+ bp++, cp++;
+ }
+ }
+ return (obuf);
+}