FAQ
wez Sat Mar 16 11:06:19 2002 EDT

Modified files:
/php4/ext/standard basic_functions.c file.c
/php4/main streams.c
Log:
Implement get_file_contents() as discussed (briefly!) by myself, Derick
and Sterling on php-dev some months ago.
It returns the file contents as a string, and uses mmap if possible.


Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.450 php4/ext/standard/basic_functions.c:1.451
--- php4/ext/standard/basic_functions.c:1.450 Sat Mar 16 07:45:42 2002
+++ php4/ext/standard/basic_functions.c Sat Mar 16 11:06:12 2002
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/

-/* $Id: basic_functions.c,v 1.450 2002/03/16 12:45:42 mfischer Exp $ */
+/* $Id: basic_functions.c,v 1.451 2002/03/16 16:06:12 wez Exp $ */

#include "php.h"
#include "php_streams.h"
@@ -611,6 +611,7 @@
PHP_FE(tempnam, NULL)
PHP_STATIC_FE("tmpfile", php_if_tmpfile, NULL)
PHP_FE(file, NULL)
+ PHP_FE(get_file_contents, NULL)
PHP_FE(fgetcsv, NULL)
PHP_FE(flock, NULL)
PHP_FE(get_meta_tags, NULL)
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.209 php4/ext/standard/file.c:1.210
--- php4/ext/standard/file.c:1.209 Fri Mar 15 21:48:35 2002
+++ php4/ext/standard/file.c Sat Mar 16 11:06:14 2002
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/

-/* $Id: file.c,v 1.209 2002/03/16 02:48:35 wez Exp $ */
+/* $Id: file.c,v 1.210 2002/03/16 16:06:14 wez Exp $ */

/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */

@@ -365,6 +365,49 @@
}

/* }}} */
+
+/* {{{ proto string get_file_contents(string filename [, bool use_include_path])
+ Read the entire file into a string */
+PHP_FUNCTION(get_file_contents)
+{
+ char *filename;
+ int filename_len;
+ char *contents, *target_buf;
+ zend_bool use_include_path = 0;
+ php_stream *stream;
+ int len, newlen;
+
+ /* Parse arguments */
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
+ &filename, &filename_len, &use_include_path) == FAILURE) {
+ return;
+ }
+
+ stream = php_stream_open_wrapper(filename, "rb",
+ use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
+ NULL TSRMLS_CC);
+ if (!stream) {
+ RETURN_FALSE;
+ }
+
+ /* uses mmap if possible */
+ if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) > 0) {
+
+ if (PG(magic_quotes_runtime)) {
+ contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
+ len = newlen;
+ }
+
+ RETVAL_STRINGL(contents, len);
+ } else {
+ RETVAL_FALSE;
+ }
+
+ php_stream_close(stream);
+
+}
+/* }}} */
+
/* {{{ proto array file(string filename [, bool use_include_path])
Read entire file into an array */

