Article View: comp.sys.amiga.tech
Article #4890Re: I/O of complex data structures in C
From: Matthew Dillon
Date: Mon, 13 Aug 1990 23:27
Date: Mon, 13 Aug 1990 23:27
43 lines
1947 bytes
1947 bytes
>Where did you find this? It doesn't exist in K&R. From V7 UNIX
>Programmer's Manual :
>
>fwrite( ptr, sizeof( *ptr ), nitems, stream )
>
>fwrite appends at most nitems of data of the type *ptr beginning at ptr
>to the named output stream. It returns the number of items actually
>written.
>
>So you can see that the two are _not_ the same. In detail, you either
>write an item, or you don't - no half written items are permitted.
I believe I said that the only real difference is in the return value.
Realistically it is not possible to guarentee that only a integral
number of objSize bytes will be written because not even low level I/O
(write()) will guarentee that!
So while you can say conceptually that fwrite() will not write half-blocks
when an error occurs, in real life it actually might.
>I looked at the source for the Manx call, and it uses two for loops to
>call fputc(), not multiply block by items, then one loop.
Manx's fwrite() is a piece of c**p then... extremely slow. But even
using two for loops does not guarentee that half-writes will not occur
on error.
-Matt
>Allan Duncan ACSnet a.duncan@trl.oz
>(03) 541 6708 ARPA a.duncan%trl.oz.au@uunet.uu.net
> UUCP {uunet,hplabs,ukc}!munnari!trl.oz.au!a.duncan
>Telecom Research Labs, PO Box 249, Clayton, Victoria, 3168, Australia.
-Matt
--
Matthew Dillon dillon@Overload.Berkeley.CA.US
891 Regal Rd. uunet.uu.net!overload!dillon
Berkeley, Ca. 94708
USA
Technical Details
Message-ID:
<dillon.5462@overload.Berkeley.CA.US>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!overload!dillonReferences:
<dillon.5326@overload.Berkeley.CA.US> <2057@trlluna.trl.oz>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!overload!dillon From: dillon@overload.Berkeley.CA.US (Matthew Dillon) Newsgroups: comp.sys.amiga.tech Subject: Re: I/O of complex data structures in C Message-ID: <dillon.5462@overload.Berkeley.CA.US> Date: 13 Aug 90 23:27:33 GMT References: <dillon.5326@overload.Berkeley.CA.US> <2057@trlluna.trl.oz> Lines: 43