diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:20:13 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-16 03:20:13 +0000 |
commit | 87be8d353b3454383940ce5abc1a176268a33d33 (patch) | |
tree | 840a6a2944fa7116a5a27670fa3f23d1565d6822 /lib/Support/Unix | |
parent | 3a101048affcb00654b85558157150ad270fc46d (diff) | |
download | llvm-87be8d353b3454383940ce5abc1a176268a33d33.tar.gz llvm-87be8d353b3454383940ce5abc1a176268a33d33.tar.bz2 llvm-87be8d353b3454383940ce5abc1a176268a33d33.tar.xz |
Add a version of sys::fs::status that uses fstat.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186378 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix')
-rw-r--r-- | lib/Support/Unix/Path.inc | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 484296cdee..9795b6e34b 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -541,43 +541,55 @@ error_code getUniqueID(const Twine Path, uint64_t &Result) { return error_code::success(); } -error_code status(const Twine &path, file_status &result) { - SmallString<128> path_storage; - StringRef p = path.toNullTerminatedStringRef(path_storage); - - struct stat status; - if (::stat(p.begin(), &status) != 0) { +static error_code fillStatus(int StatRet, const struct stat &Status, + file_status &Result) { + if (StatRet != 0) { error_code ec(errno, system_category()); if (ec == errc::no_such_file_or_directory) - result = file_status(file_type::file_not_found); + Result = file_status(file_type::file_not_found); else - result = file_status(file_type::status_error); + Result = file_status(file_type::status_error); return ec; } - perms prms = static_cast<perms>(status.st_mode); file_type Type = file_type::type_unknown; - if (S_ISDIR(status.st_mode)) + if (S_ISDIR(Status.st_mode)) Type = file_type::directory_file; - else if (S_ISREG(status.st_mode)) + else if (S_ISREG(Status.st_mode)) Type = file_type::regular_file; - else if (S_ISBLK(status.st_mode)) + else if (S_ISBLK(Status.st_mode)) Type = file_type::block_file; - else if (S_ISCHR(status.st_mode)) + else if (S_ISCHR(Status.st_mode)) Type = file_type::character_file; - else if (S_ISFIFO(status.st_mode)) + else if (S_ISFIFO(Status.st_mode)) Type = file_type::fifo_file; - else if (S_ISSOCK(status.st_mode)) + else if (S_ISSOCK(Status.st_mode)) Type = file_type::socket_file; - result = - file_status(Type, prms, status.st_dev, status.st_ino, status.st_mtime, - status.st_uid, status.st_gid, status.st_size); + perms Perms = static_cast<perms>(Status.st_mode); + Result = + file_status(Type, Perms, Status.st_dev, Status.st_ino, Status.st_mtime, + Status.st_uid, Status.st_gid, Status.st_size); return error_code::success(); } +error_code status(const Twine &Path, file_status &Result) { + SmallString<128> PathStorage; + StringRef P = Path.toNullTerminatedStringRef(PathStorage); + + struct stat Status; + int StatRet = ::stat(P.begin(), &Status); + return fillStatus(StatRet, Status, Result); +} + +error_code status(int FD, file_status &Result) { + struct stat Status; + int StatRet = ::fstat(FD, &Status); + return fillStatus(StatRet, Status, Result); +} + error_code setLastModificationAndAccessTime(int FD, TimeValue Time) { #if defined(HAVE_FUTIMENS) timespec Times[2]; |