@@ -390,7 +433,7 @@
stream = php_stream_open_wrapper(filename, "rb",
use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
NULL TSRMLS_CC);
- if (!stream) {
+ if (!stream) {
RETURN_FALSE;
}

Index: php4/main/streams.c
diff -u php4/main/streams.c:1.20 php4/main/streams.c:1.21
--- php4/main/streams.c:1.20 Sat Mar 16 09:39:51 2002
+++ php4/main/streams.c Sat Mar 16 11:06:18 2002
@@ -90,7 +90,7 @@
ret = stream->ops->close(stream, call_dtor);
stream->abstract = NULL;

- if (call_dtor) {
+ if (call_dtor) {
/* tidy up any FILE* that might have been fdopened */
if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN && stream->stdiocast) {
fclose(stream->stdiocast);

Search Discussions

  • Markus Fischer at Mar 16, 2002 at 4:27 pm

    On Sat, Mar 16, 2002 at 04:06:19PM -0000, Wez Furlong wrote :
    wez Sat Mar 16 11:06:19 2002 EDT

    Modified files:
    /php4/ext/standard basic_functions.c file.c
    /php4/main streams.c
    Log:
    Implement get_file_contents() as discussed (briefly!) by myself, Derick
    and Sterling on php-dev some months ago.
    It returns the file contents as a string, and uses mmap if possible.
    Sorry for this question, but shouldn't the name be
    file_get_contents() ? We already have ob_get_contents() for
    exmaple.

    --
    Please always Cc to me when replying to me on the lists.
    GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
  • Wez Furlong at Mar 16, 2002 at 4:49 pm
    You're probably right; I'll change it.

    --Wez.
    On 17/03/02, "Markus Fischer" wrote:
    On Sat, Mar 16, 2002 at 04:06:19PM -0000, Wez Furlong wrote :
    wez Sat Mar 16 11:06:19 2002 EDT

    Modified files:
    /php4/ext/standard basic_functions.c file.c
    /php4/main streams.c
    Log:
    Implement get_file_contents() as discussed (briefly!) by myself, Derick
    and Sterling on php-dev some months ago.
    It returns the file contents as a string, and uses mmap if possible.
    Sorry for this question, but shouldn't the name be
    file_get_contents() ? We already have ob_get_contents() for
    exmaple.

    --
    Please always Cc to me when replying to me on the lists.
    GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
  • Andi Gutmans at Mar 16, 2002 at 6:17 pm
    Can we call it file_get_contents?
    With new functions we should try and stay with the standard of
    <module>_<function_name>

    Andi
    At 04:06 PM 3/16/2002 +0000, Wez Furlong wrote:
    wez Sat Mar 16 11:06:19 2002 EDT

    Modified files:
    /php4/ext/standard basic_functions.c file.c
    /php4/main streams.c
    Log:
    Implement get_file_contents() as discussed (briefly!) by myself, Derick
    and Sterling on php-dev some months ago.
    It returns the file contents as a string, and uses mmap if possible.


    Index: php4/ext/standard/basic_functions.c
    diff -u php4/ext/standard/basic_functions.c:1.450
    php4/ext/standard/basic_functions.c:1.451
    --- php4/ext/standard/basic_functions.c:1.450 Sat Mar 16 07:45:42 2002
    +++ php4/ext/standard/basic_functions.c Sat Mar 16 11:06:12 2002
    @@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
    */

    -/* $Id: basic_functions.c,v 1.450 2002/03/16 12:45:42 mfischer Exp $ */
    +/* $Id: basic_functions.c,v 1.451 2002/03/16 16:06:12 wez Exp $ */

    #include "php.h"
    #include "php_streams.h"
    @@ -611,6 +611,7 @@
    PHP_FE(tempnam,
    NULL)
    PHP_STATIC_FE("tmpfile", php_if_tmpfile,
    NULL)
    PHP_FE(file,
    NULL)
    + PHP_FE(get_file_contents,
    NULL)
    PHP_FE(fgetcsv,
    NULL)
    PHP_FE(flock,
    NULL)
    PHP_FE(get_meta_tags,
    NULL)
    Index: php4/ext/standard/file.c
    diff -u php4/ext/standard/file.c:1.209 php4/ext/standard/file.c:1.210
    --- php4/ext/standard/file.c:1.209 Fri Mar 15 21:48:35 2002
    +++ php4/ext/standard/file.c Sat Mar 16 11:06:14 2002
    @@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
    */

    -/* $Id: file.c,v 1.209 2002/03/16 02:48:35 wez Exp $ */
    +/* $Id: file.c,v 1.210 2002/03/16 16:06:14 wez Exp $ */

    /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */

    @@ -365,6 +365,49 @@
    }

    /* }}} */
    +
    +/* {{{ proto string get_file_contents(string filename [, bool
    use_include_path])
    + Read the entire file into a string */
    +PHP_FUNCTION(get_file_contents)
    +{
    + char *filename;
    + int filename_len;
    + char *contents, *target_buf;
    + zend_bool use_include_path = 0;
    + php_stream *stream;
    + int len, newlen;
    +
    + /* Parse arguments */
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
    + &filename,
    &filename_len, &use_include_path) == FAILURE) {
    + return;
    + }
    +
    + stream = php_stream_open_wrapper(filename, "rb",
    + use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
    + NULL TSRMLS_CC);
    + if (!stream) {
    + RETURN_FALSE;
    + }
    +
    + /* uses mmap if possible */
    + if ((len = php_stream_copy_to_mem(stream, &contents,
    PHP_STREAM_COPY_ALL, 0)) > 0) {
    +
    + if (PG(magic_quotes_runtime)) {
    + contents = php_addslashes(contents, len, &newlen,
    1 TSRMLS_CC); /* 1 = free source string */
    + len = newlen;
    + }
    +
    + RETVAL_STRINGL(contents, len);
    + } else {
    + RETVAL_FALSE;
    + }
    +
    + php_stream_close(stream);
    +
    +}
    +/* }}} */
    +
    /* {{{ proto array file(string filename [, bool use_include_path])
    Read entire file into an array */

    @@ -390,7 +433,7 @@
    stream = php_stream_open_wrapper(filename, "rb",
    use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
    NULL TSRMLS_CC);
    - if (!stream) {
    + if (!stream) {
    RETURN_FALSE;
    }

    Index: php4/main/streams.c
    diff -u php4/main/streams.c:1.20 php4/main/streams.c:1.21
    --- php4/main/streams.c:1.20 Sat Mar 16 09:39:51 2002
    +++ php4/main/streams.c Sat Mar 16 11:06:18 2002
    @@ -90,7 +90,7 @@
    ret = stream->ops->close(stream, call_dtor);
    stream->abstract = NULL;

    - if (call_dtor) {
    + if (call_dtor) {
    /* tidy up any FILE* that might have been fdopened */
    if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN
    && stream->stdiocast) {
    fclose(stream->stdiocast);



    --
    PHP CVS Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Andi Gutmans at Mar 16, 2002 at 6:19 pm
    Sorry, I didn't see this was already taken care of.

    Andi
    At 08:16 PM 3/16/2002 +0200, Andi Gutmans wrote:
    Can we call it file_get_contents?
    With new functions we should try and stay with the standard of
    <module>_<function_name>

    Andi
    At 04:06 PM 3/16/2002 +0000, Wez Furlong wrote:
    wez Sat Mar 16 11:06:19 2002 EDT

    Modified files:
    /php4/ext/standard basic_functions.c file.c
    /php4/main streams.c
    Log:
    Implement get_file_contents() as discussed (briefly!) by myself, Derick
    and Sterling on php-dev some months ago.
    It returns the file contents as a string, and uses mmap if possible.


    Index: php4/ext/standard/basic_functions.c
    diff -u php4/ext/standard/basic_functions.c:1.450
    php4/ext/standard/basic_functions.c:1.451
    --- php4/ext/standard/basic_functions.c:1.450 Sat Mar 16 07:45:42 2002
    +++ php4/ext/standard/basic_functions.c Sat Mar 16 11:06:12 2002
    @@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
    */

    -/* $Id: basic_functions.c,v 1.450 2002/03/16 12:45:42 mfischer Exp $ */
    +/* $Id: basic_functions.c,v 1.451 2002/03/16 16:06:12 wez Exp $ */

    #include "php.h"
    #include "php_streams.h"
    @@ -611,6 +611,7 @@
    PHP_FE(tempnam,
    NULL)
    PHP_STATIC_FE("tmpfile", php_if_tmpfile,
    NULL)
    PHP_FE(file,
    NULL)
    + PHP_FE(get_file_contents,
    NULL)
    PHP_FE(fgetcsv,
    NULL)
    PHP_FE(flock,
    NULL)
    PHP_FE(get_meta_tags,
    NULL)
    Index: php4/ext/standard/file.c
    diff -u php4/ext/standard/file.c:1.209 php4/ext/standard/file.c:1.210
    --- php4/ext/standard/file.c:1.209 Fri Mar 15 21:48:35 2002
    +++ php4/ext/standard/file.c Sat Mar 16 11:06:14 2002
    @@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
    */

    -/* $Id: file.c,v 1.209 2002/03/16 02:48:35 wez Exp $ */
    +/* $Id: file.c,v 1.210 2002/03/16 16:06:14 wez Exp $ */

    /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */

    @@ -365,6 +365,49 @@
    }

    /* }}} */
    +
    +/* {{{ proto string get_file_contents(string filename [, bool
    use_include_path])
    + Read the entire file into a string */
    +PHP_FUNCTION(get_file_contents)
    +{
    + char *filename;
    + int filename_len;
    + char *contents, *target_buf;
    + zend_bool use_include_path = 0;
    + php_stream *stream;
    + int len, newlen;
    +
    + /* Parse arguments */
    + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
    + &filename,
    &filename_len, &use_include_path) == FAILURE) {
    + return;
    + }
    +
    + stream = php_stream_open_wrapper(filename, "rb",
    + use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS,
    + NULL TSRMLS_CC);
    + if (!stream) {
    + RETURN_FALSE;
    + }
    +
    + /* uses mmap if possible */
    + if ((len = php_stream_copy_to_mem(stream, &contents,
    PHP_STREAM_COPY_ALL, 0)) > 0) {
    +
    + if (PG(magic_quotes_runtime)) {
    + contents = php_addslashes(contents, len, &newlen,
    1 TSRMLS_CC); /* 1 = free source string */
    + len = newlen;
    + }
    +
    + RETVAL_STRINGL(contents, len);
    + } else {
    + RETVAL_FALSE;
    + }
    +
    + php_stream_close(stream);
    +
    +}
    +/* }}} */
    +
    /* {{{ proto array file(string filename [, bool use_include_path])
    Read entire file into an array */

    @@ -390,7 +433,7 @@
    stream = php_stream_open_wrapper(filename, "rb",
    use_include_path | ENFORCE_SAFE_MODE |
    REPORT_ERRORS,
    NULL TSRMLS_CC);
    - if (!stream) {
    + if (!stream) {
    RETURN_FALSE;
    }

    Index: php4/main/streams.c
    diff -u php4/main/streams.c:1.20 php4/main/streams.c:1.21
    --- php4/main/streams.c:1.20 Sat Mar 16 09:39:51 2002
    +++ php4/main/streams.c Sat Mar 16 11:06:18 2002
    @@ -90,7 +90,7 @@
    ret = stream->ops->close(stream, call_dtor);
    stream->abstract = NULL;

    - if (call_dtor) {
    + if (call_dtor) {
    /* tidy up any FILE* that might have been fdopened */
    if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FDOPEN
    && stream->stdiocast) {
    fclose(stream->stdiocast);



    --
    PHP CVS Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

    --
    PHP CVS Mailing List (http://www.php.net/)
    To unsubscribe, visit: http://www.php.net/unsub.php

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-cvs @
categoriesphp
postedMar 16, '02 at 4:06p
activeMar 16, '02 at 6:19p
posts5
users4
websitephp.net

People

Translate

site design / logo © 2019 Grokbase