mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Since 5.6 stat.cwd using emalloc (Thanks to Remi)
This commit is contained in:
parent
29c449ce98
commit
9db4e25927
1 changed files with 22 additions and 0 deletions
|
@ -1707,17 +1707,23 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type T
|
||||||
static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC)
|
static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC)
|
||||||
{
|
{
|
||||||
cwd_state new_state;
|
cwd_state new_state;
|
||||||
|
#if ZEND_EXTENSION_API_NO < PHP_5_6_X_API_NO
|
||||||
char *real_path;
|
char *real_path;
|
||||||
|
#endif
|
||||||
char *cwd;
|
char *cwd;
|
||||||
int cwd_len;
|
int cwd_len;
|
||||||
|
|
||||||
/* realpath("") returns CWD */
|
/* realpath("") returns CWD */
|
||||||
if (!*path) {
|
if (!*path) {
|
||||||
|
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
|
||||||
|
new_state.cwd = (char*)emalloc(1);
|
||||||
|
#else
|
||||||
new_state.cwd = (char*)malloc(1);
|
new_state.cwd = (char*)malloc(1);
|
||||||
if (!new_state.cwd) {
|
if (!new_state.cwd) {
|
||||||
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
new_state.cwd[0] = '\0';
|
new_state.cwd[0] = '\0';
|
||||||
new_state.cwd_length = 0;
|
new_state.cwd_length = 0;
|
||||||
if ((cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) {
|
if ((cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) {
|
||||||
|
@ -1725,18 +1731,26 @@ static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC)
|
||||||
}
|
}
|
||||||
} else if (!IS_ABSOLUTE_PATH(path, path_len) &&
|
} else if (!IS_ABSOLUTE_PATH(path, path_len) &&
|
||||||
(cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) {
|
(cwd = accel_getcwd(&cwd_len TSRMLS_CC)) != NULL) {
|
||||||
|
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
|
||||||
|
new_state.cwd = estrndup(cwd, cwd_len);
|
||||||
|
#else
|
||||||
new_state.cwd = zend_strndup(cwd, cwd_len);
|
new_state.cwd = zend_strndup(cwd, cwd_len);
|
||||||
if (!new_state.cwd) {
|
if (!new_state.cwd) {
|
||||||
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
new_state.cwd_length = cwd_len;
|
new_state.cwd_length = cwd_len;
|
||||||
} else {
|
} else {
|
||||||
|
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
|
||||||
|
new_state.cwd = (char*)emalloc(1);
|
||||||
|
#else
|
||||||
new_state.cwd = (char*)malloc(1);
|
new_state.cwd = (char*)malloc(1);
|
||||||
if (!new_state.cwd) {
|
if (!new_state.cwd) {
|
||||||
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
zend_accel_error(ACCEL_LOG_ERROR, "malloc() failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
new_state.cwd[0] = '\0';
|
new_state.cwd[0] = '\0';
|
||||||
new_state.cwd_length = 0;
|
new_state.cwd_length = 0;
|
||||||
}
|
}
|
||||||
|
@ -1745,14 +1759,22 @@ static char *accel_tsrm_realpath(const char *path, int path_len TSRMLS_DC)
|
||||||
# define CWD_REALPATH 2
|
# define CWD_REALPATH 2
|
||||||
#endif
|
#endif
|
||||||
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) {
|
if (virtual_file_ex(&new_state, path, NULL, CWD_REALPATH)) {
|
||||||
|
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
|
||||||
|
efree(new_state.cwd);
|
||||||
|
#else
|
||||||
free(new_state.cwd);
|
free(new_state.cwd);
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
|
||||||
|
return new_state.cwd;
|
||||||
|
#else
|
||||||
real_path = emalloc(new_state.cwd_length + 1);
|
real_path = emalloc(new_state.cwd_length + 1);
|
||||||
memcpy(real_path, new_state.cwd, new_state.cwd_length + 1);
|
memcpy(real_path, new_state.cwd, new_state.cwd_length + 1);
|
||||||
free(new_state.cwd);
|
free(new_state.cwd);
|
||||||
return real_path;
|
return real_path;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *accel_php_resolve_path(const char *filename, int filename_length, const char *path TSRMLS_DC)
|
static char *accel_php_resolve_path(const char *filename, int filename_length, const char *path TSRMLS_DC)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue