diff options
author | Wez Furlong <wez@php.net> | 2003-03-18 16:40:29 +0000 |
---|---|---|
committer | Wez Furlong <wez@php.net> | 2003-03-18 16:40:29 +0000 |
commit | ce01fd9526d0fca767541e176d04c3a7079235c2 (patch) | |
tree | 0f1bac9b59f4f6b168e1af31f153bcc5f0d6307f /ext/standard/php_fopen_wrapper.c | |
parent | 40326f6adf7110bd6676bf7445cff7483cf173fb (diff) | |
download | php-git-ce01fd9526d0fca767541e176d04c3a7079235c2.tar.gz |
Avoid using FILE* where possible.
Tidy up handling of potential error situations for the php:// wrapper.
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r-- | ext/standard/php_fopen_wrapper.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c index 69e223a0b7..87ee5671df 100644 --- a/ext/standard/php_fopen_wrapper.c +++ b/ext/standard/php_fopen_wrapper.c @@ -171,15 +171,7 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch fd = dup(STDOUT_FILENO); } else if (!strcasecmp(path, "stderr")) { fd = dup(STDERR_FILENO); - } - - if (fd) { - stream = php_stream_fopen_from_fd(fd, mode); - if (stream == NULL) - close(fd); - } - - if (!strncasecmp(path, "filter/", 7)) { + } else if (!strncasecmp(path, "filter/", 7)) { /* Save time/memory when chain isn't specified */ if (strchr(mode, 'r') || strchr(mode, '+')) { mode_rw |= PHP_STREAM_FILTER_READ; @@ -213,7 +205,23 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch p = php_strtok_r(NULL, "/", &token); } efree(pathdup); - } + + return stream; + } else { + /* invalid php://thingy */ + return NULL; + } + + /* must be stdin, stderr or stdout */ + if (fd == -1) { + /* failed to dup */ + return NULL; + } + + stream = php_stream_fopen_from_fd(fd, mode); + if (stream == NULL) { + close(fd); + } return stream; } |