Bug #76995 [Opn]: fseek() breaks reading in read/append (a+) mode

From: Date: Wed, 10 Oct 2018 15:07:02 +0000
Subject: Bug #76995 [Opn]: fseek() breaks reading in read/append (a+) mode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217511@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76995&edit=1

 ID:                 76995
 User updated by:    miloslav dot hula at gmail dot com
 Reported by:        miloslav dot hula at gmail dot com
 Summary:            fseek() breaks reading in read/append (a+) mode
 Status:             Open
 Type:               Bug
 Package:            Streams related
 PHP Version:        7.3.0RC2
 Block user comment: N
 Private report:     N

 New Comment:

At least, documentation is misleading. "a+ mode is for reading/append". How can one read
from file, when cannot seek?

Could be clearer with: "only appended data can be read, seeking not supported"


Previous Comments:
------------------------------------------------------------------------
[2018-10-10 15:03:30] spam2 at rhsoft dot net

but what is the bug?

> seeking in a+ mode is bad idea
> and the result of calling fseek() will be undefined

undefined is what it is - undfined - therw is no right/wrong for undefined

------------------------------------------------------------------------
[2018-10-10 14:58:08] miloslav dot hula at gmail dot com

Description:
------------
URL in a test script shows, how fseek() in 'a+' mode breaks contents reading.

Documentation of fopen() says, that fseek() is OK, but documentation of fseek() says, that seeking
in a+ mode is bad idea.

In documentation of fopen():

a+ - Open for reading and writing; place the file pointer at the end of the file. If the file does
not exist, attempt to create it. In this mode, fseek() only affects the reading position, writes are
always appended.

In documentation of fseek():

If you have opened the file in append (a or a+) mode, any data you write to the file will always be
appended, regardless of the file position, and the result of calling fseek() will be undefined.

Test script:
---------------
https://3v4l.org/gTXsR



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76995&edit=1


Thread (5 messages)

« previous php.bugs (#217511) next »