MFH: Added optional offset parameter to stream_get_contents().

This commit is contained in:
Ilia Alshanetsky 2004-10-12 23:25:24 +00:00
parent 0c40e2a06e
commit 2390ca71f1
2 changed files with 9 additions and 3 deletions

1
NEWS
View File

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

View File

@ -354,22 +354,27 @@ PHP_FUNCTION(stream_socket_recvfrom)
}
/* }}} */
/* {{{ 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)) {