what is errno and EEXIST mean?
#include<errno.h>
if(errno != EEXIST) {
perror(sha1_dir);
exit(1);
}
I can't understand the condition of if statement. is that saying "if errno doesn't exist"?
what is errno and EEXIST mean?
#include<errno.h>
if(errno != EEXIST) {
perror(sha1_dir);
exit(1);
}
I can't understand the condition of if statement. is that saying "if errno doesn't exist"?
If you dig into errno.h
, you will find EEXIST
is a C macro defined in another file. On my Debian PC, it's in /usr/include/asm-generic/errno-base.h
.
#define EEXIST 17 /* File exists */
Run man errno
to find the meaning of errno
variable:
DESCRIPTION
The <errno.h> header file defines the integer variable errno, which is
set by system calls and some library functions in the event of an error
to indicate what went wrong.
So the meaning of the code block is to check errno
generated by the last function and if it's not "File exists" (file does not exist), print the error message.
Run man perror
for more information. Seriously, you should learn C from some book before asking such a question to stackoverflow.