iliaa           Tue Oct 12 19:25:24 2004 EDT

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       streamsfuncs.c 
  Log:
  MFH: Added optional offset parameter to stream_get_contents().
  
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1818&r2=1.1819&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1818 php-src/NEWS:1.1819
--- php-src/NEWS:1.1818 Fri Oct  8 10:51:55 2004
+++ php-src/NEWS        Tue Oct 12 19:25:23 2004
@@ -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)
http://cvs.php.net/diff.php/php-src/ext/standard/streamsfuncs.c?r1=1.43&r2=1.44&ty=u
Index: php-src/ext/standard/streamsfuncs.c
diff -u php-src/ext/standard/streamsfuncs.c:1.43 
php-src/ext/standard/streamsfuncs.c:1.44
--- php-src/ext/standard/streamsfuncs.c:1.43    Mon Oct 11 14:31:49 2004
+++ php-src/ext/standard/streamsfuncs.c Tue Oct 12 19:25:24 2004
@@ -17,7 +17,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: streamsfuncs.c,v 1.43 2004/10/11 18:31:49 iliaa Exp $ */
+/* $Id: streamsfuncs.c,v 1.44 2004/10/12 23:25:24 iliaa Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -354,22 +354,27 @@
 }
 /* }}} */
 
-/* {{{ 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)) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to