What error is errno=2?

Asked 2 years ago, Updated 2 years ago, 34 views

I called execl() and found errno=2.

What does errno=2 mean? What if I just give you the error number?

c linux errno

2022-09-21 17:53

1 Answers

Each errno has its own meaning. But it's just uncomfortable for people to read

trror() or error can replace the error number with a human-readable form.

#include <errno.h>

int main(void) {
    FILE* fp;
    if((fp = fopen("hello", "r") == 0){ // open missing file
        printf("strerror(errno) : %s\n", strerror(errno));
        perror("perror : ");
    }
}

Output:

strerror(errno) : No such file or directory
perror : : No such file or directory


2022-09-21 17:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.