ncls: opendir() instead of openat+fdopendir for Windows #2062

This commit is contained in:
nick black 2021-08-24 02:40:55 -04:00
parent 3c8a313fac
commit 5840885fd1

View File

@ -95,7 +95,6 @@ int handle_inode(const std::string& dir, const char* p, const struct stat* st, c
// passing false for toplevel (but preserving |ctx|). // passing false for toplevel (but preserving |ctx|).
int handle_dir(int dirfd, const std::string& pdir, const char* p, int handle_dir(int dirfd, const std::string& pdir, const char* p,
const struct stat* st, const lsContext& ctx, bool toplevel){ const struct stat* st, const lsContext& ctx, bool toplevel){
#ifndef __MINGW64__
if(ctx.directories){ if(ctx.directories){
return handle_inode(pdir, p, st, ctx); return handle_inode(pdir, p, st, ctx);
} }
@ -105,12 +104,18 @@ int handle_dir(int dirfd, const std::string& pdir, const char* p,
if((strcmp(p, ".") == 0 || strcmp(p, "..") == 0) && !toplevel){ if((strcmp(p, ".") == 0 || strcmp(p, "..") == 0) && !toplevel){
return 0; return 0;
} }
int newdir = openat(dirfd, p, O_DIRECTORY | O_CLOEXEC); int newdir = -1;
#ifndef __MINGW64__
newdir = openat(dirfd, p, O_DIRECTORY | O_CLOEXEC);
if(newdir < 0){ if(newdir < 0){
std::cerr << "Error opening " << p << ": " << strerror(errno) << std::endl; std::cerr << "Error opening " << p << ": " << strerror(errno) << std::endl;
return -1; return -1;
} }
DIR* dir = fdopendir(newdir); DIR* dir = fdopendir(newdir);
#else
(void)dirfd;
DIR* dir = opendir(path_join(pdir, p).c_str());
#endif
if(dir == nullptr){ if(dir == nullptr){
std::cerr << "Error opening " << p << ": " << strerror(errno) << std::endl; std::cerr << "Error opening " << p << ": " << strerror(errno) << std::endl;
close(newdir); close(newdir);
@ -128,11 +133,10 @@ int handle_dir(int dirfd, const std::string& pdir, const char* p,
return -1; return -1;
} }
closedir(dir); closedir(dir);
if(newdir >= 0){
close(newdir); close(newdir);
}
return 0; return 0;
#else
return -1;
#endif
} }
int handle_deref(const char* p, const struct stat* st, const lsContext& ctx){ int handle_deref(const char* p, const struct stat* st, const lsContext& ctx){