start = &path[3];
fildes_ori = strtol(start, &end, 10);
- if (end == start || (*end != '\0' && *end != '/')) {
+ if (end == start || *end != '\0') {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC,
"php://fd/ stream must be specified in the form php://fd/<orig fd>");
return NULL;
--- /dev/null
+--TEST--
+php://fd wrapper: basic test
+--FILE--
+<?php
+$f = fopen("php://fd/1", "wb");
+fwrite($f, "hi!");
+
+echo "\nDone.\n";
+--EXPECT--
+hi!
+Done.
--- /dev/null
+--TEST--
+php://fd wrapper: mode is ignored
+--FILE--
+<?php
+$f = fopen("php://fd/1", "rkkk");
+fwrite($f, "hi!");
+
+echo "\nDone.\n";
+--EXPECT--
+hi!
+Done.
--- /dev/null
+--TEST--
+php://fd wrapper: bad syntax
+--FILE--
+<?php
+fopen("php://fd", "w");
+fopen("php://fd/", "w");
+fopen("php://fd/-2", "w");
+fopen("php://fd/1/", "w");
+
+echo "\nDone.\n";
+--EXPECTF--
+Warning: fopen(): Invalid php:// URL specified in %s on line %d
+
+Warning: fopen(php://fd): failed to open stream: operation failed in %s on line 2
+
+Warning: fopen(php://fd/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
+
+Warning: fopen(php://fd/-2): failed to open stream: The file descriptors must be non-negative numbers smaller than %d in %s on line %d
+
+Warning: fopen(php://fd/1/): failed to open stream: php://fd/ stream must be specified in the form php://fd/<orig fd> in %s on line %d
+
+Done.
--- /dev/null
+--TEST--
+php://fd wrapper: invalid file descriptor
+--SKIPIF--
+<?php include('skipif.inc');
+if(substr(PHP_OS, 0, 3) == "WIN")
+ die("skip Not for Windows");
+
+//we'd need a release and a test variation for windows, because in debug builds we get this message:
+//Warning: Invalid parameter detected in CRT function '_dup' (f:\dd\vctools\crt_bld\self_x86\crt\src\dup.c:52)
+//I greped the CRT sources and found no function capable of validating a file descriptor
+
+--FILE--
+<?php
+fopen("php://fd/12", "w");
+
+echo "\nDone.\n";
+--EXPECTF--
+Warning: fopen(php://fd/12): failed to open stream: Error duping file descriptor 12; possibly it doesn't exist: [9]: %s in %s on line %d
+
+Done.