mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-09 01:38:03 +00:00
Instead friending status, provide windows and posix constructors to file_status.
This opens the way of having static helpers in the .inc files that can construct a file_status. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186376 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
334f8b9b37
commit
77e31bca03
@ -164,14 +164,29 @@ class file_status
|
||||
uint32_t FileIndexLow;
|
||||
#endif
|
||||
friend bool equivalent(file_status A, file_status B);
|
||||
friend error_code status(const Twine &path, file_status &result);
|
||||
friend error_code getUniqueID(const Twine Path, uint64_t &Result);
|
||||
file_type Type;
|
||||
perms Perms;
|
||||
public:
|
||||
explicit file_status(file_type v=file_type::status_error,
|
||||
perms prms=perms_not_known)
|
||||
: Type(v), Perms(prms) {}
|
||||
file_status() : Type(file_type::status_error) {}
|
||||
file_status(file_type Type) : Type(Type) {}
|
||||
|
||||
#if defined(LLVM_ON_UNIX)
|
||||
file_status(file_type Type, perms Perms, dev_t Dev, ino_t Ino, time_t MTime,
|
||||
uid_t UID, gid_t GID, off_t Size)
|
||||
: fs_st_dev(Dev), fs_st_ino(Ino), fs_st_mtime(MTime), fs_st_uid(UID),
|
||||
fs_st_gid(GID), fs_st_size(Size), Type(Type), Perms(Perms) {}
|
||||
#elif defined(LLVM_ON_WIN32)
|
||||
file_status(file_type Type, uint32_t LastWriteTimeHigh,
|
||||
uint32_t LastWriteTimeLow, uint32_t VolumeSerialNumber,
|
||||
uint32_t FileSizeHigh, uint32_t FileSizeLow,
|
||||
uint32_t FileIndexHigh, uint32_t FileIndexLow)
|
||||
: LastWriteTimeHigh(LastWriteTimeHigh),
|
||||
LastWriteTimeLow(LastWriteTimeLow),
|
||||
VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
|
||||
FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
|
||||
FileIndexLow(FileIndexLow), Type(Type), Perms(perms_not_known) {}
|
||||
#endif
|
||||
|
||||
// getters
|
||||
file_type type() const { return Type; }
|
||||
@ -434,21 +449,6 @@ inline bool equivalent(const Twine &A, const Twine &B) {
|
||||
return !equivalent(A, B, result) && result;
|
||||
}
|
||||
|
||||
/// @brief Get file size.
|
||||
///
|
||||
/// @param Path Input path.
|
||||
/// @param Result Set to the size of the file in \a Path.
|
||||
/// @returns errc::success if result has been successfully set, otherwise a
|
||||
/// platform specific error_code.
|
||||
inline error_code file_size(const Twine &Path, uint64_t &Result) {
|
||||
file_status Status;
|
||||
error_code EC = status(Path, Status);
|
||||
if (EC)
|
||||
return EC;
|
||||
Result = Status.getSize();
|
||||
return error_code::success();
|
||||
}
|
||||
|
||||
/// @brief Does status represent a directory?
|
||||
///
|
||||
/// @param status A file_status previously returned from status.
|
||||
@ -529,6 +529,21 @@ error_code is_symlink(const Twine &path, bool &result);
|
||||
/// platform specific error_code.
|
||||
error_code status(const Twine &path, file_status &result);
|
||||
|
||||
/// @brief Get file size.
|
||||
///
|
||||
/// @param Path Input path.
|
||||
/// @param Result Set to the size of the file in \a Path.
|
||||
/// @returns errc::success if result has been successfully set, otherwise a
|
||||
/// platform specific error_code.
|
||||
inline error_code file_size(const Twine &Path, uint64_t &Result) {
|
||||
file_status Status;
|
||||
error_code EC = status(Path, Status);
|
||||
if (EC)
|
||||
return EC;
|
||||
Result = Status.getSize();
|
||||
return error_code::success();
|
||||
}
|
||||
|
||||
error_code setLastModificationAndAccessTime(int FD, TimeValue Time);
|
||||
|
||||
/// @brief Is status available?
|
||||
|
@ -556,28 +556,24 @@ error_code status(const Twine &path, file_status &result) {
|
||||
}
|
||||
|
||||
perms prms = static_cast<perms>(status.st_mode);
|
||||
|
||||
if (S_ISDIR(status.st_mode))
|
||||
result = file_status(file_type::directory_file, prms);
|
||||
else if (S_ISREG(status.st_mode))
|
||||
result = file_status(file_type::regular_file, prms);
|
||||
else if (S_ISBLK(status.st_mode))
|
||||
result = file_status(file_type::block_file, prms);
|
||||
else if (S_ISCHR(status.st_mode))
|
||||
result = file_status(file_type::character_file, prms);
|
||||
else if (S_ISFIFO(status.st_mode))
|
||||
result = file_status(file_type::fifo_file, prms);
|
||||
else if (S_ISSOCK(status.st_mode))
|
||||
result = file_status(file_type::socket_file, prms);
|
||||
else
|
||||
result = file_status(file_type::type_unknown, prms);
|
||||
file_type Type = file_type::type_unknown;
|
||||
|
||||
result.fs_st_dev = status.st_dev;
|
||||
result.fs_st_ino = status.st_ino;
|
||||
result.fs_st_mtime = status.st_mtime;
|
||||
result.fs_st_uid = status.st_uid;
|
||||
result.fs_st_gid = status.st_gid;
|
||||
result.fs_st_size = status.st_size;
|
||||
if (S_ISDIR(status.st_mode))
|
||||
Type = file_type::directory_file;
|
||||
else if (S_ISREG(status.st_mode))
|
||||
Type = file_type::regular_file;
|
||||
else if (S_ISBLK(status.st_mode))
|
||||
Type = file_type::block_file;
|
||||
else if (S_ISCHR(status.st_mode))
|
||||
Type = file_type::character_file;
|
||||
else if (S_ISFIFO(status.st_mode))
|
||||
Type = file_type::fifo_file;
|
||||
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);
|
||||
|
||||
return error_code::success();
|
||||
}
|
||||
|
@ -632,7 +632,6 @@ error_code status(const Twine &path, file_status &result) {
|
||||
if (attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
result = file_status(file_type::directory_file);
|
||||
else {
|
||||
result = file_status(file_type::regular_file);
|
||||
ScopedFileHandle h(
|
||||
::CreateFileW(path_utf16.begin(),
|
||||
0, // Attributes only.
|
||||
@ -646,15 +645,13 @@ error_code status(const Twine &path, file_status &result) {
|
||||
BY_HANDLE_FILE_INFORMATION Info;
|
||||
if (!::GetFileInformationByHandle(h, &Info))
|
||||
goto handle_status_error;
|
||||
result.FileIndexHigh = Info.nFileIndexHigh;
|
||||
result.FileIndexLow = Info.nFileIndexLow;
|
||||
result.FileSizeHigh = Info.nFileSizeHigh;
|
||||
result.FileSizeLow = Info.nFileSizeLow;
|
||||
result.LastWriteTimeHigh = Info.ftLastWriteTime.dwHighDateTime;
|
||||
result.LastWriteTimeLow = Info.ftLastWriteTime.dwLowDateTime;
|
||||
result.VolumeSerialNumber = Info.dwVolumeSerialNumber;
|
||||
}
|
||||
|
||||
result = file_status(
|
||||
file_type::regular_file, Info.ftLastWriteTime.dwHighDateTime,
|
||||
Info.ftLastWriteTime.dwLowDateTime, Info.dwVolumeSerialNumber,
|
||||
Info.nFileSizeHigh, Info.nFileSizeLow, Info.nFileIndexHigh,
|
||||
Info.nFileIndexLow);
|
||||
}
|
||||
return error_code::success();
|
||||
|
||||
handle_status_error:
|
||||
|
Loading…
x
Reference in New Issue
Block a user