wez Wed Oct 8 06:07:26 2003 EDT
Modified files:
/php-src/ext/standard basic_functions.c streamsfuncs.c
streamsfuncs.h
Log:
Implement stream_get_contents, which is somewhat akin to file_get_contents,
except that it works on an already opened stream.
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.629
php-src/ext/standard/basic_functions.c:1.630
--- php-src/ext/standard/basic_functions.c:1.629 Tue Sep 30 05:52:10 2003
+++ php-src/ext/standard/basic_functions.c Wed Oct 8 06:07:25 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.629 2003/09/30 09:52:10 stas Exp $ */
+/* $Id: basic_functions.c,v 1.630 2003/10/08 10:07:25 wez Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -715,6 +715,7 @@
PHP_FE(stream_socket_accept,
third_arg_force_ref)
PHP_FE(stream_socket_get_name,
NULL)
PHP_FE(stream_copy_to_stream,
NULL)
+ PHP_FE(stream_get_contents,
NULL)
PHP_FE(fgetcsv,
NULL)
PHP_FE(flock,
NULL)
PHP_FE(get_meta_tags,
NULL)
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.25
php-src/ext/standard/streamsfuncs.c:1.26
--- php-src/ext/standard/streamsfuncs.c:1.25 Tue Jul 22 03:20:55 2003
+++ php-src/ext/standard/streamsfuncs.c Wed Oct 8 06:07:25 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streamsfuncs.c,v 1.25 2003/07/22 07:20:55 jason Exp $ */
+/* $Id: streamsfuncs.c,v 1.26 2003/10/08 10:07:25 wez Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -262,6 +262,38 @@
NULL, NULL
TSRMLS_CC)) {
RETURN_FALSE;
+ }
+}
+/* }}} */
+
+/* {{{ proto long stream_get_contents(resource source [, long maxlen ])
+ Reads all remaining bytes (or up to maxlen bytes) from a stream and returns them
as a string. */
+PHP_FUNCTION(stream_get_contents)
+{
+ php_stream *stream;
+ zval *zsrc;
+ long maxlen = PHP_STREAM_COPY_ALL;
+ int len, newlen;
+ char *contents = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zsrc, &maxlen) ==
FAILURE) {
+ RETURN_FALSE;
+ }
+
+ php_stream_from_zval(stream, &zsrc);
+
+ if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
+
+ if (PG(magic_quotes_runtime)) {
+ contents = php_addslashes(contents, len, &newlen, 1
TSRMLS_CC); /* 1 = free source string */
+ len = newlen;
+ }
+
+ RETVAL_STRINGL(contents, len, 0);
+ } else if (len == 0) {
+ RETVAL_EMPTY_STRING();
+ } else {
+ RETVAL_FALSE;
}
}
/* }}} */
Index: php-src/ext/standard/streamsfuncs.h
diff -u php-src/ext/standard/streamsfuncs.h:1.5 php-src/ext/standard/streamsfuncs.h:1.6
--- php-src/ext/standard/streamsfuncs.h:1.5 Tue Jun 10 16:03:38 2003
+++ php-src/ext/standard/streamsfuncs.h Wed Oct 8 06:07:25 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streamsfuncs.h,v 1.5 2003/06/10 20:03:38 imajes Exp $ */
+/* $Id: streamsfuncs.h,v 1.6 2003/10/08 10:07:25 wez Exp $ */
/* Flags for stream_socket_client */
#define PHP_STREAM_CLIENT_PERSISTENT 1
@@ -28,6 +28,7 @@
PHP_FUNCTION(stream_socket_get_name);
PHP_FUNCTION(stream_copy_to_stream);
+PHP_FUNCTION(stream_get_contents);
PHP_FUNCTION(set_socket_blocking); /* deprecated */
PHP_FUNCTION(stream_set_blocking);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php