When calling WriteFile
can the returned lpNumberOfBytesWritten
ever be less than nNumberOfBytesToWrite
in synchronous write mode where an error has not occured (return is TRUE
)? Writing is done to a proper file (not a socket, pipe, or other special handle). lpOverlapped
is not used.
It is not entirely clear from the docs.
The WriteFile function may fail with ERROR_NOT_ENOUGH_QUOTA, which means the calling process's buffer could not be page-locked. For more information, see SetProcessWorkingSetSize. If part of the file is locked by another process and the write operation overlaps the locked portion, WriteFile fails.
For more information, see CreateFile and Synchronous and Asynchronous I/O . If an anonymous pipe is being used and the read handle has been closed, when WriteFile attempts to write using the pipe's corresponding write handle, the function returns FALSE and GetLastError returns ERROR_BROKEN_PIPE .
For x64 platforms it's 31.97 MB. For Itanium it's 63.95 MB. For more information regarding pipes, see the Remarks section. A pointer to the variable that receives the number of bytes written when using a synchronous hFile parameter. WriteFile sets this value to zero before doing any work or error checking.
If the hFile parameter is associated with an I/O completion port, you can also get the number of bytes written by calling the GetQueuedCompletionStatus function. In Windows Server 2012, this function is supported by the following technologies.
The documentation states:
The WriteFile function returns when one of the following conditions occur:
- The number of bytes requested is written.
- A read operation releases buffer space on the read end of the pipe (if the write was blocked). For more information, see the Pipes section.
- An asynchronous handle is being used and the write is occurring asynchronously.
- An error occurs.
Only the first one of these meets your criteria so the answer is that the documentation is clear *lpNumberOfBytesWritten
is always equal to nNumberOfBytesToWrite
when the function returns when called as you specify.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With