From 038ba12e8724d537040e88ec794354b0c063f0a6 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Fri, 18 Mar 2011 11:28:21 +0100 Subject: Imported Upstream version 5.3.6 --- ext/standard/php_fopen_wrapper.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'ext/standard/php_fopen_wrapper.c') diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 808a973a9..1360bab6c 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2010 The PHP Group | + | Copyright (c) 1997-2011 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ | Hartmut Holzgraefe | +----------------------------------------------------------------------+ */ -/* $Id: php_fopen_wrapper.c 293036 2010-01-03 09:23:27Z sebastian $ */ +/* $Id: php_fopen_wrapper.c 307536 2011-01-17 13:44:54Z iliaa $ */ #include #include @@ -257,6 +257,39 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch } else { fd = dup(STDERR_FILENO); } + } else if (!strncasecmp(path, "fd/", 3)) { + char *start, + *end; + long fildes_ori; + int dtablesize; + + start = &path[3]; + fildes_ori = strtol(start, &end, 10); + 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/"); + return NULL; + } + +#if HAVE_UNISTD_H + dtablesize = getdtablesize(); +#else + dtablesize = INT_MAX; +#endif + + if (fildes_ori < 0 || fildes_ori >= dtablesize) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "The file descriptors must be non-negative numbers smaller than %d", dtablesize); + return NULL; + } + + fd = dup(fildes_ori); + if (fd == -1) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, + "Error duping file descriptor %ld; possibly it doesn't exist: " + "[%d]: %s", fildes_ori, errno, strerror(errno)); + return NULL; + } } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) { -- cgit v1.2.3