Skip to content

Commit

Permalink
Make std.file.timeLastModified with two arguments safe
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed Aug 29, 2014
1 parent 6cd2e43 commit f7fc11e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions std/file.d
Expand Up @@ -905,25 +905,29 @@ else
}
--------------------
+/
SysTime timeLastModified(in char[] name, SysTime returnIfMissing)
SysTime timeLastModified(in char[] name, SysTime returnIfMissing) @safe
{
version(Windows)
{
if(!exists(name))
return returnIfMissing;

SysTime dummy = void;
SysTime ftm = void;
SysTime dummy;
SysTime ftm;

getTimesWin(name, dummy, dummy, ftm);

return ftm;
}
else version(Posix)
{
static auto trustedStat(in char[] path, ref stat_t buf) @trusted
{
return stat(path.tempCString(), &buf);
}
stat_t statbuf = void;

return stat(name.tempCString(), &statbuf) != 0 ?
return trustedStat(name, statbuf) != 0 ?
returnIfMissing :
SysTime(unixTimeToStdTime(statbuf.st_mtime));
}
Expand Down

0 comments on commit f7fc11e

Please sign in to comment.