in reply to Re: read from a file and write into the same file
in thread read from a file and write into the same file

The file pointer is not guaranteed to be anything in particular between the open and the first write, IIRC.
  • Comment on Re^2: read from a file and write into the same file

Replies are listed 'Best First'.
Re^3: read from a file and write into the same file
by almut (Canon) on Mar 03, 2008 at 07:43 UTC

    strace-ing the OP's code (where nothing is being written) shows

    ... open("test.txt", O_RDWR|O_APPEND|O_CREAT|O_LARGEFILE, 0666) = 5 _llseek(5, 0, [57], SEEK_END) = 0 ...

    which I would interpret to mean that the file pointer is positioned.

    (_llseek is a Linux-specific syscall)

      Right, as far as I know you can count on it being at the end (or at least, the end as of the time of the open) even before the first write on linux. But it isn't guaranteed in general by POSIX.