aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-11-07 07:31:13 +0000
committerMatt Fleming <matt.fleming@intel.com>2012-11-07 07:31:13 +0000
commite77d9908b4c701cb1ea6f87ccb8100a9bb3fb0fc (patch)
treef5d0b580d658ef68391fa3ab8bec903ed8a54dff
parentf754b1c3bf244a50db9d5e27d9d19f66d98483c0 (diff)
parentf2dcc2af485342a25a4fc9b8f38bbbd503ec2f16 (diff)
downloadsyslinux-e77d9908b4c701cb1ea6f87ccb8100a9bb3fb0fc.tar.gz
Merge branch 'strerror-for-mfleming' of git://github.com/geneC/syslinux into elflink
Pull klibc strerror() patches from Gene Cumm, Update strerror() to give english messages * 'strerror-for-mfleming' of git://github.com/geneC/syslinux: com32 strerror(): Remove macro WITH_ERRLIST use com32 strerror: add errlist.o to Make strerror: Use klibc version
-rw-r--r--.gitignore1
-rw-r--r--com32/lib/Makefile7
-rw-r--r--com32/lib/makeerrlist.pl98
-rw-r--r--com32/lib/strerror.c28
4 files changed, 122 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 98ea19f8..867e8220 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,6 +30,7 @@
\#*
.\#*
.depend
+/com32/lib/errlist.c
/com32/lib/sys/vesa/alphatbl.c
/diag/geodsp/mk-lba-img
/extlinux/extlinux
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index fc5defc5..84f65c1f 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -121,7 +121,7 @@ LIBOTHER_OBJS = \
mempcpy.o memmem.o memmove.o memswap.o \
perror.o qsort.o seed48.o \
srand48.o sscanf.o strcasecmp.o strcat.o \
- strerror.o \
+ strerror.o errlist.o \
strnlen.o \
strncat.o strndup.o \
stpncpy.o \
@@ -229,7 +229,7 @@ libcom32core.a : $(CORELIBOBJS)
$(RANLIB) $@
tidy dist clean:
- rm -f sys/vesa/alphatbl.c
+ rm -f sys/vesa/alphatbl.c errlist.c
find . \( -name \*.o -o -name \*.a -o -name .\*.d -o -name \*.tmp \) -print0 | \
xargs -0r rm -f
@@ -243,6 +243,9 @@ install: all
-rm -rf $(INSTALLROOT)$(COM32DIR)/include
cp -r ../include $(INSTALLROOT)$(COM32DIR)
+errlist.c: makeerrlist.pl ../include/errno.h
+ $(PERL) $< $(CFLAGS) -errlist > $@ || rm -f $@
+
# These files are performance critical, and doesn't compile well with -Os
sys/vesa/drawtxt.o: sys/vesa/drawtxt.c
$(CC) $(MAKEDEPS) $(CFLAGS) -O3 -c -o $@ $<
diff --git a/com32/lib/makeerrlist.pl b/com32/lib/makeerrlist.pl
new file mode 100644
index 00000000..9243b9dd
--- /dev/null
+++ b/com32/lib/makeerrlist.pl
@@ -0,0 +1,98 @@
+#!/usr/bin/perl
+#
+# This creates sys_errlist from <asm/errno.h> through somewhat
+# heuristic matching. It presumes the relevant entries are of the form
+# #define Exxxx <integer> /* comment */
+#
+
+use FileHandle;
+
+%errors = ();
+%errmsg = ();
+$maxerr = -1;
+@includelist = (); # Include directories
+
+sub parse_file($) {
+ my($file) = @_;
+ my($fh) = new FileHandle;
+ my($line, $error, $msg);
+ my($kernelonly) = 0;
+ my($root);
+
+ print STDERR "opening $file\n" unless ( $quiet );
+
+ $ok = 0;
+ foreach $root ( @includelist ) {
+ if ( $fh->open($root.'//'.$file, '<') ) {
+ $ok = 1;
+ last;
+ }
+ }
+
+ if ( ! $ok ) {
+ die "$0: Cannot find file $file\n";
+ }
+
+ while ( defined($line = <$fh>) ) {
+ if ( $kernelonly ) {
+ if ( $line =~ /^\#\s*endif/ ) {
+ $kernelonly--;
+ } elsif ( $line =~ /^\#\sif/ ) {
+ $kernelonly++;
+ }
+ } else {
+ if ( $line =~ /^\#\s*define\s+([A-Z0-9_]+)\s+([0-9]+)\s*\/\*\s*(.*\S)\s*\*\// ) {
+ $error = $1;
+ $errno = $2+0;
+ $msg = $3;
+ print STDERR "$error ($errno) => \"$msg\"\n" unless ( $quiet );
+ $errors{$errno} = $error;
+ $errmsg{$errno} = $msg;
+ $maxerr = $errno if ( $errno > $maxerr );
+ } elsif ( $line =~ /^\#\s*include\s+[\<\"](.*)[\>\"]/ ) {
+ parse_file($1);
+ } elsif ( $line =~ /^\#\s*ifdef\s+__KERNEL__/ ) {
+ $kernelonly++;
+ }
+ }
+ }
+ close($fh);
+ print STDERR "closing $file\n" unless ( $quiet );
+}
+
+$v = $ENV{'KBUILD_VERBOSE'};
+$quiet = defined($v) ? !$v : 0;
+
+foreach $arg ( @ARGV ) {
+ if ( $arg eq '-q' ) {
+ $quiet = 1;
+ } elsif ( $arg =~ /^-(errlist|errnos|maxerr)$/ ) {
+ $type = $arg;
+ } elsif ( $arg =~ '^\-I' ) {
+ push(@includelist, "$'");
+ } else {
+ # Ignore
+ }
+}
+
+parse_file('errno.h');
+
+if ( $type eq '-errlist' ) {
+ print "#include <errno.h>\n";
+ printf "const int sys_nerr = %d;\n", $maxerr+1;
+ printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
+ foreach $e ( sort(keys(%errors)) ) {
+ printf " [%s] = \"%s\",\n", $errors{$e}, $errmsg{$e};
+ }
+ print "};\n";
+} elsif ( $type eq '-errnos' ) {
+ print "#include <errno.h>\n";
+ printf "const int sys_nerr = %d;\n", $maxerr+1;
+ printf "const char * const sys_errlist[%d] = {\n", $maxerr+1;
+ foreach $e ( sort(keys(%errors)) ) {
+ printf " [%s] = \"%s\",\n", $errors{$e}, $errors{$e};
+ }
+ print "};\n";
+} elsif ( $type eq '-maxerr' ) {
+ print $maxerr, "\n";
+}
diff --git a/com32/lib/strerror.c b/com32/lib/strerror.c
index 8dbe74ad..1b3d4452 100644
--- a/com32/lib/strerror.c
+++ b/com32/lib/strerror.c
@@ -6,18 +6,26 @@
char *strerror(int errnum)
{
- static char message[32] = "error "; /* enough for error 2^63-1 */
+ static char message[32] = "error "; /* enough for error 2^63-1 */
+ char numbuf[32];
+ char *p;
+ unsigned int e = (unsigned int)errnum;
- char numbuf[32];
- char *p;
+ extern const int sys_nerr;
+ extern const char *const sys_errlist[];
- p = numbuf + sizeof numbuf;
- *--p = '\0';
+ if (e < (unsigned int)sys_nerr && sys_errlist[e])
+ return (char *)sys_errlist[e];
- do {
- *--p = (errnum % 10) + '0';
- errnum /= 10;
- } while (errnum);
+ p = numbuf + sizeof numbuf;
+ *--p = '\0';
- return (char *)memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
+ do {
+ *--p = (e % 10) + '0';
+ e /= 10;
+ } while (e);
+
+ memcpy(message + 6, p, (numbuf + sizeof numbuf) - p);
+
+ return message;
}