Index: trunk/xcache.c
===================================================================
--- trunk/xcache.c	(revision 867)
+++ trunk/xcache.c	(revision 869)
@@ -900,7 +900,7 @@
 /* }}} */
 
-#define XC_INCLUDE_PATH_XSTAT_FUNC(name) zend_bool name(const char *absolute_path, size_t absolute_path_len, void *data TSRMLS_DC)
+#define XC_INCLUDE_PATH_XSTAT_FUNC(name) zend_bool name(const char *filepath, size_t absolute_path_len, void *data TSRMLS_DC)
 typedef XC_INCLUDE_PATH_XSTAT_FUNC((*include_path_xstat_func_t));
-static zend_bool xc_include_path_apply(const char *filepath, char *opened_path_buffer, include_path_xstat_func_t xstat_func, void *data TSRMLS_DC) /* {{{ */
+static zend_bool xc_include_path_apply(const char *filepath, char *path_buffer, include_path_xstat_func_t xstat_func, void *data TSRMLS_DC) /* {{{ */
 {
 	char *paths, *path;
@@ -916,7 +916,7 @@
 
 	for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) {
-		absolute_path_len = snprintf(opened_path_buffer, MAXPATHLEN, "%s/%s", path, filepath);
+		absolute_path_len = snprintf(path_buffer, MAXPATHLEN, "%s/%s", path, filepath);
 		if (absolute_path_len < MAXPATHLEN - 1) {
-			if (xstat_func(opened_path_buffer, absolute_path_len, data)) {
+			if (xstat_func(path_buffer, absolute_path_len, data)) {
 				ret = 1;
 				goto finish;
@@ -936,8 +936,8 @@
 					if (dirname_len + filename_len < MAXPATHLEN - 1) {
 						++dirname_len; /* include tailing slash */
-						memcpy(opened_path_buffer, executed_filename, dirname_len);
-						memcpy(opened_path_buffer + dirname_len, filepath, filename_len);
+						memcpy(path_buffer, executed_filename, dirname_len);
+						memcpy(path_buffer + dirname_len, filepath, filename_len);
 						absolute_path_len = dirname_len + filename_len;
-						if (xstat_func(opened_path_buffer, absolute_path_len, data) == 0) {
+						if (xstat_func(path_buffer, absolute_path_len, data) == 0) {
 							ret = 1;
 							goto finish;
@@ -960,10 +960,10 @@
 static XC_INCLUDE_PATH_XSTAT_FUNC(xc_stat_file) /* {{{ */
 {
-	return VCWD_STAT(absolute_path, (struct stat *) data) == 0 ? 1 : 0;
-}
-/* }}} */
-static int xc_include_path_stat(const char *filepath, char *opened_path_buffer, struct stat *pbuf TSRMLS_DC) /* {{{ */
-{
-	return xc_include_path_apply(filepath, opened_path_buffer, xc_stat_file, (void *) pbuf TSRMLS_DC)
+	return VCWD_STAT(filepath, (struct stat *) data) == 0 ? 1 : 0;
+}
+/* }}} */
+static int xc_include_path_stat(const char *filepath, char *path_buffer, struct stat *pbuf TSRMLS_DC) /* {{{ */
+{
+	return xc_include_path_apply(filepath, path_buffer, xc_stat_file, (void *) pbuf TSRMLS_DC)
 		? SUCCESS
 		: FAILURE;
@@ -980,5 +980,5 @@
 	xc_compiler_t *compiler = entry_find_include_path_data->compiler;
 
-	compiler->new_entry.entry.name.str.val = absolute_path;
+	compiler->new_entry.entry.name.str.val = expand_filepath(filepath, compiler->opened_path_buffer TSRMLS_CC);
 	compiler->new_entry.entry.name.str.len = strlen(compiler->new_entry.entry.name.str.val);
 
@@ -993,11 +993,12 @@
 }
 /* }}} */
-static int xc_entry_find_include_path_dmz(xc_compiler_t *compiler, const char *filepath, char *opened_path_buffer, xc_entry_php_t **stored_entry TSRMLS_DC) /* {{{ */
-{
+static int xc_entry_find_include_path_dmz(xc_compiler_t *compiler, const char *filepath, xc_entry_php_t **stored_entry TSRMLS_DC) /* {{{ */
+{
+	char path_buffer[MAXPATHLEN];
 	xc_entry_find_include_path_data_t entry_find_include_path_data;
 	entry_find_include_path_data.compiler = compiler;
 	entry_find_include_path_data.stored_entry = stored_entry;
 
-	return xc_include_path_apply(filepath, opened_path_buffer, xc_entry_find_include_path_func_dmz, (void *) &entry_find_include_path_data TSRMLS_DC)
+	return xc_include_path_apply(filepath, path_buffer, xc_entry_find_include_path_func_dmz, (void *) &entry_find_include_path_data TSRMLS_DC)
 		? SUCCESS
 		: FAILURE;
@@ -1058,8 +1059,9 @@
 
 		if (xc_entry_php_quick_resolve_opened_path(compiler, &buf TSRMLS_CC) != SUCCESS) {
-			if (xc_include_path_stat(compiler->filename, compiler->opened_path_buffer, &buf TSRMLS_CC) != SUCCESS) {
+			char path_buffer[MAXPATHLEN];
+			if (xc_include_path_stat(compiler->filename, path_buffer, &buf TSRMLS_CC) != SUCCESS) {
 				return FAILURE;
 			}
-			compiler->opened_path = compiler->opened_path_buffer;
+			compiler->opened_path = expand_filepath(path_buffer, compiler->opened_path_buffer TSRMLS_CC);
 		}
 
@@ -1855,5 +1857,5 @@
 
 	ENTER_LOCK_EX(cache) {
-		if (!compiler->opened_path && xc_entry_find_include_path_dmz(compiler, compiler->filename, compiler->opened_path_buffer, &stored_entry TSRMLS_CC) == SUCCESS) {
+		if (!compiler->opened_path && xc_entry_find_include_path_dmz(compiler, compiler->filename, &stored_entry TSRMLS_CC) == SUCCESS) {
 			compiler->opened_path = compiler->opened_path_buffer;
 		}
@@ -1864,10 +1866,13 @@
 				}
 				/* fall back to real stat call */
-				else if (xc_include_path_stat(compiler->filename, compiler->opened_path_buffer, &statbuf TSRMLS_CC) == SUCCESS) {
-					compiler->opened_path = compiler->opened_path_buffer;
-				}
 				else {
-					gaveup = 1;
-					break;
+					char path_buffer[MAXPATHLEN];
+					if (xc_include_path_stat(compiler->filename, path_buffer, &statbuf TSRMLS_CC) == SUCCESS) {
+						compiler->opened_path = expand_filepath(path_buffer, compiler->opened_path_buffer TSRMLS_CC);
+					}
+					else {
+						gaveup = 1;
+						break;
+					}
 				}
 			}
