-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[singlejar] Use Win32 API directly in OutputJar::AppendFile #6021
Conversation
Also remove unused pread implementation
@laszlocsomor With this PR, singlejar can run on Windows. |
src/tools/singlejar/output_jar.cc
Outdated
while (static_cast<size_t>(total_written) < count) { | ||
ssize_t len = std::min(kBufferSize, count - total_written); | ||
DWORD n_read; | ||
if (!::ReadFile(hFile, buffer.get(), len, &n_read, NULL)) |
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.
style: Please always use { and }, even for single statements. Omitting them is error-prone -- imagine the single statement in the if's body were a multi-statement macro.
Also in next two if-bodies.
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.
Done.
@@ -911,6 +918,20 @@ ssize_t OutputJar::AppendFile(int in_fd, off64_t offset, size_t count) { | |||
} | |||
ssize_t total_written = 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.
Why is total_written
signed? Can you make it unsigned (size_t
)?
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.
We will have to ask the original author. This function return total_written
at the end and even the return type of this function is ssize_t
.
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.
Thanks.
(I guess the reason is error reporting when count = 0
. IMO, ReadFile()
's approach would be better -- i.e. return a boolean, report written amount to an argument.)
@@ -911,6 +918,20 @@ ssize_t OutputJar::AppendFile(int in_fd, off64_t offset, size_t count) { | |||
} | |||
ssize_t total_written = 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.
Thanks.
(I guess the reason is error reporting when count = 0
. IMO, ReadFile()
's approach would be better -- i.e. return a boolean, report written amount to an argument.)
pread
is only used byOutputJar::AppendFile
. ImplementingOutputJar::AppendFile
directly with Win32 API means better performance and no worry about whetherpread
polyfill follows POSIX spec correctly.Also remove unused
pread
polyfill.See #2241