]> granicus.if.org Git - php/commitdiff
This makes file_put_contents() work for:
authorDerick Rethans <derick@php.net>
Mon, 13 Mar 2006 15:01:44 +0000 (15:01 +0000)
committerDerick Rethans <derick@php.net>
Mon, 13 Mar 2006 15:01:44 +0000 (15:01 +0000)
<?php
    declare(encoding="latin1");
    $a = "1234å67890";
    file_put_contents( "/tmp/testuc.1", $a);
    file_put_contents( "/tmp/testuc.2", (string) $a);

    $context = stream_context_create();
    stream_context_set_params($context, array( "output_encoding" => "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.

ext/standard/file.c
main/streams/streams.c

index f3d9f5bf903b476f4e6e6b18215b3d7957b7c64a..53c36f45d94157f57bc9b05c26de93e11ccd2ec2 100644 (file)
@@ -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);
index 1b3718b1184210116a9f8897af5758cdad293901..530326310d12252270d069629bc28f318c70844d 100755 (executable)
@@ -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) {