Home | History | Annotate | Line # | Download | only in tcpdchk
      1 /*	$NetBSD: percent_m.c,v 1.5 2018/01/23 21:06:26 sevan 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.5 2018/01/23 21:06:26 sevan Exp $");
     15 #endif
     16 #endif
     17 
     18 #include <stdio.h>
     19 #include <errno.h>
     20 #include <string.h>
     21 
     22 #ifndef SYS_ERRLIST_DEFINED
     23 extern char *sys_errlist[];
     24 extern int sys_nerr;
     25 #endif
     26 
     27 #include "mystdarg.h"
     28 #include "percent_m.h"
     29 
     30 char *percent_m(char *obuf, const char *ibuf)
     31 {
     32     char   *bp = obuf;
     33     const char   *cp = ibuf;
     34 
     35     while ((*bp = *cp) != '\0')
     36 	if (*cp == '%' && cp[1] == 'm') {
     37 	    strcpy(bp, strerror(errno));
     38 	    bp += strlen(bp);
     39 	    cp += 2;
     40 	} else {
     41 	    bp++, cp++;
     42 	}
     43     return (obuf);
     44 }
     45