Re: Behaviour of lseek and fseek with append mode.

Kevin West (kwest1@cs.stevens-tech.edu)
Fri, 22 Oct 1999 11:10:09 -0400


If I remember correctly, this is working exactly how it should. In append
mode, the pointer is automatically positioned at the end of the file
before EVERY write. You can lseek back to other points in the file for
reading, but writing will return it to the end.

To get the behavior you want, why not just open without append, and seek
to the end when you need to append something.

-Kevin West

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:
>
> When a file is opened in append mode. The file is opened in write mode with the
> FILE_POINTER pointing to the END of the FILE, so that any new data added is
> added to the end of the file. But if one uses LSEEK , then from then on it
> should start writing from the position pointed to by FILE_POINTER.
>
> i.e simply put it always writes to the Position pointed to by FILE_POINTER with
> the special property that when the file is opened initialy the FILE_POINTER
> gets set to the end_of_file.
>
>
> ******** OR ELSE MAY BE ATLEAST THIS CAN BE DONE*************
>
> If APPEND is such that it always sets the FILE_POINTER to End_of_File when one
> is writing to the file (As documented in Opens man page), then shouldn't the
> LSEEK call give a error if one tries to lseek on a File OPENed in Append mode
> with WRITE ONLY access because the only time lseeking on append mode file makes
> sense is when one opened it with READ mode access also.
>
> I can achieve what I want with the existing Append behaviour, by rather not
> using append mode but using write mode and initially setting the FILE_POINTER
> to End_of_File so that I achieve what I want. But I still think that LSEEK
> shouldn't mislead me by allowing me to position the FILE_POINTER where ever I
> want when in APPEND | WRITE_ONLY mode followed by Write completely IGNORING
> the FILE_POINTER.
>
> --
> Keep :-)
> HanishKVC
>
>
> -
> 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/
>

-
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/