]> granicus.if.org Git - php/commitdiff
MFH: Added optional offset parameter to stream_get_contents().
authorIlia Alshanetsky <iliaa@php.net>
Tue, 12 Oct 2004 23:25:24 +0000 (23:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 12 Oct 2004 23:25:24 +0000 (23:25 +0000)
NEWS
ext/standard/streamsfuncs.c

diff --git a/NEWS b/NEWS
index 644b5ceecb5e7b86b288c782f72b32b6fb609105..93b39c1d8d08045850b6636236b6e0d627dbd29b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
+- Added optional offset parameter to stream_get_contents(). (Ilia)
 - Improved performance of:
   . general execution/compilation. (Andi, Thies, Sterling, Dmitry, Marcus)
   . switch statement. (Dmitry)
index 91093a76534399d53a70ba075d40fb6268fca26d..2853ac1ea99f2b06823c1854423c53d6888be5e5 100644 (file)
@@ -354,22 +354,27 @@ PHP_FUNCTION(stream_socket_recvfrom)
 }
 /* }}} */
 
-/* {{{ proto long stream_get_contents(resource source [, long maxlen ])
+/* {{{ proto long stream_get_contents(resource source [, long maxlen [, long offset]])
    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;
+       long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
        int len, newlen;
        char *contents = NULL;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zsrc, &maxlen) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &pos) == FAILURE) {
                RETURN_FALSE;
        }
 
        php_stream_from_zval(stream, &zsrc);
 
+       if (pos > 0 && php_stream_seek(stream, pos, SEEK_SET) < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to %ld position in the stream.", pos);
+               RETURN_FALSE;
+       }
+
        if ((len = php_stream_copy_to_mem(stream, &contents, maxlen, 0)) > 0) {
                
                if (PG(magic_quotes_runtime)) {