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 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. 9 * 10 * Of course the best of all is to use strerror(). 11 */ 12 13 #if defined(__AS386_16__) || defined(__AS386_32__) 14 #define NR_ERRORS 128 15 16 extern char **__sys_errlist; 17 extern int __sys_nerr; 18 19 char *sys_errlist[NR_ERRORS]; 20 int sys_nerr = NR_ERRORS; 21 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 37 38 static void init_vars() 39 { 40 char inbuf[256]; 41 char errbuf[80]; 42 int i, cc, fd, err, len, bufoff=0; 43 char * ptr; 44 45 fd = open("/lib/liberror.txt", 0); 46 if( fd < 0 ) return; 47 48 for(i=0; i<NR_ERRORS; i++) sys_errlist[i] = "Unknown error"; 49 50 while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 ) 51 { 52 for(i=0; i<cc; i++) 53 { 54 if( inbuf[i] == '\n' ) 55 { 56 errbuf[bufoff] = '\0'; 57 err = atoi(errbuf); 58 ptr = strchr(errbuf, ' '); 59 if( ptr && err > 0 && err < NR_ERRORS ) 60 { 61 while(*ptr == ' ') ptr++; 62 len = strlen(ptr)+1; 63 sys_errlist[err] = (void*)sbrk(len); 64 if( (int)sys_errlist[err] == -1 ) 65 { 66 sys_errlist[err] == ""; 67 break; 68 } 69 memcpy(sys_errlist[err], ptr, len); 70 } 71 bufoff = 0; 72 } 73 else if( bufoff < sizeof(errbuf)-1 ) 74 errbuf[bufoff++] = inbuf[i]; 75 } 76 } 77 close(fd); 78 79 __sys_errlist = sys_errlist; 80 __sys_nerr = sys_nerr = NR_ERRORS; 81 } 82 83 #endif /* __AS386_??__ */ 84