Do we need to reset
errnoto zero before calling a function? See below code. Now the scenario isa_dest_pathis an existing directory. But when I execute the code, it always tries tomkdirbut returns error says that the directory can't be created because it exists. In GDB, I checkerrnobefore callingopendir()anderrnois 2. And it seemserrnois not set to zero during callingopendir(). So do I need to reseterrnoto zero before callingopendir()?errnomay be changed insystem()calls, then in myelse ifbranch I check the result fromsystem()but notopendir(). So afteropendir(), do I need to assignerrnoto a variable then check this variable in theif..elseif..elsebranch?
DIR *dp = opendir(a_dest_path.c_str());
if (errno == ENOENT) {
string mkdir_comman = "mkdir " + a_dest_path;
system(mkdir_command.c_str());
} else if (errno == ENOTDIR) {
printf("Destination %s exists but is not directory\n", a_dest_path.c_str());
return k_error_not_directory;
} else if (errno == 0) {
closedir(dp);
}