]> granicus.if.org Git - php/commitdiff
Added optional maxlen parameter to file_get_contents().
authorIlia Alshanetsky <iliaa@php.net>
Tue, 8 Feb 2005 15:25:45 +0000 (15:25 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 8 Feb 2005 15:25:45 +0000 (15:25 +0000)
NEWS
ext/standard/file.c

diff --git a/NEWS b/NEWS
index df5e8bc7c74121747e180df15cff1e0855b6c4a7..71372b85128bb192f5785f05483e9bc59276819d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ PHP                                                                        NEWS
 - Added sqlite_fetch_column_types() 3rd argument for arrays. (Ilia)
 - Added optional offset parameter to stream_get_contents() and
   file_get_contents(). (Ilia)
+- Added optional maxlen parameter to file_get_contents(). (Ilia)
 - Added SAPI hook to get the current request time. (Rasmus)
 - Added new functions:
   . array_diff_key() (Andrey)
index b86dad6a5f0293755fcb4e41bd7d9f258412dc6d..ca750ca709cce604bc8ee4702dd6ead0a909658f 100644 (file)
@@ -506,7 +506,7 @@ PHP_FUNCTION(get_meta_tags)
 
 /* }}} */
 
-/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset]]])
+/* {{{ proto string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
    Read the entire file into a string */
 PHP_FUNCTION(file_get_contents)
 {
@@ -517,12 +517,13 @@ PHP_FUNCTION(file_get_contents)
        php_stream *stream;
        int len, newlen;
        long offset = -1;
+       long maxlen = PHP_STREAM_COPY_ALL;
        zval *zcontext = NULL;
        php_stream_context *context = NULL;
 
        /* Parse arguments */
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!l",
-                                 &filename, &filename_len, &use_include_path, &zcontext, &offset) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|br!ll",
+                                 &filename, &filename_len, &use_include_path, &zcontext, &offset, &maxlen) == FAILURE) {
                return;
        }
 
@@ -541,7 +542,7 @@ PHP_FUNCTION(file_get_contents)
        }
 
        /* uses mmap if possible */
-       if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {
+       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 */