Re: Behaviour of lseek and fseek with append mode.

Richard B. Johnson (root@chaos.analogic.com)
Fri, 22 Oct 1999 10:51:36 -0400 (EDT)


On Fri, 22 Oct 1999, C Hanish Menon wrote:

>
> Hi everyone
>
> I am writing a application which requires to add new things to the end of a
> existing file. So I open the file in append mode. But once the file is opened
> in append mode when ever I write any data it always writes to the end of
> the file and not where the FILE_POINTER is positioned using LSEEK.
>
> Is this right shouldn't it be working like this i.e:
>
[SNIPPED]

man 2 open

O_APPEND
The file is opened in append mode. Initially, and
before each write, the file-pointer is positioned
at the end of the file, as if with lseek.

Things don't often mean what they seem to say. You can lseek for
various reads in a file opened for append. However, the explicit
definitition requires that any writes occur at the end of the file.

You need to open the file as O_RDWR if you want to do random read/writes.
As a feature, this allows you to make sparse files as well.

Cheers,
Dick Johnson

Penguin : Linux version 2.3.13 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/