mirror of
https://github.com/php/php-src.git
synced 2025-08-20 09:24:05 +02:00
- Fix dirname()
This commit is contained in:
parent
94bea2902b
commit
a1abfb7643
1 changed files with 47 additions and 29 deletions
|
@ -691,32 +691,55 @@ PHP_FUNCTION(basename)
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
}
|
}
|
||||||
convert_to_string_ex(str);
|
convert_to_string_ex(str);
|
||||||
ret = php_basename((*str)->value.str.val,(*str)->value.str.len);
|
ret = php_basename(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
|
||||||
RETVAL_STRING(ret,1)
|
RETVAL_STRING(ret, 0)
|
||||||
efree(ret);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
PHPAPI void php_dirname(char *str, int len)
|
/* This function doesn't work with absolute paths in Win32 such as C:\foo
|
||||||
|
* (and it didn't before either). This needs to be fixed
|
||||||
|
*/
|
||||||
|
PHPAPI void php_dirname(char *path, int len)
|
||||||
{
|
{
|
||||||
register char *c;
|
register char *end = path + len - 1;
|
||||||
|
|
||||||
c = str + len - 1;
|
if (len <= 0) {
|
||||||
while (*c == '/'
|
/* Illegal use of this function */
|
||||||
#ifdef PHP_WIN32
|
return;
|
||||||
|| *c == '\\'
|
}
|
||||||
#endif
|
|
||||||
)
|
/* Strip trailing slashes */
|
||||||
c--; /* strip trailing slashes */
|
while (end >= path && IS_SLASH(*end)) {
|
||||||
*(c + 1) = '\0';
|
end--;
|
||||||
if ((c = strrchr(str, '/'))
|
}
|
||||||
#ifdef PHP_WIN32
|
if (end < path) {
|
||||||
|| (c = strrchr(str, '\\'))
|
/* The path only contained slashes */
|
||||||
#endif
|
path[0] = DEFAULT_SLASH;
|
||||||
)
|
path[1] = '\0';
|
||||||
*c='\0';
|
return;
|
||||||
else
|
}
|
||||||
*str='\0';
|
|
||||||
|
/* Strip filename */
|
||||||
|
while (end >= path && !IS_SLASH(*end)) {
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
if (end < path) {
|
||||||
|
/* No slash found, therefore return '.' */
|
||||||
|
path[0] = '.';
|
||||||
|
path[1] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Strip slashes which came before the file name */
|
||||||
|
while (end >= path && IS_SLASH(*end)) {
|
||||||
|
end--;
|
||||||
|
}
|
||||||
|
if (end < path) {
|
||||||
|
path[0] = DEFAULT_SLASH;
|
||||||
|
path[1] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*(end+1) = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* {{{ proto string dirname(string path)
|
/* {{{ proto string dirname(string path)
|
||||||
|
@ -730,14 +753,9 @@ PHP_FUNCTION(dirname)
|
||||||
WRONG_PARAM_COUNT;
|
WRONG_PARAM_COUNT;
|
||||||
}
|
}
|
||||||
convert_to_string_ex(str);
|
convert_to_string_ex(str);
|
||||||
ret = estrdup((*str)->value.str.val);
|
ret = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
|
||||||
php_dirname(ret,(*str)->value.str.len);
|
php_dirname(ret, Z_STRLEN_PP(str));
|
||||||
if(*ret) {
|
RETVAL_STRING(ret, 0);
|
||||||
RETVAL_STRING(ret,1);
|
|
||||||
} else {
|
|
||||||
RETVAL_FALSE;
|
|
||||||
}
|
|
||||||
efree(ret);
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue