Barth Barth - 6 months ago 29
C Question

How to know what the 'errno' means?

When calling

, I get an
. What does it mean? How can I know the meaning of this


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