Bug #49148 [Opn->Csd]: combination of stream_get_line and fseek does not work correctly

From: Date: Wed, 16 Jul 2014 03:18:45 +0000
Subject: Bug #49148 [Opn->Csd]: combination of stream_get_line and fseek does not work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186658@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=49148&edit=1

 ID:                 49148
 Updated by:         yohgaki@php.net
 Reported by:        mugeso at mugeso dot com
 Summary:            combination of stream_get_line and fseek does not
                     work correctly
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Streams related
 Operating System:   win32 only - Windows XP SP3
 PHP Version:        5.2.10
-Assigned To:        
+Assigned To:        yohgaki
 Block user comment: N
 Private report:     N

 New Comment:

It seems fixed in 5.4 and later with linux. Closing.
If you have issue on Windows. Please re-open.


Previous Comments:
------------------------------------------------------------------------
[2010-10-15 01:22:42] arl at andrewrlevine dot com

I can confirm this bug (on Ubuntu using PHP 5.2.10-2ubuntu6.5 with Suhosin-Patch 
0.9.7 (cli) (built: May 21 2010 06:30:21) )

Here is a workaround function I made that seems to work:

function stream_get_line_fixed($handle, $length, $ending) {
    // Only allow 3 tries since if there's a genuine failure we don't want to 
loop forever
    $tries = 3;
    $ret = FALSE;
    while ($ret === FALSE && $tries--) {
      $ret = stream_get_line($handle, $length, $ending);
    }
    return $ret;
  }

------------------------------------------------------------------------
[2009-08-31 20:04:38] garretts@php.net

This is reproduceable on Linux too.




------------------------------------------------------------------------
[2009-08-04 07:44:16] mugeso at mugeso dot com

Description:
------------
When use in combination of stream_get_line and fseek,
reading a file which has only 2 lines without ending on EOF(like below) does fail.
This happens on only Windows and with only "2lines file without ending on EOF".



Reproduce code:
---------------
2lines.txt
--
a<CRLF>
b<EOF>

phpfile:
--
<?php
$file = dirname(__FILE__) . '/2lines.txt';
$fp = fopen($file, "rb");
var_dump(stream_get_line($fp, null, "\xd\xa"));
fseek($fp, ftell($fp)); // expected that this does not affect result.
var_dump(stream_get_line($fp, null, "\xd\xa"));

Expected result:
----------------
string(1) "a"
string(1) "b"


Actual result:
--------------
string(1) "a"
bool(false)



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



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


Thread (4 messages)

« previous php.bugs (#186658) next »