bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about adding a tiny tool into GNU coreutils


From: Jim Meyering
Subject: Re: Question about adding a tiny tool into GNU coreutils
Date: Wed, 06 Jan 2010 21:02:32 +0100

Daniel Borkmann wrote:
> I was wondering if it's possible to add a tiny little program (next to
> true and false ;) ) into the gnu coreutils package? The program I've
> written is called "errno" and does nothing less than writing an error
> string according to the user-specified error number.
>
> Very often, programs or kernel modules only show/log a return value, but
> not the actual error message, so you manually have to look it up. This
> _tiny_ tool helps doing this automatically ;)
>
> I think it would rather fit into the coreutils than having it's own
> distribution package. What do you think? (Source attached)
...
Thanks for the suggestion, but it seems better to
do that with some shell and perl:

# 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"
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]