* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / error / sys_errlist.c
blobf4b27c57a402ed20db0a014b83c2031190ebc11c
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 */
6 /* This is a flash way of auto-initing the error array from an external file
7 * I wouldn't be surprised tho if it's a lot better just to hard code the
8 * error messages into the array.
10 * Of course the best of all is to use strerror().
13 #if defined(__AS386_16__) || defined(__AS386_32__)
14 #define NR_ERRORS 128
16 extern char **__sys_errlist;
17 extern int __sys_nerr;
19 char *sys_errlist[NR_ERRORS];
20 int sys_nerr = NR_ERRORS;
22 #ifdef __AS386_16__
23 #asm
24 loc 1 ! Make sure the pointer is in the correct segment
25 auto_func: ! Label for bcc -M to work.
26 .word _init_vars ! Pointer to the autorun function
27 .text ! So the function after is also in the correct seg.
28 #endasm
29 #else
30 #asm
31 loc 1 ! Make sure the pointer is in the correct segment
32 auto_func: ! Label for bcc -M to work.
33 .long _init_vars ! Pointer to the autorun function
34 .text ! So the function after is also in the correct seg.
35 #endasm
36 #endif
38 static void init_vars()
40 char inbuf[256];
41 char errbuf[80];
42 int i, cc, fd, err, len, bufoff=0;
43 char * ptr;
45 fd = open("/usr/lib/bcc/liberror.txt", 0);
46 if (fd < 0) fd = open("/lib/liberror.txt", 0);
47 if( fd < 0 ) return;
49 for(i=0; i<NR_ERRORS; i++) sys_errlist[i] = "Unknown error";
51 while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 )
53 for(i=0; i<cc; i++)
55 if( inbuf[i] == '\n' )
57 errbuf[bufoff] = '\0';
58 err = atoi(errbuf);
59 ptr = strchr(errbuf, ' ');
60 if( ptr && err > 0 && err < NR_ERRORS )
62 while(*ptr == ' ') ptr++;
63 len = strlen(ptr)+1;
64 sys_errlist[err] = (void*)sbrk(len);
65 if( (int)sys_errlist[err] == -1 )
67 sys_errlist[err] == "";
68 break;
70 memcpy(sys_errlist[err], ptr, len);
72 bufoff = 0;
74 else if( bufoff < sizeof(errbuf)-1 )
75 errbuf[bufoff++] = inbuf[i];
78 close(fd);
80 __sys_errlist = sys_errlist;
81 __sys_nerr = sys_nerr = NR_ERRORS;
84 #endif /* __AS386_??__ */