Fri Nov 13 13:04:53 CET 2009

fdopen and read + write

man fdopen:

   Reads and writes may be intermixed on read/write streams in any
   order.  Note that ANSI C requires that a file positioning function
   intervene between output and input, unless an input operation
   encounters end-of-file.  (If this condition is not met, then a read
   is allowed to return the result of writes other than the most
   recent.)  Therefore it is good practice (and indeed sometimes
   necessary under Linux) to put an fseek() or fgetpos() opera- tion
   between write and read operations on such a stream.  This operation
   may be an apparent no-op (as in fseek(..., 0L, SEEK_CUR) called for
   its synchronizing side effect.

It's probably best to use 2 FILE objects.