Skip to content

io: fix dispatch_io_create_with_path() on Windows #494

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

Merged
merged 1 commit into from
Jun 26, 2019
Merged

io: fix dispatch_io_create_with_path() on Windows #494

merged 1 commit into from
Jun 26, 2019

Conversation

adierking
Copy link
Contributor

This function assumes POSIX-style paths. Add Windows-specific checks for
absolute paths and separators.

Additionally, _dispatch_fd_entry_guarded_open() does not handle the
open flags correctly. O_RDONLY is 0, so we need to use a switch
statement to check for it. O_EXCL is not handled at all. O_TRUNC's
behavior needs to change depending on whether O_CREAT is specified.
Finally, we must open files with maximum sharing to match the semantics
of other platforms. (The dispatch_io test already has a handle open when
it calls dispatch_io_create_with_path().)

@adierking
Copy link
Contributor Author

cc @compnerd @ktopley-apple

@adierking
Copy link
Contributor Author

Addressed review comments. cc @compnerd

@compnerd
Copy link
Member

@swift-ci please test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

src/io.c Outdated
// Check parent directory
char *c = strrchr(path_data->path, '/');
char *c = NULL;
for (size_t i = path_data->pathlen; i-- > 0;) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although this code is correct, I found it confusing at first because it appears that the start index should be path_data->pathlen - 1, but this is not the case because i-- decrements before each pass of the loop. I understand the reason for the - size_t is unsigned. Maybe it would be clearer to cast to ssize_t:

for (ssize_t i = (ssize_t)path_data->pathlen - 1; i >= 0; i--)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot that Dispatch declares ssize_t on Windows. (It normally isn't present.) That sounds better, thanks!

This function assumes POSIX-style paths. Add Windows-specific checks for
absolute paths and separators.

Additionally, `_dispatch_fd_entry_guarded_open()` does not handle the
open flags correctly. `O_RDONLY` is 0, so we need to use a switch
statement to check for it. `O_EXCL` is not handled at all. `O_TRUNC`'s
behavior needs to change depending on whether `O_CREAT` is specified.
Finally, we must open files with maximum sharing to match the semantics
of other platforms. (The dispatch_io test already has a handle open when
it calls `dispatch_io_create_with_path()`.)
@ktopley-apple
Copy link
Contributor

@swift-ci please test

@ktopley-apple ktopley-apple merged commit 318f6e5 into swiftlang:master Jun 26, 2019
rokhinip pushed a commit that referenced this pull request Nov 5, 2021
io: fix dispatch_io_create_with_path() on Windows
Signed-off-by: Kim Topley <[email protected]>
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.

3 participants