-
Notifications
You must be signed in to change notification settings - Fork 471
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
Conversation
Addressed review comments. cc @compnerd |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC: @ktopley-apple
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;) { |
There was a problem hiding this comment.
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--)
There was a problem hiding this comment.
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()`.)
@swift-ci please test |
io: fix dispatch_io_create_with_path() on Windows Signed-off-by: Kim Topley <[email protected]>
This function assumes POSIX-style paths. Add Windows-specific checks for
absolute paths and separators.
Additionally,
_dispatch_fd_entry_guarded_open()
does not handle theopen flags correctly.
O_RDONLY
is 0, so we need to use a switchstatement to check for it.
O_EXCL
is not handled at all.O_TRUNC
'sbehavior 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()
.)