Skip to content

Commit e7aad28

Browse files
committed
std: Handle DT_DIR file types in dirent pointers
This "fast path" in `DirEntry::file_type` on Unix wasn't turning out to be so much of a fast path as the `DT_DIR` case wasn't handled, so directories fell back to using `lstat` instead. This commit adds the missing case to return quickly if a path is a directory and `DirEntry::file_type` is used.
1 parent c322dbb commit e7aad28

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/rt/rust_builtin.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ rust_list_dir_val(struct dirent* entry_ptr) {
5050

5151
int
5252
rust_dir_get_mode(struct dirent* entry_ptr) {
53-
#if defined(_DIRENT_HAVE_D_TYPE)
53+
#if defined(_DIRENT_HAVE_D_TYPE) || defined(__APPLE__)
5454
switch (entry_ptr->d_type) {
5555
case DT_BLK: return S_IFBLK;
5656
case DT_CHR: return S_IFCHR;
5757
case DT_FIFO: return S_IFIFO;
5858
case DT_LNK: return S_IFLNK;
5959
case DT_REG: return S_IFREG;
6060
case DT_SOCK: return S_IFSOCK;
61+
case DT_DIR: return S_IFDIR;
6162
}
6263
#endif
6364
return -1;

0 commit comments

Comments
 (0)