[syslinux:elflink] strerror: Use klibc version

syslinux-bot for Gene Cumm gene.cumm at gmail.com
Tue Nov 13 11:06:09 PST 2012


Commit-ID:  8a31cbeed4629084475bbf68fd20c6db934da619
Gitweb:     http://www.syslinux.org/commit/8a31cbeed4629084475bbf68fd20c6db934da619
Author:     Gene Cumm <gene.cumm at gmail.com>
AuthorDate: Sat, 16 Jun 2012 13:33:19 -0400
Committer:  Gene Cumm <gene.cumm at gmail.com>
CommitDate: Tue, 6 Nov 2012 21:23:37 -0500

strerror: Use klibc version

Remove old in favor of current klibc version

Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

---
 com32/lib/makeerrlist.pl |   98 ++++++++++++++++++++++++++++++++++++++++++++++
 com32/lib/strerror.c     |   30 +++++++++-----
 2 files changed, 118 insertions(+), 10 deletions(-)

diff --git a/com32/lib/makeerrlist.pl b/com32/lib/makeerrlist.pl
new file mode 100644
index 0000000..9243b9d
--- /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;
+ at 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 8dbe74a..fed0e49 100644
--- a/com32/lib/strerror.c
+++ b/com32/lib/strerror.c
@@ -6,18 +6,28 @@
 
 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;
+#ifdef WITH_ERRLIST
+	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];
+#endif
 
-    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;
 }


More information about the Syslinux-commits mailing list