Re: cvs: php4 /ext/standard basic_functions.c file.c /main streams.c
| From: | Andi Gutmans | Date: | Sat, 16 Mar 2002 18:16:11 +0000 |
| Subject: | Re: cvs: php4 /ext/standard basic_functions.c file.c /main streams.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-10254@lists.php.net to get a copy of this message | ||
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 EDTModified files:/php4/ext/standard basic_functions.c file.c /php4/main streams.cLog: 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