ZEND_API const char *get_active_class_name(const char **space);
ZEND_API const char *get_active_function_name(void);
ZEND_API const char *zend_get_executed_filename(void);
+ZEND_API zend_string *zend_get_executed_filename_ex(void);
ZEND_API uint zend_get_executed_lineno(void);
ZEND_API zend_bool zend_is_executing(void);
}
/* }}} */
+ZEND_API zend_string *zend_get_executed_filename_ex(void) /* {{{ */
+{
+ zend_execute_data *ex = EG(current_execute_data);
+
+ while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) {
+ ex = ex->prev_execute_data;
+ }
+ if (ex) {
+ return ex->func->op_array.filename;
+ } else {
+ return NULL;
+ }
+}
+/* }}} */
+
ZEND_API uint zend_get_executed_lineno(void) /* {{{ */
{
zend_execute_data *ex = EG(current_execute_data);
!is_stream_path(file_handle->filename)) {
char *include_path = NULL;
int include_path_len = 0;
- const char *parent_script = NULL;
- int parent_script_len = 0;
+ zend_string *parent_script = NULL;
+ size_t parent_script_len = 0;
int cur_len = 0;
int cwd_len;
char *cwd;
in include path too.
*/
if (EG(current_execute_data) &&
- (parent_script = zend_get_executed_filename()) != NULL &&
- parent_script[0] != '[') {
+ (parent_script = zend_get_executed_filename_ex()) != NULL) {
- parent_script_len = strlen(parent_script);
- while ((--parent_script_len > 0) && !IS_SLASH(parent_script[parent_script_len]));
+ parent_script_len = parent_script->len;
+ while ((--parent_script_len > 0) && !IS_SLASH(parent_script->val[parent_script_len]));
}
/* Calculate key length */
cur_len = cwd_len + 1 + path_length + 1;
if (parent_script_len) {
- memcpy(ZCG(key) + cur_len, parent_script, parent_script_len);
+ memcpy(ZCG(key) + cur_len, parent_script->val, parent_script_len);
cur_len += parent_script_len;
ZCG(key)[cur_len] = ':';
cur_len++;
const char *ptr, *end, *p;
const char *actual_path;
php_stream_wrapper *wrapper;
+ zend_string *exec_filename;
if (!filename || CHECK_NULL_PATH(filename, filename_length)) {
return NULL;
/* check in calling scripts' current working directory as a fall back case
*/
- if (zend_is_executing()) {
- const char *exec_fname = zend_get_executed_filename();
- int exec_fname_length = (int)strlen(exec_fname);
+ if (zend_is_executing() &&
+ (exec_filename = zend_get_executed_filename_ex()) != NULL) {
+ const char *exec_fname = exec_filename->val;
+ size_t exec_fname_length = exec_filename->len;
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
- if (exec_fname && exec_fname[0] != '[' &&
- exec_fname_length > 0 &&
+ if (exec_fname_length > 0 &&
exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) {
memcpy(trypath, exec_fname, exec_fname_length + 1);
memcpy(trypath+exec_fname_length + 1, filename, filename_length+1);
PHPAPI FILE *php_fopen_with_path(const char *filename, const char *mode, const char *path, zend_string **opened_path)
{
char *pathbuf, *ptr, *end;
- const char *exec_fname;
char trypath[MAXPATHLEN];
FILE *fp;
- int path_length;
int filename_length;
- int exec_fname_length;
+ zend_string *exec_filename;
if (opened_path) {
*opened_path = NULL;
/* append the calling scripts' current working directory
* as a fall back case
*/
- if (zend_is_executing()) {
- exec_fname = zend_get_executed_filename();
- exec_fname_length = (int)strlen(exec_fname);
- path_length = (int)strlen(path);
+ if (zend_is_executing() &&
+ (exec_filename = zend_get_executed_filename_ex()) != NULL) {
+ const char *exec_fname = exec_filename->val;
+ size_t exec_fname_length = exec_filename->len;
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
if ((exec_fname && exec_fname[0] == '[') || exec_fname_length <= 0) {
/* [no active file] or no path */
pathbuf = estrdup(path);
} else {
+ size_t path_length = strlen(path);
+
pathbuf = (char *) emalloc(exec_fname_length + path_length + 1 + 1);
memcpy(pathbuf, path, path_length);
pathbuf[path_length] = DEFAULT_DIR_SEPARATOR;
/* code ripped off from fopen_wrappers.c */
char *pathbuf, *end;
const char *ptr;
- const char *exec_fname;
char trypath[MAXPATHLEN];
php_stream *stream;
- int path_length;
int filename_length;
- int exec_fname_length;
+ zend_string *exec_filename;
if (opened_path) {
*opened_path = NULL;
/* append the calling scripts' current working directory
* as a fall back case
*/
- if (zend_is_executing()) {
- exec_fname = zend_get_executed_filename();
- exec_fname_length = (int)strlen(exec_fname);
- path_length = (int)strlen(path);
+ if (zend_is_executing() &&
+ (exec_filename = zend_get_executed_filename_ex()) != NULL) {
+ const char *exec_fname = exec_filename->val;
+ size_t exec_fname_length = exec_filename->len;
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
- if ((exec_fname && exec_fname[0] == '[')
- || exec_fname_length<=0) {
- /* [no active file] or no path */
+ if (exec_fname_length<=0) {
+ /* no path */
pathbuf = estrdup(path);
} else {
+ size_t path_length = strlen(path);
+
pathbuf = (char *) emalloc(exec_fname_length + path_length +1 +1);
memcpy(pathbuf, path, path_length);
pathbuf[path_length] = DEFAULT_DIR_SEPARATOR;