Bug #2954: feof doesn't always evaluate correctly

From: Date: Fri, 10 Dec 1999 18:47:07 +0000
Subject: Bug #2954: feof doesn't always evaluate correctly
Groups: php.dev 
Request: Send a blank email to php-dev+get-13565@lists.php.net to get a copy of this message
From: nickl@mycomputer.com Operating system: linux RH PHP version: 3.0.12 PHP Bug Type: Misbehaving function Bug description: feof doesn't always evaluate correctly If 'tmp' is a file that is exactly 25 bytes long, then: $fd = fopen('tmp', 'r'); echo "fpos: " . ftell($fd) . " eof: " . feof($fd) . "\n"; fread($fd, 25); echo "fpos: " . ftell($fd) . " eof: " . feof($fd) . "\n"; fread($fd, 1); echo "fpos: " . ftell($fd) . " eof: " . feof($fd) . "\n"; results: fpos: 0 eof?: fpos: 25 eof?: fpos: 25 eof?: 1 This caused one of my scripts to crash since even though the next fread() didn't die, passing the null it returned on to an unpack() did. My current work-around is rather than to use: while (feof($fd)) {} I do: $size = filesize($file); while (ftell($fd) < $size) {} However, this obviously won't work on streams that don't come from the local filesystem. My setup is: (from config.status) ./configure --with-mysql=/usr/local/mysql --enable-track-vars --enable-sysvsem --enable-sysvshm --with-gdchart=/usr/local/src/gdchart0.94b --with-gd=/usr/local/src/gd1.5 --prefix=/usr/local --with-ttf --enable-magic-quotes --with-apache=/usr/local/apache Actually, this isn't exactly correct - I also compile the CGI version - for which I remove the apache stuff... and in fact it's the CGI version that I was using when I noticed the problem.

« previous php.dev (#13565) next »