[libcxx-commits] [PATCH] D91169: [14/N] [libcxx] Implement the current_path function for windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 10 08:35:37 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/D91169

Files:
  libcxx/src/filesystem/operations.cpp


Index: libcxx/src/filesystem/operations.cpp
===================================================================
--- libcxx/src/filesystem/operations.cpp
+++ libcxx/src/filesystem/operations.cpp
@@ -1135,6 +1135,13 @@
 path __current_path(error_code* ec) {
   ErrorHandler<path> err("current_path", ec);
 
+#if defined(_LIBCPP_WIN32API)
+  std::unique_ptr<wchar_t, decltype(&::free)> buff(::_wgetcwd(nullptr, 0),
+                                                   &::free);
+  if (buff.get() == nullptr)
+    return err.report(capture_errno(), "call to _wgetcwd failed");
+  return {buff.get()};
+#else
   auto size = ::pathconf(".", _PC_PATH_MAX);
   _LIBCPP_ASSERT(size >= 0, "pathconf returned a 0 as max size");
 
@@ -1144,6 +1151,7 @@
     return err.report(capture_errno(), "call to getcwd failed");
 
   return {buff.get()};
+#endif
 }
 
 void __current_path(const path& p, error_code* ec) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91169.304205.patch
Type: text/x-patch
Size: 899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201110/3584c381/attachment.bin>


More information about the libcxx-commits mailing list