From: Derick Rethans Date: Mon, 13 Mar 2006 15:01:44 +0000 (+0000) Subject: This makes file_put_contents() work for: X-Git-Tag: RELEASE_1_3~445 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7bfe18307ef487b418871abeb713a3e6a0494e2;p=php This makes file_put_contents() work for: "latin1" ) ); file_put_contents( "/tmp/testuc.3", $a, FILE_TEXT, $context); file_put_contents( "/tmp/testuc.4", (string) $a, FILE_TEXT, $context); ?> But it still throws a warning on ".3". It's a small design issue that I didn't want to touch right now. --- diff --git a/ext/standard/file.c b/ext/standard/file.c index f3d9f5bf90..53c36f45d9 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -662,7 +662,7 @@ PHP_FUNCTION(file_put_contents) if (numchars < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to write %d characters to %s", ustrlen, filename); numchars = -1; - } else if (numchars != UBYTES(Z_USTRLEN_P(data))) { + } else if (numchars != ustrlen) { int numchars = u_countChar32(Z_USTRVAL_P(data), numchars); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only %d of %d characters written, possibly out of free disk space", numchars, ustrlen); diff --git a/main/streams/streams.c b/main/streams/streams.c index 1b3718b118..530326310d 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -1140,7 +1140,7 @@ static size_t _php_stream_write_buffer(php_stream *stream, int buf_type, zstr bu stream->ops->seek(stream, stream->position, SEEK_SET, &stream->position TSRMLS_CC); } - if (stream->output_encoding) { + if (stream->output_encoding && buf_type == IS_UNICODE) { char *dest; int destlen; UErrorCode status = U_ZERO_ERROR; @@ -1150,7 +1150,9 @@ static size_t _php_stream_write_buffer(php_stream *stream, int buf_type, zstr bu buflen = destlen; } else { /* Sloppy handling, make it a binary buffer */ - buflen = UBYTES(buflen); + if (buf_type != IS_STRING) { + buflen = UBYTES(buflen); + } } while (buflen > 0) {