Bug #13832: fseek() offset problem with Win32 newlines

From: Date: Fri, 26 Oct 2001 01:42:01 +0000
Subject: Bug #13832: fseek() offset problem with Win32 newlines
Groups: php.dev 
Request: Send a blank email to php-dev+get-69033@lists.php.net to get a copy of this message
From:             ryan@footboot.net
Operating system: Windows 2000 Professional
PHP version:      4.0.6
PHP Bug Type:     Filesystem function related
Bug description:  fseek() offset problem with Win32 newlines

Note: this still occurs in 4.0.6 (I think they're the same bug)

What I did: tried to read over a file backwards using fseek().

What should have happened: I should be able to create an array of the last
few lines of a file, without reading the whole file.

What did happen: for every newline fseek()ed over fread() seemed to gain a
byte.

I believe this could be a problem with the way fseek() handles new lines in
Win32 (possibly not always). fread() seems to read Win32 newlines as one
byte, while fseek() reads them as two.

In the following example, if the file has no newlines or the newlines are
in Unix format, $buf is identical. If there are Win32 newlines, it isn't.

<example>
$fp = fopen('/temp/newline.txt', 'r');

fread($fp, 5);
$buf = fread($fp, 5);


fclose($fp);

$fp = fopen('/temp/newline.txt', 'r');

fseek($fp, 5);
$buf = fread($fp, 5);

fclose($fp);
</example>
-- 
Edit bug report at: http://bugs.php.net/?id=13832&edit=1



Thread (4 messages)

« previous php.dev (#69033) next »