Merge branch 'vendor/BYACC'
[dragonfly.git] / contrib / tcp_wrappers / percent_m.c
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 <string.h>
10
11 #ifndef SYS_ERRLIST_DEFINED
12 extern char *sys_errlist[];
13 extern int sys_nerr;
14 #endif
15
16 #include "mystdarg.h"
17
18 char   *percent_m(obuf, ibuf)
19 char   *obuf;
20 char   *ibuf;
21 {
22     char   *bp = obuf;
23     char   *cp = ibuf;
24
25     while ((*bp = *cp) != 0)
26         if (*cp == '%' && cp[1] == 'm') {
27             if (errno < sys_nerr && errno > 0) {
28                 strcpy(bp, sys_errlist[errno]);
29             } else {
30                 sprintf(bp, "Unknown error %d", errno);
31             }
32             bp += strlen(bp);
33             cp += 2;
34         } else {
35             bp++, cp++;
36         }
37     return (obuf);
38 }