aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2004-06-18 00:08:03 +0000
committerH. Peter Anvin <hpa@zytor.com>2004-06-18 00:08:03 +0000
commit7c484677f4acdf4ac88c24cc7fbea833d5167aa6 (patch)
treead70d1df3c8d045a1f498e5bc7481cff19cbeeee
parent91bc06ab4ecb55fcab13b65b3a53d2bde9494bbb (diff)
downloadklibc-7c484677f4acdf4ac88c24cc7fbea833d5167aa6.tar.gz
Default to giving real error messages.klibc-0.146
-rw-r--r--MCONFIG5
-rw-r--r--klibc/MCONFIG5
-rw-r--r--klibc/Makefile9
-rw-r--r--klibc/perror.c3
-rw-r--r--klibc/strerror.c9
5 files changed, 28 insertions, 3 deletions
diff --git a/MCONFIG b/MCONFIG
index a57071a6b5dc1..0b6575cd32b74 100644
--- a/MCONFIG
+++ b/MCONFIG
@@ -41,6 +41,11 @@ LIBSHARED = $(KLIBSRC)/libc.so
#
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 253a9461b7289..5b6eecd037ed5 100644
--- a/klibc/MCONFIG
+++ b/klibc/MCONFIG
@@ -8,6 +8,11 @@ include ../MCONFIG
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 2ef8076e357fb..ab04879336319 100644
--- a/klibc/Makefile
+++ b/klibc/Makefile
@@ -43,6 +43,10 @@ LIBOBJS = vsnprintf.o snprintf.o vsprintf.o sprintf.o \
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 @@ interp.o: interp.S $(SOLIB).hash
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 @@ clean: archclean
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 45585cd57739e..26f8ce8f6d963 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 bc053dbca9eb0..c8e3eac793517 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';