Barth Barth - 1 month ago 11
C Question

How to know what the 'errno' means?

When calling

execl(...)
, I get an
errno=2
. What does it mean? How can I know the meaning of this
errno
?

Answer

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().