137340Sbostic /* 2*61193Sbostic * Copyright (c) 1988, 1993 3*61193Sbostic * The Regents of the University of California. All rights reserved. 437340Sbostic * 542635Sbostic * %sccs.include.redist.c% 637340Sbostic */ 737340Sbostic 837340Sbostic #if defined(LIBC_SCCS) && !defined(lint) 9*61193Sbostic static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 06/04/93"; 1037340Sbostic #endif /* LIBC_SCCS and not lint */ 1137340Sbostic 1242181Sbostic #include <string.h> 1342181Sbostic 1437340Sbostic char * strerror(num)1549064Sbosticstrerror(num) 1649064Sbostic int num; 1737340Sbostic { 1837340Sbostic extern int sys_nerr; 1937340Sbostic extern char *sys_errlist[]; 2049064Sbostic #define UPREFIX "Unknown error: " 2149064Sbostic static char ebuf[40] = UPREFIX; /* 64-bit number + slop */ 2249064Sbostic register unsigned int errnum; 2349064Sbostic register char *p, *t; 2449064Sbostic char tmp[40]; 2537340Sbostic 2649064Sbostic errnum = num; /* convert to unsigned */ 2749064Sbostic if (errnum < sys_nerr) 2837340Sbostic return(sys_errlist[errnum]); 2949064Sbostic 3049064Sbostic /* Do this by hand, so we don't include stdio(3). */ 3149064Sbostic t = tmp; 3249064Sbostic do { 3349064Sbostic *t++ = "0123456789"[errnum % 10]; 3449064Sbostic } while (errnum /= 10); 3549064Sbostic for (p = ebuf + sizeof(UPREFIX) - 1;;) { 3649064Sbostic *p++ = *--t; 3749064Sbostic if (t <= tmp) 3849064Sbostic break; 3949064Sbostic } 4037340Sbostic return(ebuf); 4137340Sbostic } 42