wez Sat Sep 7 15:00:51 2002 EDT
Modified files:
/php4/ext/standard php_fopen_wrapper.c
Log:
Implement php://output wrapper, which can be used to write to the output
buffer via PHPWRITE.
Index: php4/ext/standard/php_fopen_wrapper.c
diff -u php4/ext/standard/php_fopen_wrapper.c:1.21
php4/ext/standard/php_fopen_wrapper.c:1.22
--- php4/ext/standard/php_fopen_wrapper.c:1.21 Tue Apr 16 18:14:24 2002
+++ php4/ext/standard/php_fopen_wrapper.c Sat Sep 7 15:00:46 2002
@@ -17,7 +17,7 @@
| Hartmut Holzgraefe <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: php_fopen_wrapper.c,v 1.21 2002/04/16 22:14:24 wez Exp $ */
+/* $Id: php_fopen_wrapper.c,v 1.22 2002/09/07 19:00:46 wez Exp $ */
#include <stdio.h>
#include <stdlib.h>
@@ -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 @@
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 @@
} 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);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php