diff --git a/src/fileio.c b/src/fileio.c index 87a17eab42..6b223e7078 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2924,16 +2924,18 @@ DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0, bool file_directory_p (Lisp_Object file) { + Lisp_Object encoded = ENCODE_FILE (file); + #ifdef DOS_NT /* This is cheaper than 'stat'. */ - bool retval = faccessat (AT_FDCWD, SSDATA (file), D_OK, AT_EACCESS) == 0; + bool retval = faccessat (AT_FDCWD, SSDATA (encoded), D_OK, AT_EACCESS) == 0; if (!retval && errno == EACCES) errno = ENOTDIR; /* like the non-DOS_NT branch below does */ return retval; #else # ifdef O_PATH /* Use O_PATH if available, as it avoids races and EOVERFLOW issues. */ - int fd = emacs_openat (AT_FDCWD, SSDATA (file), + int fd = emacs_openat (AT_FDCWD, SSDATA (encoded), O_PATH | O_CLOEXEC | O_DIRECTORY, 0); if (0 <= fd) { @@ -2950,12 +2952,12 @@ file_directory_p (Lisp_Object file) is inaccessible, fall back on fstatat; if the latter fails with EOVERFLOW then FILE must have been a directory unless a race condition occurred (a problem hard to work around portably). */ - if (file_accessible_directory_p (file)) + if (file_accessible_directory_p (encoded)) return true; if (errno != EACCES) return false; struct stat st; - if (emacs_fstatat (AT_FDCWD, SSDATA (file), &st, 0) != 0) + if (emacs_fstatat (AT_FDCWD, SSDATA (encoded), &st, 0) != 0) return errno == EOVERFLOW; if (S_ISDIR (st.st_mode)) return true;