shell: errno memo
Your open
call just set errno
to 26
, you're in GDB and don't want to
write another /tmp/test.new2.c to discover what just happened. Another day ruined.
The year is $current_year
and I don't care to learn errno values.
Enough grepping around. Let's build a better tomorrow.
# $1: (nil) or errno value
# output: full errno list or errno value name
errno () {(
err=${1}
[ "$err" ] && filter="| grep \"${err}\""
filter="$filter |column -t"
cmdline="cc -E -dM /usr/include/errno.h \
|grep 'define E' \
|sort -n -k 3 \
|cut -d' ' -f2- \
$filter"
eval $cmdline
)}
$ errno 26
ETXTBSY 26
ENOKEY 126
$ errno ENOBUFS
ENOBUFS 105
Your C compiler of choice will preprocess only an include from the command line, that happens to be the definition for errno codes on the system. After some text manipulation and formatting, a filter is applied, optionally a match on a name or a value.
So many seconds saved, now let's do something less productive.