This is an archive of the discontinued LLVM Phabricator instance.

[14/N] [libcxx] Implement the current_path function for windows
ClosedPublic

Authored by mstorsjo on Nov 10 2020, 8:35 AM.

Details

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 10 2020, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2020, 8:35 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
amccarth added inline comments.Dec 2 2020, 4:53 PM
libcxx/src/filesystem/operations.cpp
1139

Is _wgetcwd the right choice here? Shouldn't this instead go straight to Windows with GetCurrentDirectoryW so it doesn't take a dependence on MSVC's CRT?

mstorsjo added inline comments.Dec 3 2020, 5:09 AM
libcxx/src/filesystem/operations.cpp
1139

I guess we could do that as well; we still have a few other calls that go through the CRT (in the FileDescriptor helper class further up in the file, used for file copying), and in this case, there's no other practical limitation in _wgetcwd that we'd get around, other than cleanliness. (Calling GetCurrentDirectoryW takes two calls and manual allocation inbetween, unless we want to hardcode a PATH_MAX allocation, but I'd rather move away from such specific limits.)

But yeah I can change it if you still prefer that.

amccarth accepted this revision.Dec 11 2020, 2:23 PM

Your call on using the CRT. I was under the mistaken impression that libcxx would implement both the standard C++ library as well as the CRT.

mstorsjo updated this revision to Diff 317578.Jan 19 2021, 8:21 AM

Moved to a getcwd helper in posix_compat.h, change existing code to use path::value_type instead of hardcoded char.

ldionne set the repository for this revision to rG LLVM Github Monorepo.Jan 28 2021, 3:18 PM
mstorsjo removed rG LLVM Github Monorepo as the repository for this revision.Jan 29 2021, 3:47 AM
mstorsjo updated this revision to Diff 320102.Jan 29 2021, 4:32 AM
mstorsjo set the repository for this revision to rG LLVM Github Monorepo.

Reworked this patch to allow two use patterns of the POSIX getcwd() function - in strict POSIX getcwd(), it has to be given a preallocated buffer of a fixed size - but at least glibc and Darwin libc's (and windows) allow passing nullptr, to let the function allocate a suitably large buffer. For now I only use that codepath for windows (to reduce the risk of anything breaking due to this patch), but we could enable it on POSIX systems where we know it's supported as a later feature.

ldionne accepted this revision.Feb 2 2021, 12:29 PM
This revision is now accepted and ready to land.Feb 2 2021, 12:29 PM
This revision was landed with ongoing or failed builds.Feb 2 2021, 1:04 PM
This revision was automatically updated to reflect the committed changes.