blob: 1d9e65b4e07df7318ab59f376c4744f3491498f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* Copyright (C) 1996 Robert de Bath <robert@debath.thenet.co.uk>
* This file is part of the Linux-8086 C library and is distributed
* under the GNU Library General Public License.
*/
/* This is a flash way of auto-initing the error array from an external file
* I wouldn't be surprised tho if it's a lot better just to hard code the
* error messages into the array.
*
* Of course the best of all is to use strerror().
*/
#ifdef __AS386_16__
#define NR_ERRORS 128
extern char **__sys_errlist;
extern int __sys_nerr;
char *sys_errlist[NR_ERRORS];
int sys_nerr = NR_ERRORS;
#asm
loc 1 ! Make sure the pointer is in the correct segment
auto_func: ! Label for bcc -M to work.
.word _init_vars ! Pointer to the autorun function
.word no_op ! Space filler cause segs are padded to 4 bytes.
.text ! So the function after is also in the correct seg.
#endasm
static void init_vars()
{
char inbuf[256];
char errbuf[80];
int i, cc, fd, err, len, bufoff=0;
char * ptr;
fd = open("/usr/lib/liberror.txt", 0);
if( fd < 0 ) return;
for(i=0; i<NR_ERRORS; i++) sys_errlist[i] = "Unknown error";
while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 )
{
for(i=0; i<cc; i++)
{
if( inbuf[i] == '\n' )
{
errbuf[bufoff] = '\0';
err = atoi(errbuf);
ptr = strchr(errbuf, ' ');
if( ptr && err > 0 && err < NR_ERRORS )
{
while(*ptr == ' ') ptr++;
len = strlen(ptr)+1;
sys_errlist[err] = (void*)sbrk(len);
if( (int)sys_errlist[err] == -1 )
{
sys_errlist[err] == "";
break;
}
memcpy(sys_errlist[err], ptr, len);
}
bufoff = 0;
}
else if( bufoff < sizeof(errbuf)-1 )
errbuf[bufoff++] = inbuf[i];
}
}
close(fd);
__sys_errlist = sys_errlist;
__sys_nerr = sys_nerr = NR_ERRORS;
}
#endif /* __AS386_16__ */
|