|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13832 fseek() offset problem with Win32 newlines
Submitted: 2001-10-25 21:42 UTC Modified: 2001-10-26 01:35 UTC
From: ryan at footboot dot net Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.0.6 OS: Windows 2000 Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
48 - 34 = ?
Subscribe to this entry?

 [2001-10-25 21:42 UTC] ryan at footboot dot net
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.

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

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


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

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



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-25 21:44 UTC] ryan at footboot dot net
This bug is probably related to bug number #6023 ("Problem with either fgets or ftell in ISAPI")
 [2001-10-26 01:35 UTC]
Markus says it's bogus
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jul 23 16:01:23 2021 UTC