* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / error / error.c
blob3edec7dd9fefa5e452591cbea577311b135440b3
1 /* Copyright (C) 1996 Robert de Bath <robert@debath.thenet.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
4 */
5 #include <string.h>
7 char **__sys_errlist =0;
8 int __sys_nerr = 0;
10 char *
11 strerror(err)
12 int err;
14 int fd;
15 static char retbuf[80];
16 char inbuf[256];
17 int cc;
18 int bufoff = 0;
20 if( __sys_nerr )
22 if( err < 0 || err >= __sys_nerr ) goto unknown;
23 return __sys_errlist[err];
26 if( err <= 0 ) goto unknown; /* NB the <= allows comments in the file */
27 fd = open("/usr/lib/bcc/liberror.txt", 0);
28 if (fd < 0) fd = open("/lib/liberror.txt", 0);
29 if( fd < 0 ) goto unknown;
31 while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 )
33 int i;
34 for(i=0; i<cc; i++)
36 if( inbuf[i] == '\n' )
38 retbuf[bufoff] = '\0';
39 if( err == atoi(retbuf) )
41 char * p = strchr(retbuf, ' ');
42 if( p == 0 ) goto unknown;
43 while(*p == ' ') p++;
44 close(fd);
45 return p;
47 bufoff = 0;
49 else if( bufoff < sizeof(retbuf)-1 )
50 retbuf[bufoff++] = inbuf[i];
53 unknown:;
54 if( fd >= 0 ) close(fd);
55 strcpy(retbuf, "Unknown error ");
56 strcpy(retbuf+14, itoa(err));
57 return retbuf;