[PHP-CVS] cvs: php-src /ext/standard file.c /main/streams streams.c

2006-03-29 Thread Sara Golemon
pollita Wed Mar 29 22:52:24 2006 UTC

  Modified files:  
/php-src/ext/standard   file.c 
/php-src/main/streams   streams.c 
  Log:
  Update php_stream_passthru() to handle unicode data.
  This updates userspace functions fpassthru() and readfile()
  
  UG(output_encoding) is used by php_stream_passthru() to translate
  unicode stream contents back to an outputable character set.
  
  Note: readfile()'s second parameter (use_include_path) has been changed
  to be a bitmask flags parameter instead.
  
  For the most commonly used values (TRUE, 1) this will continue functioning
  as expected since the value of FILE_USE_INCLUDE_PATH is (coincidentally) 1.
  The impact to other values should be noted in the migration6 guide.
  
  This change makes it possible to allow readfile() to output binary file
  contents (default) or unicode transcoded contents (using FILE_TEXT flag).
  
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.431r2=1.432diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.431 php-src/ext/standard/file.c:1.432
--- php-src/ext/standard/file.c:1.431   Wed Mar 29 01:20:42 2006
+++ php-src/ext/standard/file.c Wed Mar 29 22:52:24 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.431 2006/03/29 01:20:42 pollita Exp $ */
+/* $Id: file.c,v 1.432 2006/03/29 22:52:24 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -547,7 +547,7 @@
 }
 /* }}} */
 
-/* {{{ proto int file_put_contents(string file, mixed data [, int flags [, 
resource context]])
+/* {{{ proto int file_put_contents(string file, mixed data [, int flags [, 
resource context]]) U
Write/Create a file with contents data and return the number of bytes 
written */
 PHP_FUNCTION(file_put_contents)
 {
@@ -991,7 +991,7 @@
 }
 /* }}} */
 
-/* {{{ proto string fgets(resource fp[, int length])
+/* {{{ proto string fgets(resource fp[, int length]) U
Get a line from file pointer */
 PHPAPI PHP_FUNCTION(fgets)
 {
@@ -1021,7 +1021,7 @@
 }
 /* }}} */
 
-/* {{{ proto string fgetc(resource fp)
+/* {{{ proto string fgetc(resource fp) U
Get a character from file pointer */
 PHPAPI PHP_FUNCTION(fgetc)
 {
@@ -1052,7 +1052,7 @@
 }
 /* }}} */
 
-/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags])
+/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags]) U
Get a line from file pointer and strip HTML tags */
 PHPAPI PHP_FUNCTION(fgetss)
 {
@@ -1168,7 +1168,7 @@
 }
 /* }}} */
 
-/* {{{ proto int fwrite(resource fp, string str [, int length])
+/* {{{ proto int fwrite(resource fp, string str [, int length]) U
Binary-safe file write */
 PHPAPI PHP_FUNCTION(fwrite)
 {
@@ -1371,26 +1371,30 @@
 }
 /* }}} */
 
-/* {{{ proto int readfile(string filename [, bool use_include_path[, resource 
context]])
+/* {{{ proto int readfile(string filename [, int flags[, resource context]]) U
Output a file or a URL */
-/* UTODO: Accept unicode contents */
 PHP_FUNCTION(readfile)
 {
char *filename;
int size = 0;
int filename_len;
-   zend_bool use_include_path = 0;
+   long flags = 0;
zval *zcontext = NULL;
php_stream *stream;
php_stream_context *context = NULL;
+   char *mode = rb;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|br!, 
filename, filename_len, use_include_path, zcontext) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lr!, 
filename, filename_len, flags, zcontext) == FAILURE) {
RETURN_FALSE;
}
 
context = php_stream_context_from_zval(zcontext, 0);
 
