Skip to content

Commit be8c06a

Browse files
committed
Don't set position=0 on ESPIPE
We should recognize that this is a pipe, but leave the position as -1, as the pipe is not seekable. This makes the behavior consistent between fd+file and as such also between STDIN and php://stdin.
1 parent a2c21e1 commit be8c06a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

main/streams/plain_wrapper.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha
270270
stream->position = zend_lseek(self->fd, 0, SEEK_CUR);
271271
#ifdef ESPIPE
272272
if (stream->position == (zend_off_t)-1 && errno == ESPIPE) {
273-
stream->position = 0;
274273
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
275274
self->is_pipe = 1;
276275
}

sapi/cli/tests/std_streams.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Testing ftell() on std streams
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_IO_CAPTURE_TESTS")) {
6+
die("skip I/O capture test");
7+
}
8+
?>
9+
--CAPTURE_STDIO--
10+
STDOUT
11+
--FILE--
12+
<?php
13+
14+
var_dump(ftell(STDIN));
15+
var_dump(ftell(STDERR));
16+
var_dump(ftell(fopen("php://stdin", "r")));
17+
var_dump(ftell(fopen("php://stderr", "w")));
18+
19+
var_dump(ftell(STDOUT));
20+
var_dump(ftell(fopen("php://stdout", "w")));
21+
22+
?>
23+
--EXPECT--
24+
bool(false)
25+
bool(false)
26+
bool(false)
27+
bool(false)
28+
int(0)
29+
int(0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy