Merge commit 'crater/master'
[dragonfly.git] / contrib / tcp_wrappers / percent_m.c
blob1019b82d8c367726ee065d383a70188287f1510f
1 /*
2 * Replace %m by system error message.
3 *
4 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5 */
7 #ifndef lint
8 static char sccsid[] = "@(#) percent_m.c 1.1 94/12/28 17:42:37";
9 #endif
11 #include <stdio.h>
12 #include <errno.h>
13 #include <string.h>
15 #ifndef SYS_ERRLIST_DEFINED
16 extern char *sys_errlist[];
17 extern int sys_nerr;
18 #endif
20 #include "mystdarg.h"
22 char *percent_m(obuf, ibuf)
23 char *obuf;
24 char *ibuf;
26 char *bp = obuf;
27 char *cp = ibuf;
29 while (*bp = *cp)
30 if (*cp == '%' && cp[1] == 'm') {
31 if (errno < sys_nerr && errno > 0) {
32 strcpy(bp, sys_errlist[errno]);
33 } else {
34 sprintf(bp, "Unknown error %d", errno);
36 bp += strlen(bp);
37 cp += 2;
38 } else {
39 bp++, cp++;
41 return (obuf);