bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fwrite error reporting


From: Ulrich Drepper
Subject: Re: fwrite error reporting
Date: 03 Apr 2001 19:46:31 -0700
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.2 (Thelxepeia)

Petr Vandrovec <address@hidden> writes:

> while (bytes_to_write > 0) {
>   int tmp = bytes_to_write > 1048576 ? 1048576 : bytes_to_write;
>   int count = fwrite(pointer, 1, tmp, outstream);
>   if (count <= 0) {
>     return FATAL_ERROR;
>   }
>   bytes_to_write -= count;
>   pointer += count;
> }

fwrite() returns 0 if nothing gets written.  I have no idea why you
claim to see something different.  Provide a complete example.

> And another point, stdio library in this case sets ferror()
> indication and refuses to do any more work on this stream
> until clearerr or rewind. libio just does not care - so we just
> get file which misses 32KB in the middle, although there was no
> error reported to application (except one short write which
> I assume is legal).

It's the user's responsibility to check for errors.  If a write is
short something bad happens and another call must be made for the
not-written data.

In general, using fwrite() is bad since it has far too many issues
like this.  It's a horribly designed interface.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]