summaryrefslogtreecommitdiff
path: root/libc/error/sys_errlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/error/sys_errlist.c')
-rw-r--r--libc/error/sys_errlist.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/libc/error/sys_errlist.c b/libc/error/sys_errlist.c
new file mode 100644
index 0000000..1d9e65b
--- /dev/null
+++ b/libc/error/sys_errlist.c
@@ -0,0 +1,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__ */