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

2006-10-01 Thread Sara Golemon
pollita Mon Oct  2 02:24:29 2006 UTC

  Modified files:  
/php-src/main   php_streams.h 
/php-src/ext/standard   file.c 
  Log:
  Try out simplified API for encoding paths/filenames
  
http://cvs.php.net/viewvc.cgi/php-src/main/php_streams.h?r1=1.115r2=1.116diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.115 php-src/main/php_streams.h:1.116
--- php-src/main/php_streams.h:1.115Sun Sep 24 20:33:14 2006
+++ php-src/main/php_streams.h  Mon Oct  2 02:24:29 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.115 2006/09/24 20:33:14 pollita Exp $ */
+/* $Id: php_streams.h,v 1.116 2006/10/02 02:24:29 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -388,6 +388,61 @@
 END_EXTERN_C()
 
 
+#define php_stream_path_param_encode(ppzval, ppath, ppath_len, options, 
context) \
+   _php_stream_path_param_encode((ppzval), (ppath), (ppath_len), 
(options), (context) TSRMLS_CC)
+static inline int _php_stream_path_param_encode(zval **ppzval, char **ppath, 
int *ppath_len, int options, php_stream_context *context TSRMLS_DC)
+{
+   if (Z_TYPE_PP(ppzval) == IS_UNICODE) {
+   zval *zpath;
+   char *path;
+   int path_len;
+
+   /* Convert the path and put it into a fresh new zval */
+   if (FAILURE == php_stream_path_encode(NULL, path, path_len, 
Z_USTRVAL_PP(ppzval), Z_USTRLEN_PP(ppzval), options, context)) {
+   return FAILURE;
+   }
+   MAKE_STD_ZVAL(zpath);
+   ZVAL_STRINGL(zpath, path, path_len, 0);
+   zpath-is_ref = 0;
+   zpath-refcount = 1;
+
+   /* Replace the param stack with the new zval */
+   zval_ptr_dtor(ppzval);
+   *ppzval = zpath;
+   } else if (Z_TYPE_PP(ppzval) != IS_STRING) {
+   if ((*ppzval)-is_ref ||
+   (*ppzval)-refcount  1) {
+   zval *zpath;
+
+   /* Produce a new zval of type string */
+   MAKE_STD_ZVAL(zpath);
+   *zpath = **ppzval;
+   zval_copy_ctor(zpath);
+   convert_to_string(zpath);
+   zpath-is_ref = 0;
+   zpath-refcount = 1;
+
+   /* Replace the param stack with it */
+   zval_ptr_dtor(ppzval);
+   *ppzval = zpath;
+   } else {
+   /* Convert the value on the param stack directly */
+   convert_to_string(*ppzval);
+   }
+   }
+
+   /* Populate convenience params if requested */
+   if (ppath) {
+   *ppath = Z_STRVAL_PP(ppzval);
+   }
+   if (ppath_len) {
+   *ppath_len = Z_STRLEN_PP(ppzval);
+   }
+
+   return SUCCESS;
+}
+
+
 /* Flags for mkdir method in wrapper ops */
 #define PHP_STREAM_MKDIR_RECURSIVE 1
 /* define REPORT ERRORS 8 (below) */
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.457r2=1.458diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.457 php-src/ext/standard/file.c:1.458
--- php-src/ext/standard/file.c:1.457   Sun Sep 24 21:40:44 2006
+++ php-src/ext/standard/file.c Mon Oct  2 02:24:29 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.457 2006/09/24 21:40:44 pollita Exp $ */
+/* $Id: file.c,v 1.458 2006/10/02 02:24:29 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1016,30 +1016,25 @@
Open a file or a URL and return a file pointer */
 PHP_NAMED_FUNCTION(php_if_fopen)
 {
+   zval **ppfilename;
char *filename, *mode;
int filename_len, mode_len;
-   zend_uchar filename_type;
zend_bool use_include_path = 0;
zval *zcontext = NULL;
php_stream *stream;
php_stream_context *context = NULL;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ts|br, 
filename, filename_len, filename_type,
-   mode, mode_len, use_include_path, zcontext) 
== FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, Zs|br, 
ppfilename, mode, mode_len, use_include_path, zcontext) == FAILURE) {
RETURN_FALSE;
}
 
