]> granicus.if.org Git - php/commitdiff
Add convenience function for openeing files with unicode names
authorSara Golemon <pollita@php.net>
Wed, 10 Jan 2007 22:43:17 +0000 (22:43 +0000)
committerSara Golemon <pollita@php.net>
Wed, 10 Jan 2007 22:43:17 +0000 (22:43 +0000)
main/php_streams.h
main/streams/streams.c

index fd08e8902eac04dd316ce917714016ee7c90bbe3..8bd694561d0146e8ea84ddb5c47f768824d984ec 100755 (executable)
@@ -618,12 +618,18 @@ PHPAPI int php_register_url_stream_wrapper_volatile(char *protocol, php_stream_w
 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 *_php_stream_u_open_wrapper(zend_uchar type,  zstr path, int path_len, char *mode, int options, zstr *opened_path, int *opened_path_len, 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);
 
 #define php_stream_open_wrapper(path, mode, options, opened)   _php_stream_open_wrapper_ex((path), (mode), (options), (opened), NULL STREAMS_CC TSRMLS_CC)
 #define php_stream_open_wrapper_ex(path, mode, options, opened, context)       _php_stream_open_wrapper_ex((path), (mode), (options), (opened), (context) STREAMS_CC TSRMLS_CC)
 
+#define php_stream_u_open_wrapper(type, path, path_len, mode, options, opened, context)        \
+       _php_stream_u_open_wrapper((type), (path), (path_len), (mode), (options), (opened), NULL, (context) STREAMS_CC TSRMLS_CC)
+#define php_stream_u_open_wrapper_ex(type, path, path_len, mode, options, opened, opened_len, context) \
+       _php_stream_u_open_wrapper((type), (path), (path_len), (mode), (options), (opened), (opened_len), (context) STREAMS_CC TSRMLS_CC)
+
 #define php_stream_get_from_zval(stream, zstream, mode, options, opened, context) \
                if (Z_TYPE_PP((zstream)) == IS_RESOURCE) { \
                        php_stream_from_zval((stream), (zstream)); \
index 2837ec864174cdc018b391f50e9f4a9f6e3bac15..ddddd29f7f9ffccf475f8e42f2f3cb879aeecd40 100755 (executable)
@@ -2434,6 +2434,61 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int optio
 }
 /* }}} */
 
+/* {{{ _php_stream_u_open_wrapper */
+PHPAPI php_stream *_php_stream_u_open_wrapper(zend_uchar type, zstr path, int path_len,
+                       char *mode, int options, zstr *opened_path, int *opened_path_len,
+                       php_stream_context *context STREAMS_DC TSRMLS_DC)
+{
+       php_stream *stream;
+       char *filename = NULL;
+       int filename_len;
+
+       if (opened_path) {
+               opened_path->v = NULL;
+       }
+       if (opened_path_len) {
+               *opened_path_len = 0;
+       }
+
+       if (type == IS_STRING) {
+               stream = php_stream_open_wrapper_ex(path.s, mode, options, (char**)opened_path, context);
+
+               if (opened_path_len && opened_path && opened_path->s) {
+                       *opened_path_len = strlen(opened_path->s);
+               }
+
+               return stream;
+       }
+
+       /* type == IS_UNICODE */
+       if (FAILURE == php_stream_path_encode(NULL, &filename, &filename_len, path.u, path_len, options, context)) {
+               return NULL;
+       }
+
+       stream = php_stream_open_wrapper_ex(filename, mode, options, (char**)opened_path, context);
+       efree(filename);
+
+       if (opened_path && opened_path->s) {
+               UChar *upath;
+               int upath_len;
+
+               if (SUCCESS == php_stream_path_decode(NULL, &upath, &upath_len, opened_path->s, strlen(opened_path->s), options, context)) {
+                       efree(opened_path->s);
+                       opened_path->u = upath;
+                       if (opened_path_len) {
+                               *opened_path_len = upath_len;
+                       }
+               } else {
+                       /* Shouldn't happen */
+                       efree(opened_path->s);
+                       opened_path->s = NULL;
+               }
+       }
+
+       return stream;
+}
+/* }}} */
+
 /* {{{ context API */
 PHPAPI php_stream_context *php_stream_context_set(php_stream *stream, php_stream_context *context)
 {