]> granicus.if.org Git - php/commitdiff
Added optional offset parameter to file_get_contents().
authorIlia Alshanetsky <iliaa@php.net>
Wed, 13 Oct 2004 23:26:29 +0000 (23:26 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 13 Oct 2004 23:26:29 +0000 (23:26 +0000)
NEWS
ext/standard/file.c

diff --git a/NEWS b/NEWS
index 93b39c1d8d08045850b6636236b6e0d627dbd29b..3747e4cb041ee222672e99989dfcf0ccff213ea5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2004, PHP 5.1.0
-- Added optional offset parameter to stream_get_contents(). (Ilia)
+- Added optional offset parameter to stream_get_contents() and 
+  file_get_contents(). (Ilia)
 - Improved performance of:
   . general execution/compilation. (Andi, Thies, Sterling, Dmitry, Marcus)
   . switch statement. (Dmitry)
index da53e1968292cf18ec15289dd29225a5acf6d757..8869a1966ae4c458e92abfb4db508d963638fb38 100644 (file)
@@ -462,7 +462,7 @@ PHP_FUNCTION(get_meta_tags)
 
 /* }}} */
 
-/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context]])
+/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset]]])
    Read the entire file into a string */
 PHP_FUNCTION(file_get_contents)
 {
@@ -472,12 +472,13 @@ PHP_FUNCTION(file_get_contents)
        zend_bool use_include_path = 0;
        php_stream *stream;
        int len, newlen;
+       long offset = -1;
        zval *zcontext = NULL;
        php_stream_context *context = NULL;
 
        /* Parse arguments */
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!",
-                                 &filename, &filename_len, &use_include_path, &zcontext) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!l",
+                                 &filename, &filename_len, &use_include_path, &zcontext, &offset) == FAILURE) {
                return;
        }
 
@@ -490,6 +491,11 @@ PHP_FUNCTION(file_get_contents)
                RETURN_FALSE;
        }
 
+       if (offset > 0 && php_stream_seek(stream, offset, SEEK_SET) < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to %ld position in the stream.", offset);
+               RETURN_FALSE;
+       }
+
        /* uses mmap if possible */
        if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {