linux的errno

/**
g++ error_test.cpp -g -O0 -o error_test
./error_test 9
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char** argv){
    if(argc <= 1){
        printf("Usage: %s <errno>\nFor example:\n    %s 9\n", argv[0], argv[0]);
        exit(1);
    }

    int no = atoi(argv[1]);
    printf("error=%d(%#x)(%s)\n", no, no, strerror(no));

    return 0;
}

执行结果如下:

[winlin@localhost zmq]$ g++ error_test.cpp -g -O0 -o error_test
[winlin@localhost zmq]$ ./error_test
Usage: ./error_test <errno>
For example:
    ./error_test 9
[winlin@localhost zmq]$ ./error_test 9
error=9(0x9)(Bad file descriptor)


你可能感兴趣的:(linux的errno)