Merge branch 'vendor/FILE'
[dragonfly.git] / contrib / tcp_wrappers / percent_m.c
CommitLineData
984263bc
MD
1 /*
2 * Replace %m by system error message.
3 *
4 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
5 */
6
7#ifndef lint
8static 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
984263bc
MD
15#ifndef SYS_ERRLIST_DEFINED
16extern char *sys_errlist[];
17extern int sys_nerr;
18#endif
19
20#include "mystdarg.h"
21
22char *percent_m(obuf, ibuf)
23char *obuf;
24char *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}