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