summaryrefslogtreecommitdiff
path: root/ext/standard/php_fopen_wrapper.c
diff options
context:
space:
mode:
authorWez Furlong <wez@php.net>2002-09-07 19:00:46 +0000
committerWez Furlong <wez@php.net>2002-09-07 19:00:46 +0000
commit30082fdb6879563f1f0c91461e72367e611b4300 (patch)
tree0831d7b6bc7864590b67c6f645d80fa35b8fb119 /ext/standard/php_fopen_wrapper.c
parent759a0068aaaba71d5af72935d8d53bd179822c9c (diff)
downloadphp-git-30082fdb6879563f1f0c91461e72367e611b4300.tar.gz
Implement php://output wrapper, which can be used to write to the output
buffer via PHPWRITE.
Diffstat (limited to 'ext/standard/php_fopen_wrapper.c')
-rw-r--r--ext/standard/php_fopen_wrapper.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
index e2a9eea8b6..bc9e3a65b9 100644
--- a/ext/standard/php_fopen_wrapper.c
+++ b/ext/standard/php_fopen_wrapper.c
@@ -30,6 +30,40 @@
#include "php_standard.h"
#include "php_fopen_wrappers.h"
+static size_t php_stream_output_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+{
+ PHPWRITE(buf, count);
+ return count;
+}
+
+static size_t php_stream_output_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+{
+ return 0;
+}
+
+static int php_stream_output_close(php_stream *stream, int close_handle TSRMLS_DC)
+{
+ return 0;
+}
+
+static int php_stream_output_flush(php_stream *stream TSRMLS_DC)
+{
+ sapi_flush(TSRMLS_C);
+ return 0;
+}
+
+php_stream_ops php_stream_output_ops = {
+ php_stream_output_write,
+ php_stream_output_read,
+ php_stream_output_close,
+ php_stream_output_flush,
+ "Output",
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
FILE * fp = NULL;
@@ -38,6 +72,10 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
if (!strncasecmp(path, "php://", 6))
path += 6;
+ if (!strcasecmp(path, "output")) {
+ return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb");
+ }
+
if (!strcasecmp(path, "stdin")) {
fp = fdopen(dup(STDIN_FILENO), mode);
} else if (!strcasecmp(path, "stdout")) {
@@ -45,7 +83,6 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
} else if (!strcasecmp(path, "stderr")) {
fp = fdopen(dup(STDERR_FILENO), mode);
}
- /* TODO: implement php://output as a stream to write to the current output buffer ? */
if (fp) {
stream = php_stream_fopen_from_file(fp, mode);