Re: WriteFile()



Chris said it was possible.

Unless he knows something unbeknownst to me, I don't think so. I can't
think of any normal condition where this is possible.

In sync mode, the WriteFile() operation must complete, otherwise there is a
underlining problem. Like possibly out of disk space, in which case you
can get less than the requested write amount. WriteFile() returns false the
extended error is ERROR_DISK_FULL.

In async mode, it is possible to get less than the requested write. That's
the whole purpose of async.

So you are correct, the lpNumberOfBytesWritten is redundant in SYNC mode,
and this is highlighted by the MSDN documentation where it says it can be
NULL in sync mode (starting with Windows 2000).

Just think about it. In sync mode, what physical barrier could there be
that can produce partial write?

I can only see a disk error, or maybe the handle becoming invalid or some
other conflict while the write is happening, but these should also produce a
FALSE result. You should never get TRUE for errors otherwise the world
will blow up. <g>

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com






"Frank A. Uepping" <trash@xxxxxxxxxxxxxxx> wrote in message
news:d36ppn$84f$05$2@xxxxxxxxxxxxxxxxxxxx
> Hello,
>
> Can we always assume that when WriteFile() (in synchronous operation
> mode) returns successfully it has written the requested number of bytes,
> i.e. nNumberOfBytesToWrite == *lpNumberOfBytesWritten?
>
> Or is it legal for WriteFile() to return successfully without having
> written all requested bytes, i.e. nNumberOfBytesToWrite >
> *lpNumberOfBytesWritten?
>
> (I assume the latter, otherwise I see no sense for having
> lpNumberOfBytesWritten.)
>
> Thanks
> FAU

.



Relevant Pages

  • Re: WriteFile()
    ... WriteFile() returns false the ... In async mode, it is possible to get less than the requested write. ... So you are correct, the lpNumberOfBytesWritten is redundant in SYNC mode, ... written all requested bytes, i.e. nNumberOfBytesToWrite> ...
    (microsoft.public.win32.programmer.kernel)
  • Re: WriteFile()
    ... WriteFile() returns false the ... It would also be thinkable that WriteFilereturns true with less bytes written than requested (because this is what the file system layer was able to process till the error happens), ... NULL in sync mode. ... In SYNC mode we have lpOverlapped set to NULL, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to Discover if Overlapped IO is enabled for a Handle
    ... DWORD ModeS = MAXDWORD, ModeA = MAXDWORD; ... Sync mode: 0x00000020 ... Async mode: 0x00000000 ...
    (microsoft.public.win32.programmer.kernel)
  • Re: WriteFile()
    ... Like possibly out of disk space, ... The next call to the file system layer will then ... NULL in sync mode. ...
    (microsoft.public.win32.programmer.kernel)

Loading