summaryrefslogtreecommitdiff
path: root/ext/standard/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r--ext/standard/file.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index e10295496..8ff709c58 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2007 The PHP Group |
+ | Copyright (c) 1997-2008 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.409.2.6.2.28 2007/09/04 12:51:49 iliaa Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.31 2007/12/31 07:20:12 sebastian Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -592,6 +592,7 @@ PHP_FUNCTION(file_put_contents)
zval *zcontext = NULL;
php_stream_context *context = NULL;
php_stream *srcstream = NULL;
+ char mode[3] = "wb";
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|lr!", &filename, &filename_len,
&data, &flags, &zcontext) == FAILURE) {
@@ -604,8 +605,14 @@ PHP_FUNCTION(file_put_contents)
context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);
- stream = php_stream_open_wrapper_ex(filename, (flags & PHP_FILE_APPEND) ? "ab" : "wb",
- ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
+ if (flags & PHP_FILE_APPEND) {
+ mode[0] = 'a';
+ } else if (flags & LOCK_EX) {
+ mode[0] = 'c';
+ }
+ mode[2] = '\0';
+
+ stream = php_stream_open_wrapper_ex(filename, mode, ((flags & PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
if (stream == NULL) {
RETURN_FALSE;
}
@@ -615,6 +622,10 @@ PHP_FUNCTION(file_put_contents)
RETURN_FALSE;
}
+ if (mode[0] == 'c') {
+ php_stream_truncate_set_size(stream, 0);
+ }
+
switch (Z_TYPE_P(data)) {
case IS_RESOURCE:
numbytes = php_stream_copy_to_stream(srcstream, stream, PHP_STREAM_COPY_ALL);