context = php_stream_context_from_zval(zcontext, 0);
 
-   if (filename_type == IS_UNICODE) {
-   if (php_stream_path_encode(NULL, filename, filename_len, 
(UChar*)filename, filename_len, REPORT_ERRORS, context) == FAILURE) {
-   RETURN_FALSE;
-   }
+   if (FAILURE == php_stream_path_param_encode(ppfilename, filename, 
filename_len, REPORT_ERRORS, context)) {
+   RETURN_FALSE;
}
+
stream = 

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

2006-09-24 Thread Sara Golemon
pollita Sun Sep 24 20:33:14 2006 UTC

  Modified files:  
/php-src/main   php_streams.h 
/php-src/main/streams   streams.c plain_wrapper.c 
/php-src/ext/standard   file.c 
  Log:
  PHP6 Updates for popen() and related functionality
  http://cvs.php.net/viewvc.cgi/php-src/main/php_streams.h?r1=1.114r2=1.115diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.114 php-src/main/php_streams.h:1.115
--- php-src/main/php_streams.h:1.114Fri Sep 22 19:54:30 2006
+++ php-src/main/php_streams.h  Sun Sep 24 20:33:14 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.114 2006/09/22 19:54:30 pollita Exp $ */
+/* $Id: php_streams.h,v 1.115 2006/09/24 20:33:14 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -561,6 +561,7 @@
 PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
 PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, 
php_stream_wrapper *wrapper TSRMLS_DC);
 PHPAPI int php_unregister_url_stream_wrapper_volatile(char *protocol 
TSRMLS_DC);
+PHPAPI void php_stream_fix_encoding(php_stream *stream, const char *mode, 
php_stream_context *context TSRMLS_DC);
 PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int 
options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
 PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, 
char **path_for_open, int options TSRMLS_DC);
 PHPAPI void *php_stream_locate_eol(php_stream *stream, zstr zbuf, int buf_len 
TSRMLS_DC);
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.136r2=1.137diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.136 
php-src/main/streams/streams.c:1.137
--- php-src/main/streams/streams.c:1.136Fri Sep 22 19:54:30 2006
+++ php-src/main/streams/streams.c  Sun Sep 24 20:33:14 2006
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.136 2006/09/22 19:54:30 pollita Exp $ */
+/* $Id: streams.c,v 1.137 2006/09/24 20:33:14 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -2285,6 +2285,32 @@
 }
 /* }}} */
 
+/* {{{ php_stream_fix_encoding
+ * Sets read/write encoding on a stream based on the fopen mode, context 
options, and INI setting */
+PHPAPI void php_stream_fix_encoding(php_stream *stream, const char *mode, 
php_stream_context *context TSRMLS_DC)
+{
+   /* Output encoding on text mode streams defaults to utf8 unless 
specified in context parameter */
+   if (stream  strchr(mode, 't')  UG(unicode)) {
+   /* Only apply implicit unicode.to. filter if the wrapper didn't 
do it for us */
+   if ((php_stream_filter_product(stream-writefilters, 
IS_UNICODE) == IS_UNICODE)  
+   (strchr(mode, 'w') || strchr(mode, 'a') || strchr(mode, 
'+'))) {
+   char *encoding = (context  context-output_encoding) 
? context-output_encoding : UG(stream_encoding);
+
+   /* UTODO: (Maybe?) Allow overriding the default error 
handlers on a per-stream basis via context params */
+   php_stream_encoding_apply(stream, 1, encoding, 
UG(from_error_mode), UG(from_subst_char));
+   }
+
+   /* Only apply implicit unicode.from. filter if the wrapper 
didn't do it for us */
+   if ((stream-readbuf_type == IS_STRING)  (strchr(mode, 'r') 
|| strchr(mode, '+'))) {
+   char *encoding = (context  context-input_encoding) ? 
context-input_encoding : UG(stream_encoding);
+
+   /* UTODO: (Maybe?) Allow overriding the default error 
handlers on a per-stream basis via context params */
+   php_stream_encoding_apply(stream, 0, encoding, 
UG(to_error_mode), NULL);
+   }
+   }
+}
+/* }}} */
+
 /* {{{ php_stream_open_wrapper_ex */
 PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int 
options,
char **opened_path, php_stream_context *context STREAMS_DC 
TSRMLS_DC)
@@ -2387,25 +2413,8 @@
}
}
 
