1  /*
2   * Replace %m by system error message.
3   *
4   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5   */
6 
7 #include <stdio.h>
8 #include <errno.h>
9 #include <stdarg.h>
10 #include <string.h>
11 
12 #ifndef SYS_ERRLIST_DEFINED
13 extern char *sys_errlist[];
14 extern int sys_nerr;
15 #endif
16 
17 char   *percent_m(obuf, ibuf)
18 char   *obuf;
19 char   *ibuf;
20 {
21     char   *bp = obuf;
22     char   *cp = ibuf;
23 
24     while ((*bp = *cp) != 0)
25 	if (*cp == '%' && cp[1] == 'm') {
26 	    if (errno < sys_nerr && errno > 0) {
27 		strcpy(bp, sys_errlist[errno]);
28 	    } else {
29 		sprintf(bp, "Unknown error %d", errno);
30 	    }
31 	    bp += strlen(bp);
32 	    cp += 2;
33 	} else {
34 	    bp++, cp++;
35 	}
36     return (obuf);
37 }
38