[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 Nov 10 08:34:24 PST 2020
mstorsjo created this revision.
mstorsjo added a reviewer: libc++.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.
mstorsjo requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91168
Files:
libcxx/src/filesystem/operations.cpp
Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -1415,6 +1415,7 @@
space_info __space(const path& p, error_code* ec) {
ErrorHandler<void> err("space", ec, &p);
space_info si;
+#if !defined(_LIBCPP_WIN32API)
struct statvfs m_svfs = {};
if (::statvfs(p.c_str(), &m_svfs) == -1) {
err.report(capture_errno());
@@ -1430,6 +1431,34 @@
do_mult(si.capacity, m_svfs.f_blocks);
do_mult(si.free, m_svfs.f_bfree);
do_mult(si.available, m_svfs.f_bavail);
+#else
+ ULARGE_INTEGER free_bytes_available_to_caller, total_number_of_bytes,
+ total_number_of_free_bytes;
+ 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) {
+ err.report(make_error_code(errc::no_such_file_or_directory));
+ si.capacity = si.free = si.available = static_cast<uintmax_t>(-1);
+ return si;
+ }
+ dir = parent;
+ }
+ if (!GetDiskFreeSpaceExW(dir.c_str(), &free_bytes_available_to_caller,
+ &total_number_of_bytes,
+ &total_number_of_free_bytes)) {
+ err.report(detail::capture_last_error());
+ si.capacity = si.free = si.available = static_cast<uintmax_t>(-1);
+ return si;
+ }
+ si.capacity = total_number_of_bytes.QuadPart;
+ si.free = total_number_of_free_bytes.QuadPart;
+ si.available = free_bytes_available_to_caller.QuadPart;
+#endif
return si;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91168.304203.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201110/9eb2bfef/attachment.bin>
More information about the libcxx-commits
mailing list