Skip to content

Commit

Permalink
Merge pull request #422 from CyberShadow/std-file-exists
Browse files Browse the repository at this point in the history
std.file: Use stat instead of access to check file existence on POSIX
  • Loading branch information
andralex committed Feb 18, 2012
2 parents 1b871d9 + f999f6b commit 2f39ce1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion std/file.d
Expand Up @@ -1136,7 +1136,28 @@ unittest
}
else version(Posix)
{
return access(toStringz(name), 0) == 0;
/*
The reason why we use stat (and not access) here is
the quirky behavior of access for SUID programs: if
we used access, a file may not appear to "exist",
despite that the program would be able to open it
just fine. The behavior in question is described as
follows in the access man page:
> The check is done using the calling process's real
> UID and GID, rather than the effective IDs as is
> done when actually attempting an operation (e.g.,
> open(2)) on the file. This allows set-user-ID
> programs to easily determine the invoking user's
> authority.
While various operating systems provide eaccess or
euidaccess functions, these are not part of POSIX -
so it's safer to use stat instead.
*/

struct_stat64 statbuf = void;
return stat64(toStringz(name), &statbuf) == 0;
}
}

Expand Down

0 comments on commit 2f39ce1

Please sign in to comment.