[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#175755: fopen does not positions the stream at the end of the file in mode a+



At 08 Jan 2003 12:56:10 +0100,
Ander wrote:
> [1  <text/plain; ISO-8859-15 (quoted-printable)>]
> El mi�, 08-01-2003 a las 05:10, GOTO Masanori escribi�:
> > At 07 Jan 2003 23:02:03 +0100,
> > Ander wrote:
> > > Package: libc6
> > > Version: 2.3.1-8
> > > Severity: critical
> > > 
> > > Opening a file with fopen in mode a+ will position the stream at the
> > > begining of the file and not at the end.
> > > 
> > > I am using Debian GNU/Linux testing/unstable, kernel 2.4.19 and libc6
> > > 2.3.1-8
> > > 
> > 
> > Send us minimal test program.
> > You have to check below test.  You find it works fine.
> > 
> I have check your test and it works, but check this one:
> 
> #include <stdio.h>
> 
> int main(void)
> {
>  	FILE *archivo;
> 	int pos;
> 
> 	archivo=fopen("main.c","a+");
> 	pos=ftell(archivo);
> 	printf("file pos after opening: %i\n",pos);
> 	fseek(archivo,0,SEEK_SET);
> 	pos=ftell(archivo);
> 	printf("file pos after SEEK_SET: %i\n",pos);
> 	fseek(archivo,0,SEEK_END);
> 	pos=ftell(archivo);
> 	printf("file pos after SEEK_END: %i\n",pos);
> 	fclose(archivo);
> 
> 	return 0;
> }

Read the standard.  XPG6 says:

    a+ or ab+ or a+b	Append; open or create file for update, writing
			at end-of-file.

    Opening a file with append mode (a as the first character in the
    mode argument) shall cause all subsequent writes to the file to be
    forced to the then current end-of-file, regardless of intervening
    calls to fseek( ).

ISO C99:

    a+ append; open or create text file for update, writing at
    end-of-file

    Opening a file with append mode (theathe as the first character in
    the mode argument) causes all subsequent writes to the file to be
    forced to the then current end-of-file, regardless of intervening
    calls to the fseek function. In some implementations, opening a
    binary file with append mode (thebthe as the second or third
    character in the above list of mode argument values) may initially
    position the file position indicator for the stream beyond the
    last data written, because of null character padding.

    When a file is opened with update mode (the+the as the second or
    third character in the above list of mode argument values), both
    input and output may be performed on the associated
    stream. However, output shall not be directly followed by input
    without an intervening call to the fflush function or to a file
    positioning function (fseek, fsetpos,orrewind), and input shall
    not be directly followed by output without an intervening call to
    a file positioning function, unless the input operation encounters
    end-of- file. Opening (or creating) a text file with update mode
    may instead open (or create) a binary stream in some
    implementations.

I guess you argue "opening a file with fopen in mode a+ will move file
position indicator in a stream at the end", but it's not true.

It's not bug.  I close this report.

-- gotom



Reply to: