]> granicus.if.org Git - php/commitdiff
Changed stream_resolve_include_path to use zend_resolve_path
authorMikko Koppanen <mkoppanen@php.net>
Thu, 24 Dec 2009 13:12:03 +0000 (13:12 +0000)
committerMikko Koppanen <mkoppanen@php.net>
Thu, 24 Dec 2009 13:12:03 +0000 (13:12 +0000)
backported stream_resolve_include_path to PHP 5.3
backported stream_resolve_include_path test to PHP 5.3

ext/standard/streamsfuncs.c

index c12fb4afb78f147fa62a66f699a2b31a2c2f665b..d90e0881cefcc5d45f85500398644d212a08fa27 100644 (file)
@@ -1668,63 +1668,32 @@ PHP_FUNCTION(stream_encoding)
 }
 /* }}} */
 
-/* {{{ proto string stream_resolve_include_path(string filename[, resource context]) U
+/* {{{ proto string stream_resolve_include_path(string filename) U
 Determine what file will be opened by calls to fopen() with a relative path */
 PHP_FUNCTION(stream_resolve_include_path)
 {
-       zval **ppfilename, *zcontext = NULL;
-       char *filename, *ptr = PG(include_path), *end = ptr + (ptr ? strlen(ptr) : 0), buffer[MAXPATHLEN];
+       zval **ppz_filename, *pz_context = NULL;
+       char *filename, *resolved_path;
        int filename_len;
        php_stream_context *context = NULL;
-       struct stat sb;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", &ppfilename, &zcontext) == FAILURE ||
-               php_stream_path_param_encode(ppfilename, &filename, &filename_len, REPORT_ERRORS, context = php_stream_context_from_zval(zcontext, 0)) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|r", &ppz_filename, &pz_context) == FAILURE ||
+               php_stream_path_param_encode(ppz_filename, &filename, &filename_len, REPORT_ERRORS, context = php_stream_context_from_zval(pz_context, 0)) == FAILURE) {
                return;
        }
 
-       while (ptr < end) {
-               char *s = strchr(ptr, DEFAULT_DIR_SEPARATOR);
-               UChar *upath;
-               int upath_len;
+       resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC);
 
-               if (!s) {
-                       s = end;
-               }
-
-               if (s == ptr) {
-                       ptr++;
-                       continue;
-               }
-
-               if ((s - ptr) + 1 + filename_len >= MAXPATHLEN) {
-                       /* Too long to try */
-                       ptr = s + 1;
-                       continue;
-               }
-
-               memcpy(buffer, ptr, s - ptr);
-               buffer[s - ptr] = '/';
-               memcpy(buffer + (s - ptr) + 1, filename, filename_len + 1);
-
-               if (php_check_open_basedir_ex(buffer, 0 TSRMLS_CC)) {
-                       ptr = s + 1;
-                       continue;
-               }
-
-               if (VCWD_STAT(buffer, &sb)) {
-                       ptr = s + 1;
-                       continue;
-               }
-
-               if (SUCCESS == php_stream_path_decode(NULL, &upath, &upath_len, buffer, (s - ptr) + 1 + filename_len, REPORT_ERRORS, context)) {
-                       RETURN_UNICODEL(upath, upath_len, 0);
+       if (resolved_path) {
+               UChar *ustr;
+               int ulen;
+               if (SUCCESS == zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, resolved_path, strlen(resolved_path) TSRMLS_CC)) {
+                       efree(resolved_path);
+                       RETURN_UNICODEL(ustr, ulen, 0);
                } else {
-                       /* Fallback */
-                       RETURN_STRINGL(buffer, (s - ptr) + 1 + filename_len, 1);
+                       RETURN_STRINGL(resolved_path, strlen(resolved_path), 1);
                }
        }
-
        RETURN_FALSE;
 }
 /* }}} */