-   /* Output encoding on text mode streams defaults to utf8 unless 
specified in context parameter */
-   if (stream  strchr(implicit_mode, 't')  UG(unicode)) {
-   /* Only apply implicit unicode.to. filter if the wrapper didn't 
do it for us */
-   if ((php_stream_filter_product(stream-writefilters, 
IS_UNICODE) == IS_UNICODE)  
-   (strchr(implicit_mode, 'w') || strchr(implicit_mode, 
'a') || strchr(implicit_mode, '+'))) {
-   char *encoding = (context  context-output_encoding) 
? context-output_encoding : UG(stream_encoding);
 
-   /* UTODO: (Maybe?) Allow overriding the default error 
handlers on a per-stream basis via 

[PHP-CVS] cvs: php-src /ext/standard file.c /main php_streams.h /main/streams streams.c ZendEngine2 zend.c zend_globals.h

2006-03-31 Thread Sara Golemon
pollita Fri Mar 31 22:51:37 2006 UTC

  Modified files:  
/ZendEngine2zend.c zend_globals.h 
/php-src/ext/standard   file.c 
/php-src/main   php_streams.h 
/php-src/main/streams   streams.c 
  Log:
  Add API hooks and unicode.filesystem_encoding for handling unicode
  conversions of filename entries.
  
  Normal path conversions will simply use this converter,
  Certain other protocols (such as http) which specify a
  required character set (utf8), may override the conversion
  by defining a path_encode() and/or path_decode() wrapper ops method.
  
  http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend.c?r1=1.349r2=1.350diff_format=u
Index: ZendEngine2/zend.c
diff -u ZendEngine2/zend.c:1.349 ZendEngine2/zend.c:1.350
--- ZendEngine2/zend.c:1.349Thu Mar 30 21:39:15 2006
+++ ZendEngine2/zend.c  Fri Mar 31 22:51:37 2006
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: zend.c,v 1.349 2006/03/30 21:39:15 tony2001 Exp $ */
+/* $Id: zend.c,v 1.350 2006/03/31 22:51:37 pollita Exp $ */
 
 #include zend.h
 #include zend_extensions.h
@@ -179,6 +179,7 @@
STD_ZEND_INI_ENTRY(unicode.runtime_encoding,  NULL, ZEND_INI_ALL, 
OnUpdateEncoding,   runtime_encoding_conv, zend_unicode_globals, 
unicode_globals)
STD_ZEND_INI_ENTRY(unicode.script_encoding,  NULL, ZEND_INI_ALL, 
OnUpdateEncoding,   script_encoding_conv, zend_unicode_globals, unicode_globals)
STD_ZEND_INI_ENTRY(unicode.http_input_encoding,  NULL, ZEND_INI_ALL, 
OnUpdateEncoding,   http_input_encoding_conv, zend_unicode_globals, 
unicode_globals)
+   STD_ZEND_INI_ENTRY(unicode.filesystem_encoding,  NULL, ZEND_INI_ALL, 
OnUpdateEncoding,   filesystem_encoding_conv, zend_unicode_globals, 
unicode_globals)
 ZEND_INI_END()
 
 
http://cvs.php.net/viewcvs.cgi/ZendEngine2/zend_globals.h?r1=1.154r2=1.155diff_format=u
Index: ZendEngine2/zend_globals.h
diff -u ZendEngine2/zend_globals.h:1.154 ZendEngine2/zend_globals.h:1.155
--- ZendEngine2/zend_globals.h:1.154Sun Mar 26 06:19:24 2006
+++ ZendEngine2/zend_globals.h  Fri Mar 31 22:51:37 2006
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: zend_globals.h,v 1.154 2006/03/26 06:19:24 andrei Exp $ */
+/* $Id: zend_globals.h,v 1.155 2006/03/31 22:51:37 pollita Exp $ */
 
 #ifndef ZEND_GLOBALS_H
 #define ZEND_GLOBALS_H
@@ -299,6 +299,7 @@
UConverter *output_encoding_conv;/* output layer converter */
UConverter *script_encoding_conv;/* default script encoding 
converter */
UConverter *http_input_encoding_conv;/* http input encoding converter */
+   UConverter *filesystem_encoding_conv;/* default filesystem converter 
(entries, not contents) */ 
UConverter *utf8_conv;   /* all-purpose UTF-8 
converter */
 
uint16_t from_error_mode;
http://cvs.php.net/viewcvs.cgi/php-src/ext/standard/file.c?r1=1.433r2=1.434diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.433 php-src/ext/standard/file.c:1.434
--- php-src/ext/standard/file.c:1.433   Thu Mar 30 00:22:51 2006
+++ php-src/ext/standard/file.c Fri Mar 31 22:51:37 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.433 2006/03/30 00:22:51 pollita Exp $ */
+/* $Id: file.c,v 1.434 2006/03/31 22:51:37 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -866,25 +866,34 @@
 }
 /* }}} */
 
-/* {{{ proto resource fopen(string filename, string mode [, bool 
use_include_path [, resource context]])
+/* {{{ proto resource fopen(string filename, string mode [, bool 
use_include_path [, resource context]]) U
Open a file or a URL and return a file pointer */
 PHP_NAMED_FUNCTION(php_if_fopen)
 {
char *filename, *mode;
int filename_len, mode_len;
+   zend_uchar filename_type;
zend_bool use_include_path = 0;
zval *zcontext = NULL;
php_stream *stream;
php_stream_context *context = NULL;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ss|br, 
filename, filename_len,
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ts|br, 
filename, filename_len, filename_type,
mode, mode_len, use_include_path, zcontext) 
== FAILURE) {
RETURN_FALSE;
}
 
context = php_stream_context_from_zval(zcontext, 0);
-   
+
+   if (filename_type == IS_UNICODE) {
+   if (php_stream_path_encode(NULL, filename, filename_len, 
filename, filename_len, REPORT_ERRORS, context) == FAILURE) {
+   RETURN_FALSE;
+   }
+   }
stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? 
USE_PATH : 0) | REPORT_ERRORS, NULL, context);
+   if (filename_type == IS_UNICODE) {
+   efree(filename);
+   

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

2006-03-29 Thread Sara Golemon
pollita Thu Mar 30 00:22:51 2006 UTC

  Modified files:  
/php-src/ext/standard   file.c 
/php-src/main   php_streams.h 
/php-src/main/streams   streams.c 
  Log:
  Make php_stream_copy_to_mem() unicode aware and
  update userspace function file_get_contents().
  
  Note: fgc()'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 fgc() to return 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.432r2=1.433diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.432 php-src/ext/standard/file.c:1.433
--- php-src/ext/standard/file.c:1.432   Wed Mar 29 22:52:24 2006
+++ php-src/ext/standard/file.c Thu Mar 30 00:22:51 2006
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.432 2006/03/29 22:52:24 pollita Exp $ */
+/* $Id: file.c,v 1.433 2006/03/30 00:22:51 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -497,32 +497,32 @@
 
 /* }}} */
 
-/* {{{ proto string file_get_contents(string filename [, bool use_include_path 
[, resource context [, long offset [, long maxlen)
+/* {{{ proto string file_get_contents(string filename [, long flags [, 
resource context [, long offset [, long maxlen) U
Read the entire file into a string */
-/* UTODO: Accept unicode contents -- Maybe? Perhaps a binary fetch leaving the 
script to icu_ucnv_toUnicode() on its own is best? */
 PHP_FUNCTION(file_get_contents)
 {
char *filename;
int filename_len;
char *contents;
+   long flags = 0;
zend_bool use_include_path = 0;
php_stream *stream;
int len;
long offset = -1;
-   long maxlen = PHP_STREAM_COPY_ALL;
+   long maxlen = PHP_STREAM_COPY_ALL, real_maxlen;
zval *zcontext = NULL;
php_stream_context *context = NULL;
 
/* Parse arguments */
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|br!ll,
- filename, filename_len, use_include_path, 
zcontext, offset, maxlen) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lr!ll,
+ filename, filename_len, flags, zcontext, 
offset, maxlen) == FAILURE) {
return;
}
 
