Page MenuHomePhabricator

[9/N] [libcxx] Implement the stat function family on top of native windows APIs
Needs ReviewPublic

Authored by mstorsjo on Tue, Nov 10, 1:43 AM.

Details

Reviewers
amccarth
EricWF
rnk
Group Reviewers
Restricted Project
Summary

While the windows CRTs (the modern UCRT, and the legacy msvcrt.dll that mingw still often defaults to) do provide stat functions, they're a bit lacking - they only provide second precision on the modification time, lack support for symlinks and a few other details.

Instead reimplement them using a couple windows native functions, getting exactly the info we need. (Technically, the implementation within the CRT calls these functions anyway.)

If we only need a few fields, we could also do with fewer calls, as a later optimization.

Diff Detail

Event Timeline

mstorsjo created this revision.Tue, Nov 10, 1:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptTue, Nov 10, 1:43 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
mstorsjo requested review of this revision.Tue, Nov 10, 1:43 AM
mstorsjo retitled this revision from [libcxx] Implement the stat function family on top of native windows APIs to [9/N] [libcxx] Implement the stat function family on top of native windows APIs.Tue, Nov 10, 1:43 AM
rnk resigned from this revision.Tue, Nov 10, 12:27 PM
mstorsjo updated this revision to Diff 305078.Fri, Nov 13, 3:40 AM

Made the set_errno() helper take the error code as a parameter, to avoid double calls to GetLastError() if the caller already has fetched and inspected the error code.

LGTM as long as the run-time calculation of the default value for set_errno is legit.

libcxx/src/filesystem/operations.cpp
409

Whoa! I thought default argument values had to be compile-time constants. I've never seen this done before. Is this a newer C++ feature?

mstorsjo added inline comments.Wed, Nov 18, 1:15 PM
libcxx/src/filesystem/operations.cpp
409

No idea actually, I just tried it and it worked. If it wouldn't, it'd be trivial to make a parameterless overload of the function that just calls set_errno(GetLastError()) anyway.