php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #24071 4.3.2 fopen("filename", "a") not place file pointer to the end.
Submitted: 2003-06-06 17:46 UTC Modified: 2004-08-07 15:56 UTC
Votes:4
Avg. Score:2.8 ± 1.1
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: artem at w510 dot tm dot odessa dot ua Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.2 OS: redhat
Private report: No CVE-ID: None
 [2003-06-06 17:46 UTC] artem at w510 dot tm dot odessa dot ua
after installing 4.3.2 
 $fr = fopen("filename", "a");
 $pointer = ftell($fr);

points to 0! forced to add

  fseek($fr, 0, SEEK_END);
  $pointer = ftell($fr);

to move to the file end

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-06 18:11 UTC] wez@php.net
'a' mode forces the kernel to always write at the end of the file.
ftell() will give undefined results for append-only streams, as will seeking.

Writing to such a file should always be appended, regardless of the results from ftell().

Making this a documentation problem.
 [2003-06-06 18:33 UTC] artem at w510 dot tm dot odessa dot ua
maybe,
but i used this without any problem from version 4.0 (one of first) to store initial append position  - that' about some years...
and it's worked through updates up to 4.2.3
 [2004-08-07 10:56 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"ftell() gives undefined results for append-only streams (opened with "a" flag)."
 [2004-08-07 11:39 UTC] vrana@php.net
From code at php-src/main/streams/streams.c:1693 (revision 1.61) it seems that this is supposed to work (but doesn't).

	if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) {
		off_t newpos = 0;

		/* if opened for append, we need to revise our idea of the initial file position */
		if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) {
			stream->position = newpos;
		}
	}

If it will be fixed, reclasify this back to docprob so we can add a note that it works since version x.x.x.

(Spotted by dave@php.net.)
 [2004-08-07 14:48 UTC] wez@php.net
Read my lips...
Using ftell() and fseek() on append mode streams is undefined.
Period.

 [2004-08-07 15:56 UTC] nlopess@php.net
I've also add the note to fseek().
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 04 17:01:30 2024 UTC