Browse Source

Added optional offset parameter to file_get_contents().

PHP-5.1
Ilia Alshanetsky 22 years ago
parent
commit
51ffc01776
  1. 3
      NEWS
  2. 12
      ext/standard/file.c

3
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)

12
ext/standard/file.c

@ -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) {

Loading…
Cancel
Save