Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change sopen_s to wsopen_s (fmtlib#3234) #3293

Merged
merged 3 commits into from Feb 16, 2023
Merged

Conversation

Fros1er
Copy link
Contributor

@Fros1er Fros1er commented Feb 6, 2023

Fix #3234.

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Overall looks good, just a few minor comments inline.

Comment on lines 42 to 43
errno_t wsopen_s(int* pfh, const wchar_t* filename, int oflag, int shflag,
int pmode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed because there is no corresponding test in posix-mock-test. You'll need to remove FMT_POSIX_CALL around the call to wsopen_s as well.

src/os.cc Outdated
using mode_t = int;
constexpr mode_t mode =
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
FMT_POSIX_CALL(wsopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, mode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like wsopen_s returns an error code so I suggest using it instead of global errno.

src/os.cc Outdated
int fd_ = -1;
using mode_t = int;
constexpr mode_t mode =
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move to a constant, e.g. default_open_mode and reuse here and above to make sure modes are consistent.

@Fros1er
Copy link
Contributor Author

Fros1er commented Feb 14, 2023

It seems windows doesn't return EINTR on _wsopen_s, so I removed open_retry in posix mock test.
And sorry for those force pushes.

src/os.cc Outdated
Comment on lines 224 to 227
fd_ = -1;
FMT_POSIX_CALL(sopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, mode));
auto converted = detail::utf8_to_utf16(string_view(path.c_str()));
auto err =
_wsopen_s(&fd_, converted.c_str(), oflag, _SH_DENYNO, default_open_mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could avoid a bit of duplication by calling open_windows_file here and moving its result into *this.

@vitaut vitaut merged commit b5c2f74 into fmtlib:master Feb 16, 2023
@vitaut
Copy link
Contributor

vitaut commented Feb 16, 2023

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_wfopen support
2 participants