cvs: php-src(PHP_5_3) /ext/standard file.c /main/streams plain_wrapper.c
| From: | Ilia Alshanetsky | Date: | Mon, 12 Nov 2007 18:44:18 +0000 |
| Subject: | cvs: php-src(PHP_5_3) /ext/standard file.c /main/streams plain_wrapper.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-47122@lists.php.net to get a copy of this message | ||
iliaa Mon Nov 12 18:44:18 2007 UTC
Modified files: (Branch: PHP_5_3)
/php-src/main/streams plain_wrapper.c
/php-src/ext/standard file.c
Log:
Fixed bug #43182 (file_put_contents() LOCK_EX does not work properly on file
truncation).
http://cvs.php.net/viewvc.cgi/php-src/main/streams/plain_wrapper.c?r1=1.52.2.6.2.23.2.3&r2=1.52.2.6.2.23.2.4&diff_format=u
Index: php-src/main/streams/plain_wrapper.c
diff -u php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.3
php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.4
--- php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.3 Tue Nov 6 12:12:58 2007
+++ php-src/main/streams/plain_wrapper.c Mon Nov 12 18:44:18 2007
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.3 2007/11/06 12:12:58 helly Exp $ */
+/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.4 2007/11/12 18:44:18 iliaa Exp $ */
#include "php.h"
#include "php_globals.h"
@@ -63,6 +63,9 @@
case 'x':
flags = O_CREAT|O_EXCL;
break;
+ case 'c':
+ flags = O_CREAT;
+ break;
default:
/* unknown mode */
return FAILURE;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.28.2.4&r2=1.409.2.6.2.28.2.5&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.28.2.4
php-src/ext/standard/file.c:1.409.2.6.2.28.2.5
--- php-src/ext/standard/file.c:1.409.2.6.2.28.2.4 Fri Nov 9 11:08:22 2007
+++ php-src/ext/standard/file.c Mon Nov 12 18:44:18 2007
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.409.2.6.2.28.2.4 2007/11/09 11:08:22 dmitry Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.28.2.5 2007/11/12 18:44:18 iliaa Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -581,6 +581,7 @@
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) {
return;
@@ -592,8 +593,14 @@
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;
}
@@ -603,6 +610,10 @@
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);