Skip to content

Commit

Permalink
std: Handle DT_DIR file types in dirent pointers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed May 20, 2015
1 parent c322dbb commit e7aad28
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rt/rust_builtin.c
Expand Up @@ -50,14 +50,15 @@ rust_list_dir_val(struct dirent* entry_ptr) {

int
rust_dir_get_mode(struct dirent* entry_ptr) {
#if defined(_DIRENT_HAVE_D_TYPE)
#if defined(_DIRENT_HAVE_D_TYPE) || defined(__APPLE__)
switch (entry_ptr->d_type) {
case DT_BLK: return S_IFBLK;
case DT_CHR: return S_IFCHR;
case DT_FIFO: return S_IFIFO;
case DT_LNK: return S_IFLNK;
case DT_REG: return S_IFREG;
case DT_SOCK: return S_IFSOCK;
case DT_DIR: return S_IFDIR;
}
#endif
return -1;
Expand Down

0 comments on commit e7aad28

Please sign in to comment.