From 55fd7ac6013b39601b3242d62fe0e0244da2d063 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 8 Feb 2005 15:25:45 +0000 Subject: [PATCH] Added optional maxlen parameter to file_get_contents(). --- NEWS | 1 + ext/standard/file.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index df5e8bc7c7..71372b8512 100644 --- 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) diff --git a/ext/standard/file.c b/ext/standard/file.c index b86dad6a5f..ca750ca709 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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 */ -- 2.40.0