blob: 3695719dbd640aeee2cd855d1dc5169a016a9ad6 (
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
|
/* 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.
*/
#include <string.h>
char **__sys_errlist =0;
int __sys_nerr = 0;
char *
strerror(err)
int err;
{
int fd;
static char retbuf[80];
char inbuf[256];
int cc;
int bufoff = 0;
if( __sys_nerr )
{
if( err < 0 || err >= __sys_nerr ) goto unknown;
return __sys_errlist[err];
}
if( err <= 0 ) goto unknown; /* NB the <= allows comments in the file */
fd = open("/usr/lib/liberror.txt", 0);
if( fd < 0 ) goto unknown;
while( (cc=read(fd, inbuf, sizeof(inbuf))) > 0 )
{
int i;
for(i=0; i<cc; i++)
{
if( inbuf[i] == '\n' )
{
retbuf[bufoff] = '\0';
if( err == atoi(retbuf) )
{
char * p = strchr(retbuf, ' ');
if( p == 0 ) goto unknown;
while(*p == ' ') p++;
close(fd);
return p;
}
bufoff = 0;
}
else if( bufoff < sizeof(retbuf)-1 )
retbuf[bufoff++] = inbuf[i];
}
}
unknown:;
if( fd >= 0 ) close(fd);
strcpy(retbuf, "Unknown error ");
strcpy(retbuf+14, itoa(err));
return retbuf;
}
|