[libcxx-commits] [PATCH] D91168: [13/N] [libcxx] Implement the space function for windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 2 08:22:52 PST 2021
mstorsjo updated this revision to Diff 320801.
mstorsjo set the repository for this revision to rG LLVM Github Monorepo.
mstorsjo added a comment.
Retriggering CI.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91168/new/
https://reviews.llvm.org/D91168
Files:
libcxx/src/filesystem/operations.cpp
libcxx/src/filesystem/posix_compat.h
Index: libcxx/src/filesystem/posix_compat.h
===================================================================
--- libcxx/src/filesystem/posix_compat.h
+++ libcxx/src/filesystem/posix_compat.h
@@ -277,6 +277,41 @@
}
int close(int fd) { return _close(fd); }
int chdir(const wchar_t *path) { return _wchdir(path); }
+
+struct StatVFS {
+ uint64_t f_frsize;
+ uint64_t f_blocks;
+ uint64_t f_bfree;
+ uint64_t f_bavail;
+};
+
+int statvfs(const wchar_t *p, StatVFS *buf) {
+ path dir = p;
+ while (true) {
+ error_code local_ec;
+ const file_status st = status(dir, local_ec);
+ if (!exists(st) || is_directory(st))
+ break;
+ path parent = dir.parent_path();
+ if (parent == dir) {
+ errno = ENOENT;
+ return -1;
+ }
+ dir = parent;
+ }
+ ULARGE_INTEGER free_bytes_available_to_caller, total_number_of_bytes,
+ total_number_of_free_bytes;
+ if (!GetDiskFreeSpaceExW(dir.c_str(), &free_bytes_available_to_caller,
+ &total_number_of_bytes,
+ &total_number_of_free_bytes))
+ return set_errno();
+ buf->f_frsize = 1;
+ buf->f_blocks = total_number_of_bytes.QuadPart;
+ buf->f_bfree = total_number_of_free_bytes.QuadPart;
+ buf->f_bavail = free_bytes_available_to_caller.QuadPart;
+ return 0;
+}
+
#else
int symlink_file(const char *oldname, const char *newname) {
return ::symlink(oldname, newname);
@@ -295,10 +330,13 @@
using ::remove;
using ::rename;
using ::stat;
+using ::statvfs;
using ::truncate;
#define O_BINARY 0
+using StatVFS = struct statvfs;
+
#endif
} // namespace
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -1301,8 +1301,8 @@
space_info __space(const path& p, error_code* ec) {
ErrorHandler<void> err("space", ec, &p);
space_info si;
- struct statvfs m_svfs = {};
- if (::statvfs(p.c_str(), &m_svfs) == -1) {
+ detail::StatVFS m_svfs = {};
+ if (detail::statvfs(p.c_str(), &m_svfs) == -1) {
err.report(capture_errno());
si.capacity = si.free = si.available = static_cast<uintmax_t>(-1);
return si;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91168.320801.patch
Type: text/x-patch
Size: 2220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210202/073b5491/attachment-0001.bin>
More information about the libcxx-commits
mailing list