sterling                Wed Mar 12 01:47:35 2003 EDT

  Modified files:              
    /php4/ext/standard  basic_functions.c file.c file.h 
  Log:
  @ Add the file_set_contents() function, as a complement to the file_get_contents()
  @ function. (Sterling)
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.595 
php4/ext/standard/basic_functions.c:1.596
--- php4/ext/standard/basic_functions.c:1.595   Sun Mar  9 18:12:31 2003
+++ php4/ext/standard/basic_functions.c Wed Mar 12 01:47:34 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.595 2003/03/09 23:12:31 pollita Exp $ */
+/* $Id: basic_functions.c,v 1.596 2003/03/12 06:47:34 sterling Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -672,6 +672,7 @@
        PHP_STATIC_FE("tmpfile",                php_if_tmpfile,                        
                         NULL)
        PHP_FE(file,                                                                   
                                                 NULL)
        PHP_FE(file_get_contents,                                                      
                                         NULL)
+       PHP_FE(file_set_contents,                                                      
                                         NULL)
        PHP_FE(stream_select,                                     
first_through_third_args_force_ref)
        PHP_FE(stream_context_create,                                                  
                                 NULL)
        PHP_FE(stream_context_set_params,                                              
                                 NULL)
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.324 php4/ext/standard/file.c:1.325
--- php4/ext/standard/file.c:1.324      Fri Mar  7 00:15:23 2003
+++ php4/ext/standard/file.c    Wed Mar 12 01:47:34 2003
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.324 2003/03/07 05:15:23 sniper Exp $ */
+/* $Id: file.c,v 1.325 2003/03/12 06:47:34 sterling Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -458,6 +458,34 @@
        
 }
 /* }}} */
+
+/* {{{ proto string file_set_contents(string file, string data)
+   Write/Create a file with contents data */
+PHP_FUNCTION(file_set_contents)
+{
+       php_stream *stream;
+       char *filename, *data;
+       size_t filename_len, data_len;
+       int numbytes;
+       zend_bool use_include_path = 0;
+       
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &filename, 
&filename_len, 
+                               &data, &data_len, &use_include_path) == FAILURE) {
+               return;
+       }
+
+       stream = php_stream_open_wrapper(filename, "wb", 
+                       (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | 
REPORT_ERRORS, NULL);
+       if (data_len) {
+               numbytes = php_stream_write(stream, data, data_len);
+               if (numbytes < 0) {
+                       RETURN_FALSE;
+               }
+       }
+       php_stream_close(stream);
+       
+       RETURN_TRUE;
+}
 
 /* {{{ proto array file(string filename [, int flags])
    Read entire file into an array */
Index: php4/ext/standard/file.h
diff -u php4/ext/standard/file.h:1.79 php4/ext/standard/file.h:1.80
--- php4/ext/standard/file.h:1.79       Fri Feb 28 14:53:20 2003
+++ php4/ext/standard/file.h    Wed Mar 12 01:47:34 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: file.h,v 1.79 2003/02/28 19:53:20 wez Exp $ */
+/* $Id: file.h,v 1.80 2003/03/12 06:47:34 sterling Exp $ */
 
 /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
 
@@ -54,6 +54,7 @@
 PHP_FUNCTION(copy);
 PHP_FUNCTION(file);
 PHP_FUNCTION(file_get_contents);
+PHP_FUNCTION(file_set_contents);
 PHP_FUNCTION(get_meta_tags);
 PHP_FUNCTION(flock);
 PHP_FUNCTION(fd_set);



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

Reply via email to