Default to giving real error messages.

diff --git a/MCONFIG b/MCONFIG
index a57071a..0b6575c 100644
--- a/MCONFIG
+++ b/MCONFIG
@@ -41,6 +41,11 @@
 #
 SHLIBDIR = /lib
 
+# Enable this to make perror/strerror return real error messages
+# This makes klibc.so and any static binary which uses these functions
+# about 4K bigger.
+ERRLIST = 1
+
 #
 # Include arch-specific rule fragments
 #
diff --git a/klibc/MCONFIG b/klibc/MCONFIG
index 253a946..5b6eecd 100644
--- a/klibc/MCONFIG
+++ b/klibc/MCONFIG
@@ -8,6 +8,11 @@
 include ../MRULES
 
 WARNFLAGS = -W -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Winline
+
+ifeq ($(ERRLIST),1)
+REQFLAGS += -DWITH_ERRLIST
+endif
+
 CFLAGS  = -Wp,-MD,$(dir $*).$(notdir $*).d $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS)
 
 SOFLAGS = -fPIC
diff --git a/klibc/Makefile b/klibc/Makefile
index 2ef8076..ab04879 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -43,6 +43,10 @@
 	  inet/inet_ntoa.o inet/inet_aton.o inet/inet_addr.o \
 	  inet/inet_ntop.o inet/inet_pton.o inet/bindresvport.o \
 	  send.o recv.o
+ifeq ($(ERRLIST),1)
+LIBOBJS += errlist.o
+endif
+
 SOLIB   = libc.so
 SOHASH  = klibc.so
 
@@ -108,6 +112,9 @@
 crt0.o: arch/$(ARCH)/crt0.o
 	cp arch/$(ARCH)/crt0.o .
 
+errlist.c:
+	$(PERL) makeerrlist.pl -errlist > $@ || rm -f $@
+
 # We pass -ansi to keep cpp from define e.g. "i386" as well as "__i386__"
 SYSCALLS.i: SYSCALLS.def
 	$(CC) $(CFLAGS) -D__ASSEMBLY__ -ansi -x assembler-with-cpp -E -o $@ $<
@@ -144,7 +151,7 @@
 	rm -f $(TESTS) tests/*.stripped
 	rm -rf syscalls syscalls.dir
 	rm -rf socketcalls socketcalls.dir
-	rm -f sha1hash
+	rm -f sha1hash errlist.c
 
 spotless: clean
 	find . \( -name \*~ -o -name '.*.d' \) -not -type d -print0 | \
diff --git a/klibc/perror.c b/klibc/perror.c
index 45585cd..26f8ce8 100644
--- a/klibc/perror.c
+++ b/klibc/perror.c
@@ -8,5 +8,6 @@
 
 void perror(const char *s)
 {
-  fprintf(stderr, "%s: error %d\n", s, errno);
+  int e = errno;
+  fprintf(stderr, "%s: %s\n", s, strerror(e));
 }
diff --git a/klibc/strerror.c b/klibc/strerror.c
index bc053db..c8e3eac 100644
--- a/klibc/strerror.c
+++ b/klibc/strerror.c
@@ -7,11 +7,18 @@
 char *strerror(int errnum)
 {
   static char message[32] = "error "; /* enough for error 2^63-1 */
-
   char numbuf[32];
   char *p;
   unsigned int e = (unsigned int)errnum;
 
+#ifdef WITH_ERRLIST
+  extern const int sys_nerr;
+  extern const char * const sys_errlist[];
+
+  if ( e < (unsigned int)sys_nerr && sys_errlist[e] )
+    return (char *)sys_errlist[e];
+#endif
+
   p = numbuf+sizeof numbuf;
   *--p = '\0';