summaryrefslogtreecommitdiff
path: root/libc/error/error.c
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-03-24 21:25:23 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:29:54 +0200
commitdcc973ea3e31710429858c99d4f040334ac67c06 (patch)
tree8883b902eb18eba489957b7f03caa491fd7992a7 /libc/error/error.c
parentfe22c37817ce338fbbc90b239320248c270957fa (diff)
downloaddev86-dcc973ea3e31710429858c99d4f040334ac67c06.tar.gz
Import Dev86-0.0.5.tar.gzv0.0.5
Diffstat (limited to 'libc/error/error.c')
-rw-r--r--libc/error/error.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/libc/error/error.c b/libc/error/error.c
new file mode 100644
index 0000000..3695719
--- /dev/null
+++ b/libc/error/error.c
@@ -0,0 +1,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;
+}