How can I get error message for errno value (C language)?

c c89
Andrey Bushman picture Andrey Bushman · Sep 30, 2012 · Viewed 13.9k times · Source

How can I get error message for errno value (C language)? For example, I can write such file (errno_messages.h):

#include <errno.h>

char* get_errno_message(void){
    switch (errno) {
    case 0:
        return "";
        break;
    case EPERM:
        return "Operation not permitted";
        break;
    case ENOENT:
        return "No such file or directory";
        break;
    case ESRCH:
        return "No such process";
        break;
        /* e.t.c. */
    default:        
        break;
    }
}

But maybe such function is exists already?

Best Regards

Answer

Joachim Isaksson picture Joachim Isaksson · Sep 30, 2012

I think what you're looking for is strerror().