xref: /freebsd/contrib/tcp_wrappers/percent_m.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1  /*
2   * Replace %m by system error message.
3   *
4   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5   */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#) percent_m.c 1.1 94/12/28 17:42:37";
9 #endif
10 
11 #include <stdio.h>
12 #include <errno.h>
13 #include <string.h>
14 
15 #ifndef SYS_ERRLIST_DEFINED
16 extern char *sys_errlist[];
17 extern int sys_nerr;
18 #endif
19 
20 #include "mystdarg.h"
21 
22 char   *percent_m(obuf, ibuf)
23 char   *obuf;
24 char   *ibuf;
25 {
26     char   *bp = obuf;
27     char   *cp = ibuf;
28 
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);
35 	    }
36 	    bp += strlen(bp);
37 	    cp += 2;
38 	} else {
39 	    bp++, cp++;
40 	}
41     return (obuf);
42 }
43