-   stream = php_stream_open_wrapper_ex(filename, rb, (use_include_path ? 
USE_PATH : 0) | REPORT_ERRORS, NULL, context);
+   if (flags  PHP_FILE_TEXT) {
+   mode = rt;
+   }
+
+   stream = php_stream_open_wrapper_ex(filename, mode, ((flags  
PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH : 0) | REPORT_ERRORS, NULL, context);
if (stream) {
size = php_stream_passthru(stream);
php_stream_close(stream);
@@ -1429,9 +1433,8 @@
 
 /* }}} */
 
-/* {{{ proto int fpassthru(resource fp)
+/* {{{ proto int fpassthru(resource fp) U
Output all remaining data from a file pointer */
-/* UTODO: Accept unicode contents */
 PHPAPI PHP_FUNCTION(fpassthru)
 {
zval **arg1;
@@ -1733,7 +1736,7 @@
 }
 /* }}} */
 
-/* {{{ proto string fread(resource fp, int length)
+/* {{{ proto string fread(resource fp, int length) U
Binary-safe file read */
 PHPAPI PHP_FUNCTION(fread)
 {
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/streams.c?r1=1.115r2=1.116diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.115 
php-src/main/streams/streams.c:1.116
--- php-src/main/streams/streams.c:1.115Wed Mar 29 01:20:43 2006
+++ 

[PHP-CVS] cvs: php-src /ext/standard file.c /main/streams streams.c

2006-03-14 Thread Sara Golemon
pollita Wed Mar 15 00:28:57 2006 UTC

  Modified files:  
/php-src/ext/standard   file.c 
/php-src/main/streams   streams.c 
  Log:
  Switch (zstr) casts to use ZSTR() macro.
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.426r2=1.427diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.426 php-src/ext/standard/file.c:1.427
--- php-src/ext/standard/file.c:1.426   Tue Mar 14 21:15:05 2006
+++ php-src/ext/standard/file.c Wed Mar 15 00:28:57 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.426 2006/03/14 21:15:05 pollita Exp $ */
+/* $Id: file.c,v 1.427 2006/03/15 00:28:57 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -749,7 +749,7 @@
s = target_buf;
e = target_buf + target_len;

-   if (!(p = php_stream_locate_eol(stream, (zstr)target_buf, 
target_len TSRMLS_CC))) {
+   if (!(p = php_stream_locate_eol(stream, ZSTR(target_buf), 
target_len TSRMLS_CC))) {
p = e;
goto parse_eol;
}
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/streams.c?r1=1.102r2=1.103diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.102 
php-src/main/streams/streams.c:1.103
--- php-src/main/streams/streams.c:1.102Tue Mar 14 21:15:05 2006
+++ php-src/main/streams/streams.c  Wed Mar 15 00:28:57 2006
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.102 2006/03/14 21:15:05 pollita Exp $ */
+/* $Id: streams.c,v 1.103 2006/03/15 00:28:57 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1335,7 +1335,7 @@
int ret = 0;
 
if (stream-writefilters.head) {
-   _php_stream_write_filtered(stream, IS_STRING, (zstr)NULL, 0, 
closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC  TSRMLS_CC);
+   _php_stream_write_filtered(stream, IS_STRING, ZSTR(NULL), 0, 
closing ? PSFS_FLAG_FLUSH_CLOSE : PSFS_FLAG_FLUSH_INC  TSRMLS_CC);
}
 
if (stream-ops-flush) {
@@ -1352,9 +1352,9 @@
}
 
if (stream-writefilters.head) {
-   return _php_stream_write_filtered(stream, IS_STRING, 
(zstr)((char*)buf), count, PSFS_FLAG_NORMAL TSRMLS_CC);
+   return _php_stream_write_filtered(stream, IS_STRING, 
ZSTR((void*)buf), count, PSFS_FLAG_NORMAL TSRMLS_CC);
} else {
-   return _php_stream_write_buffer(stream, IS_STRING, 
(zstr)((char*)buf), count TSRMLS_CC);
+   return _php_stream_write_buffer(stream, IS_STRING, 
ZSTR((void*)buf), count TSRMLS_CC);
}
 }
 
@@ -1367,9 +1367,9 @@
}
 
if (stream-writefilters.head) {
-   ret = _php_stream_write_filtered(stream, IS_UNICODE, 
(zstr)((UChar*)buf), count, PSFS_FLAG_NORMAL TSRMLS_CC);
+   ret = _php_stream_write_filtered(stream, IS_UNICODE, 
ZSTR((void*)buf), count, PSFS_FLAG_NORMAL TSRMLS_CC);
} else {
-   ret = _php_stream_write_buffer(stream, IS_UNICODE, 
(zstr)((UChar*)buf), count TSRMLS_CC);
+   ret = _php_stream_write_buffer(stream, IS_UNICODE, 
ZSTR((void*)buf), count TSRMLS_CC);
}
 
return ret;

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



[PHP-CVS] cvs: php-src /ext/standard file.c /main/streams streams.c

2006-03-13 Thread Derick Rethans
derick  Mon Mar 13 15:01:44 2006 UTC

  Modified files:  
/php-src/main/streams   streams.c 
/php-src/ext/standard   file.c 
  Log:
  This makes file_put_contents() work for:
  
  ?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. 
  
  
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/streams.c?r1=1.99r2=1.100diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.99 php-src/main/streams/streams.c:1.100
--- php-src/main/streams/streams.c:1.99 Mon Mar 13 04:40:11 2006
+++ php-src/main/streams/streams.c  Mon Mar 13 15:01:44 2006
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.99 2006/03/13 04:40:11 pollita Exp $ */
+/* $Id: streams.c,v 1.100 2006/03/13 15:01:44 derick Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1140,7 +1140,7 @@
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 @@
buflen = destlen;
} else {
/* Sloppy handling, make it a binary buffer */
-   buflen = UBYTES(buflen);
+   if (buf_type != IS_STRING) {
+   buflen = UBYTES(buflen);
+   }
}
 
while (buflen  0) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.424r2=1.425diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.424 php-src/ext/standard/file.c:1.425
--- php-src/ext/standard/file.c:1.424   Mon Mar 13 04:40:11 2006
+++ php-src/ext/standard/file.c Mon Mar 13 15:01:44 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.424 2006/03/13 04:40:11 pollita Exp $ */
+/* $Id: file.c,v 1.425 2006/03/13 15:01:44 derick Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -662,7 +662,7 @@
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);

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