xref: /freebsd/contrib/tcp_wrappers/percent_m.c (revision 2b833162)
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(char *obuf, char *ibuf)
23 {
24     char   *bp = obuf;
25     char   *cp = ibuf;
26 
27     while (*bp = *cp)
28 	if (*cp == '%' && cp[1] == 'm') {
29 	    if (errno < sys_nerr && errno > 0) {
30 		strcpy(bp, sys_errlist[errno]);
31 	    } else {
32 		sprintf(bp, "Unknown error %d", errno);
33 	    }
34 	    bp += strlen(bp);
35 	    cp += 2;
36 	} else {
37 	    bp++, cp++;
38 	}
39     return (obuf);
40 }
41