diff options
author | Gene Cumm <gene.cumm@gmail.com> | 2012-06-16 13:33:19 -0400 |
---|---|---|
committer | Gene Cumm <gene.cumm@gmail.com> | 2012-11-06 21:23:37 -0500 |
commit | 8a31cbeed4629084475bbf68fd20c6db934da619 (patch) | |
tree | 31c9891acc4a1dc99142d731f187f2a6dcf09ddd | |
parent | c44fe85310a4efb1334b4e807b999870ab90e3f6 (diff) | |
download | syslinux-8a31cbeed4629084475bbf68fd20c6db934da619.tar.gz syslinux-8a31cbeed4629084475bbf68fd20c6db934da619.tar.xz syslinux-8a31cbeed4629084475bbf68fd20c6db934da619.zip |
strerror: Use klibc version
Remove old in favor of current klibc version
Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
-rw-r--r-- | com32/lib/makeerrlist.pl | 98 | ||||
-rw-r--r-- | 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 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..fed0e492 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; } |