[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#8090: strerror(1) and strsignal(1)?
From: |
Jim Meyering |
Subject: |
bug#8090: strerror(1) and strsignal(1)? |
Date: |
Mon, 21 Feb 2011 00:20:24 +0100 |
Bruce Korb wrote:
> I had to go grubbing through headers to translate "11" into something
> comprehensible one too many times. If this is acceptable, I'll double
> my time investment and whip up some .texi verbiage.
>
> I believe my paperwork is in order, but I'm not convinced that this
> qualifies as "significant" :-D.
Hi Bruce,
[your subject mentions strsignal -- you know you can get a list
via "env kill --table", assuming you have kill from coreutils? ]
I've had that itch many times.
Here are some handy bash/perl functions I wrote:
$ errno-find 11
EAGAIN
$ errno-int-to-msg 11
Resource temporarily unavailable
$ errno-sym-to-int EAGAIN
11
# Print a table of names/values/messages:
errno-table()
{
perl -MErrno -e 'my %e= map { Errno->$_()=>$_ } keys %!;' \
-e 'print grep !/unknown error/i,' \
-e 'map sprintf("%4d %-12s %s".$/,$_,$e{$_},$!=$_), 0..256'
}
# map errno integer to message, e.g., 2 to No such file or directory
errno-int-to-msg()
{
local fail=0
case $# in 1) case $1 in [0-9]*) ;; *) fail=1;; esac;; *) fail=1;; esac
test $fail = 1 && { echo "Usage: $FUNCNAME ERRNO_INT" 1>&2; return 1; }
perl -le '$!='"$1"'; print $!'
}
# map errno symbolic name to integer, e.g., ENOSYS to 28
errno-sym-to-int()
{
local fail=0
case $# in 1) case $1 in [0-9]*) fail=1;; esac;; *) fail=1;; esac
test $fail = 1 && { echo "Usage: $FUNCNAME ERRNO_SYM" 1>&2; return 1; }
perl -le "use Errno '$1'; print $1"
}
errno-find()
{
case $# in
1) ;;
*) echo "Usage: $FUNCNAME ERRNO_VALUE" 1>&2; return 1;;
esac
perl -MErrno -le 'my %e=map { Errno->$_()=>$_ } keys %!; print $e{'"$1"'}'
}