How to know what the 'errno' means?
You can use strerror()
to get a human-readable string for the error number. This is the same string printed by perror()
but it's useful if you're formatting the error message for something other than standard error output.
For example:
#include <errno.h>#include <string.h>/* ... */if(read(fd, buf, 1)==-1) { printf("Oh dear, something went wrong with read()! %s\n", strerror(errno));}
Linux also supports the explicitly-threadsafe variant strerror_r()
.
On Linux there is also a very neat tool that can tell right away what each error code means. On Ubuntu: apt-get install errno
.
Then if for example you want to get the description of error type 2, just type errno 2
in the terminal.
With errno -l
you get a list with all errors and their descriptions. Much easier that other methods mentioned by previous posters.