Home | History | Annotate | Line # | Download | only in tcpdchk
percent_m.c revision 1.2
      1 /*	$NetBSD: percent_m.c,v 1.2 1997/10/11 21:41:40 christos Exp $	*/
      2 
      3  /*
      4   * Replace %m by system error message.
      5   *
      6   * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
      7   */
      8 
      9 #include <sys/cdefs.h>
     10 #ifndef lint
     11 #if 0
     12 static char sccsid[] = "@(#) percent_m.c 1.1 94/12/28 17:42:37";
     13 #else
     14 __RCSID("$NetBSD: percent_m.c,v 1.2 1997/10/11 21:41:40 christos Exp $");
     15 #endif
     16 #endif
     17 
     18 #include <stdio.h>
     19 #include <errno.h>
     20 #include <string.h>
     21 
     22 extern int errno;
     23 #ifndef SYS_ERRLIST_DEFINED
     24 extern char *sys_errlist[];
     25 extern int sys_nerr;
     26 #endif
     27 
     28 #include "mystdarg.h"
     29 #include "percent_m.h"
     30 
     31 char   *percent_m(obuf, ibuf)
     32 char   *obuf;
     33 const char   *ibuf;
     34 {
     35     char   *bp = obuf;
     36     const char   *cp = ibuf;
     37 
     38     while ((*bp = *cp) != '\0')
     39 	if (*cp == '%' && cp[1] == 'm') {
     40 	    if (errno < sys_nerr && errno > 0) {
     41 		strcpy(bp, sys_errlist[errno]);
     42 	    } else {
     43 		sprintf(bp, "Unknown error %d", errno);
     44 	    }
     45 	    bp += strlen(bp);
     46 	    cp += 2;
     47 	} else {
     48 	    bp++, cp++;
     49 	}
     50     return (obuf);
     51 }
     52