Suppose I have an application running on a UNIX box that is failing with a system error status of '13'. Now, I can easily look up this value in errno.h, to find out that it is a permission-denied problem.
> grep -w 13 /usr/include/errno.h
#define EACCES 13 /* Permission denied */
Is there a simpler command to retrieve this information? I'd like to be able to run something like this:
> lookuperror 13
EACCES (Permission denied)
Instead of grepping system header files. Does such a command/program exist?
Update: As pointed out in the answers below, the strerror()
system call returns this information. Are there any UNIX operating systems that ship with an executable utility that makes this system call, or do I need to write my own program to do it?
I use to do
You can just put the Perl code in a file and have it in the path.
Of course it can be done using C as well
Try strerror(3).
From the manpage:
As a workaround you could in your shell make an alias or function:
eg.
.bashrc
cpp -dM
preprocesses a source or header file and prints every#define
that it finds. It's more robust than grepping through/usr/include/errno.h
, since it will get every file that/usr/include/errno.h
includes.Combining cpp -dM with others' suggestions:
Insert to .bashrc, or place its contents as a standalone shell script.