com php-src: refactor _php_stream_fopen_{temporary_ ,tmp}file(): main/streams/plain_wrapper.c
| From: | Michael Wallner | Date: | Thu, 03 Jul 2014 18:40:40 +0000 |
| Subject: | com php-src: refactor _php_stream_fopen_{temporary_ ,tmp}file(): main/streams/plain_wrapper.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79231@lists.php.net to get a copy of this message | ||
Commit: 11e401ab59b73b22dcd6ce91e250c82ca808cd4f
Author: Michael Wallner <mike@php.net> Wed, 2 Jul 2014 12:10:10 +0200
Parents: 04c6a5b3773548388dec178058f270f30fc0c4de
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=11e401ab59b73b22dcd6ce91e250c82ca808cd4f
Log:
refactor _php_stream_fopen_{temporary_,tmp}file()
Changed paths:
M main/streams/plain_wrapper.c
Diff:
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 5e9e5c7..aba16ff 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -183,31 +183,20 @@ static php_stream *_php_stream_fopen_from_file_int(FILE *file, const char
*mode
return php_stream_alloc_rel(&php_stream_stdio_ops, self, 0, mode);
}
-PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char
**opened_path STREAMS_DC TSRMLS_DC)
+PHPAPI php_stream *_php_stream_fopen_temporary_file(const char *dir, const char *pfx, char
**opened_path_ptr STREAMS_DC TSRMLS_DC)
{
- int fd = php_open_temporary_fd(dir, pfx, opened_path TSRMLS_CC);
+ char *opened_path = NULL;
+ int fd;
+ fd = php_open_temporary_fd(dir, pfx, opened_path TSRMLS_CC);
if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
- if (stream) {
- return stream;
- }
- close(fd);
-
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to allocate stream");
-
- return NULL;
- }
- return NULL;
-}
+ php_stream *stream;
-PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
-{
- char *opened_path = NULL;
- int fd = php_open_temporary_fd(NULL, "php", &opened_path TSRMLS_CC);
+ if (opened_path_ptr) {
+ *opened_path_ptr = opened_path;
+ }
- if (fd != -1) {
- php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
+ stream = php_stream_fopen_from_fd_int_rel(fd, "r+b", NULL);
if (stream) {
php_stdio_stream_data *self = (php_stdio_stream_data*)stream->abstract;
stream->wrapper = &php_plain_files_wrapper;
@@ -227,6 +216,11 @@ PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
return NULL;
}
+PHPAPI php_stream *_php_stream_fopen_tmpfile(int dummy STREAMS_DC TSRMLS_DC)
+{
+ return php_stream_fopen_temporary_file(NULL, "php", NULL);
+}
+
PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const char *persistent_id
STREAMS_DC TSRMLS_DC)
{
php_stream *stream = php_stream_fopen_from_fd_int_rel(fd, mode, persistent_id);