pollita         Fri Sep 22 18:23:33 2006 UTC

  Modified files:              
    /php-src/ext/standard       file.c 
  Log:
  Tweak file_get_contents()'s return value a little
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.451&r2=1.452&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.451 php-src/ext/standard/file.c:1.452
--- php-src/ext/standard/file.c:1.451   Tue Sep 19 10:38:31 2006
+++ php-src/ext/standard/file.c Fri Sep 22 18:23:33 2006
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.451 2006/09/19 10:38:31 dmitry Exp $ */
+/* $Id: file.c,v 1.452 2006/09/22 18:23:33 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -512,7 +512,7 @@
        char *filename;
        int filename_len;
        zend_uchar filename_type;
-       void *contents;
+       void *contents = NULL;
        long flags = 0;
        php_stream *stream;
        int len;
@@ -552,21 +552,32 @@
        if (maxlen <= 0 || stream->readbuf_type == IS_STRING) {
                real_maxlen = maxlen;
        } else {
-               /* Allows worst case scenario of each input char being turned 
into two UChars */
-               real_maxlen = (maxlen * 2);
+               /* Allows worst case scenario of each input char being turned 
into two UChars
+                * UTODO: Have this take converter into account, since many 
never generate surrogate pairs */
+               real_maxlen = maxlen * 2;
        }
 
        /* uses mmap if possible */
        len = php_stream_copy_to_mem_ex(stream, stream->readbuf_type, 
&contents, real_maxlen, maxlen, 0);
 
-       if (stream->readbuf_type == IS_STRING && len > 0) {
-               RETVAL_STRINGL(contents, len, 0);
-       } else if (stream->readbuf_type == IS_UNICODE && len > 0) {
-               RETVAL_UNICODEL(contents, len, 0);
-       } else if (len == 0) {
-               RETVAL_EMPTY_STRING();
+       if (stream->readbuf_type == IS_STRING) {
+               if (len > 0) {
+                       RETVAL_STRINGL(contents, len, 0);
+               } else {
+                       if (contents) {
+                               efree(contents);
+                       }
+                       RETVAL_EMPTY_STRING();
+               }
        } else {
-               RETVAL_FALSE;
+               if (len > 0) {
+                       RETVAL_UNICODEL(contents, len, 0);
+               } else {
+                       if (contents) {
+                               efree(contents);
+                       }
+                       RETVAL_EMPTY_UNICODE();
+               }
        }
 
        php_stream_close(stream);

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

Reply via email to