137340Sbostic /* 237340Sbostic * Copyright (c) 1988 Regents of the University of California. 337340Sbostic * All rights reserved. 437340Sbostic * 542635Sbostic * %sccs.include.redist.c% 637340Sbostic */ 737340Sbostic 837340Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*49064Sbostic static char sccsid[] = "@(#)strerror.c 5.6 (Berkeley) 05/04/91"; 1037340Sbostic #endif /* LIBC_SCCS and not lint */ 1137340Sbostic 1242181Sbostic #include <string.h> 1342181Sbostic 1437340Sbostic char * 15*49064Sbostic strerror(num) 16*49064Sbostic int num; 1737340Sbostic { 1837340Sbostic extern int sys_nerr; 1937340Sbostic extern char *sys_errlist[]; 20*49064Sbostic #define UPREFIX "Unknown error: " 21*49064Sbostic static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ 22*49064Sbostic register unsigned int errnum; 23*49064Sbostic register char *p, *t; 24*49064Sbostic char tmp[40]; 2537340Sbostic 26*49064Sbostic errnum = num; /* convert to unsigned */ 27*49064Sbostic if (errnum < sys_nerr) 2837340Sbostic return(sys_errlist[errnum]); 29*49064Sbostic 30*49064Sbostic /* Do this by hand, so we don't include stdio(3). */ 31*49064Sbostic t = tmp; 32*49064Sbostic do { 33*49064Sbostic *t++ = "0123456789"[errnum % 10]; 34*49064Sbostic } while (errnum /= 10); 35*49064Sbostic for (p = ebuf + sizeof(UPREFIX) - 1;;) { 36*49064Sbostic *p++ = *--t; 37*49064Sbostic if (t <= tmp) 38*49064Sbostic break; 39*49064Sbostic } 4037340Sbostic return(ebuf); 4137340Sbostic } 42