-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle the unknown d_type field in posix readdir
- Loading branch information
Showing
5 changed files
with
192 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <sys/stat.h> | ||
|
||
int lstat_is_directory(const char *path) { | ||
struct stat statbuf; | ||
|
||
// XXX Using fstatat with a dirfd and relative path would be faster. | ||
// Call lstat to get the file status | ||
// We use lstat instead of stat for correctness with symbolic link | ||
if (lstat(path, &statbuf) == 0) { | ||
// Check if the file is a directory using S_ISDIR macro | ||
if (S_ISDIR(statbuf.st_mode)) { | ||
return 1; // It is a directory | ||
} else { | ||
return 0; // Not a directory | ||
} | ||
} | ||
return -1; // An error occurred (stat failed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.