From: Sara Golemon Date: Wed, 10 Jan 2007 22:43:17 +0000 (+0000) Subject: Add convenience function for openeing files with unicode names X-Git-Tag: RELEASE_1_0_0RC1~314 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53333166fc5b510d7134d9bff4cf05700f53b8ea;p=php Add convenience function for openeing files with unicode names --- diff --git a/main/php_streams.h b/main/php_streams.h index fd08e8902e..8bd694561d 100755 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -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)); \ diff --git a/main/streams/streams.c b/main/streams/streams.c index 2837ec8641..ddddd29f7f 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -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) {