xref: /titanic_41/usr/src/lib/libwrap/percent_m.c (revision c2580b931007758eab8cb5ae8726ebe1588e259b)
1 /*
2  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 #pragma ident	"%Z%%M%	%I%	%E% SMI"
6 
7  /*
8   * Replace %m by system error message.
9   *
10   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
11   */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#) percent_m.c 1.1 94/12/28 17:42:37";
15 #endif
16 
17 #include <stdio.h>
18 #include <errno.h>
19 #include <string.h>
20 
21 extern int errno;
22 #ifndef SYS_ERRLIST_DEFINED
23 extern char *sys_errlist[];
24 extern int sys_nerr;
25 #endif
26 
27 #include "mystdarg.h"
28 
29 char   *percent_m(obuf, ibuf)
30 char   *obuf;
31 char   *ibuf;
32 {
33     char   *bp = obuf;
34     char   *cp = ibuf;
35 
36     while (*bp = *cp)
37 	if (*cp == '%' && cp[1] == 'm') {
38 	    if (errno < sys_nerr && errno > 0) {
39 		strcpy(bp, sys_errlist[errno]);
40 	    } else {
41 		sprintf(bp, "Unknown error %d", errno);
42 	    }
43 	    bp += strlen(bp);
44 	    cp += 2;
45 	} else {
46 	    bp++, cp++;
47 	}
48     return (obuf);
49 }
50