context = php_stream_context_from_zval(zcontext, 0);
 
-   stream = php_stream_open_wrapper_ex(filename, rb, 
-   (use_include_path ? USE_PATH : 0) | 
REPORT_ERRORS,
+   stream = php_stream_open_wrapper_ex(filename, (flags  PHP_FILE_TEXT) ? 
rt : rb, 
+   ((flags  PHP_FILE_USE_INCLUDE_PATH) ? USE_PATH 
: 0) | REPORT_ERRORS,
NULL, context);
if (!stream) {
RETURN_FALSE;
@@ -533,9 +533,20 @@
RETURN_FALSE;
}
 
+   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);
+   }
+
/* uses mmap if possible */
-   if ((len = php_stream_copy_to_mem(stream, contents, maxlen, 0))  0) {
+   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();
} else {
http://cvs.php.net/viewcvs.cgi/php-src/main/php_streams.h?r1=1.109r2=1.110diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.109 php-src/main/php_streams.h:1.110
--- php-src/main/php_streams.h:1.109Wed Mar 29 01:20:43 2006
+++ php-src/main/php_streams.h  Thu Mar 30 00:22:51 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.109 2006/03/29 01:20:43 pollita Exp $ */
+/* $Id: php_streams.h,v 1.110 2006/03/30 00:22:51 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -284,6 +284,7 @@
 /* Convert using runtime_encoding if necessary -- return unicode */
 PHPAPI size_t _php_stream_read_unicode(php_stream *stream, UChar *buf, int 
maxlen, int maxchars TSRMLS_DC);
 #define php_stream_read_unicode(stream, buf, maxlen)   
_php_stream_read_unicode((stream), 

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

2006-03-14 Thread Sara Golemon
pollita Tue Mar 14 21:15:05 2006 UTC

  Modified files:  
/php-src/main   php_streams.h 
/php-src/main/streams   streams.c 
/php-src/ext/standard   file.c 
  Log:
  More stream updates.
  fgets() will work now as will anything which calls one of the
  _php_stream_get_line() family of functions.
  The one exception here is when the legacy defines are used on a unicode
  stream.  At the moment they'll simply return NULL, I'll update these
  to do sloppy conversion in a bit.
  
  'make (u)test' still doesn't work, but it's a different doesn't work. 
  
  http://cvs.php.net/viewcvs.cgi/php-src/main/php_streams.h?r1=1.106r2=1.107diff_format=u
Index: php-src/main/php_streams.h
diff -u php-src/main/php_streams.h:1.106 php-src/main/php_streams.h:1.107
--- php-src/main/php_streams.h:1.106Mon Mar 13 04:40:11 2006
+++ php-src/main/php_streams.h  Tue Mar 14 21:15:05 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.106 2006/03/13 04:40:11 pollita Exp $ */
+/* $Id: php_streams.h,v 1.107 2006/03/14 21:15:05 pollita Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -320,10 +320,14 @@
 PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC);
 #define php_stream_flush(stream)   _php_stream_flush((stream), 0 TSRMLS_CC)
 
-PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t 
maxlen, size_t *returned_len TSRMLS_DC);
-#define php_stream_gets(stream, buf, maxlen)   _php_stream_get_line((stream), 
(buf), (maxlen), NULL TSRMLS_CC)
+PHPAPI void *_php_stream_get_line(php_stream *stream, int buf_type, zstr buf, 
size_t maxlen, size_t maxchars, size_t *returned_len TSRMLS_DC);
+#define php_stream_get_line(stream, buf, maxlen, retlen)   
_php_stream_get_line((stream), IS_STRING, ZSTR(buf), (maxlen), 0, (retlen) 
TSRMLS_CC)
+#define php_stream_get_line_ex(stream, buf_type, buf, maxlen, maxchars, 
retlen) \
+   
_php_stream_get_line((stream), 
(buf_type), ZSTR(buf), (maxlen), (maxchars), (retlen) TSRMLS_CC)
+#define php_stream_gets(stream, buf, maxlen)   
_php_stream_get_line((stream), IS_STRING, ZSTR(buf), (maxlen), 0, NULL 
TSRMLS_CC)
+#define php_stream_gets_ex(stream, buf_type, buf, maxlen, maxchars) \
+   
_php_stream_get_line((stream), 
(buf_type), ZSTR(buf), (maxlen), (maxchars), NULL TSRMLS_CC)
 
-#define php_stream_get_line(stream, buf, maxlen, retlen) 
_php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
 PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t 
*returned_len, char *delim, size_t delim_len TSRMLS_DC);
 
 PHPAPI UChar *_php_stream_u_get_line(php_stream *stream, UChar *buf, int32_t 
*pmax_bytes, int32_t *pmax_chars, int *pis_unicode TSRMLS_DC);
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/streams.c?r1=1.101r2=1.102diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.101 
php-src/main/streams/streams.c:1.102
--- php-src/main/streams/streams.c:1.101Mon Mar 13 20:54:06 2006
+++ php-src/main/streams/streams.c  Tue Mar 14 21:15:05 2006
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.101 2006/03/13 20:54:06 pollita Exp $ */
+/* $Id: streams.c,v 1.102 2006/03/14 21:15:05 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -955,18 +955,25 @@
 
 /* If buf == NULL, the buffer will be allocated automatically and will be of an
  * appropriate length to hold the line, regardless of the line length, memory
- * permitting -- returned string will be up to (maxlen-1), last byte holding 
terminating NULL
- * Like php_stream_read(), this will treat unicode streams as ugly binary data 
(use with caution) */
-PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
-   size_t *returned_len TSRMLS_DC)
+ * permitting -- returned string will be up to (maxlen-1) units of (maxchars) 
characters, last byte holding terminating NULL
+ * Like php_stream_read(), this will (UTODO) treat unicode streams as ugly 
binary data (use with caution) */
+PHPAPI void *_php_stream_get_line(php_stream *stream, int buf_type, zstr buf, 
size_t maxlen, size_t maxchars, size_t *returned_len TSRMLS_DC)
 {
size_t avail = 0;
size_t current_buf_size = 0;
size_t total_copied = 0;
int grow_mode = 0;
-   char *bufstart = buf;
+   int is_unicode = php_stream_reads_unicode(stream);
+   int split_surrogate = 0;
+   zstr bufstart = buf;
+
+   if ((buf_type == IS_STRING  is_unicode) ||
+   (buf_type == IS_UNICODE  !is_unicode)) {
+   /* UTODO: Allow