moriyoshi Sat Apr 12 17:53:46 2003 EDT
Modified files:
/php4/ext/standard string.c
/php4/tests/run-test test007.phpt
/php4 TODO
Log:
Made dirname() binary-safe.
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.372 php4/ext/standard/string.c:1.373
--- php4/ext/standard/string.c:1.372 Sat Apr 12 16:04:06 2003
+++ php4/ext/standard/string.c Sat Apr 12 17:53:45 2003
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.372 2003/04/12 20:04:06 pollita Exp $ */
+/* $Id: string.c,v 1.373 2003/04/12 21:53:45 moriyoshi Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -1142,7 +1142,7 @@
/* {{{ php_dirname
Returns directory name component of path */
-PHPAPI void php_dirname(char *path, int len)
+PHPAPI size_t php_dirname(char *path, size_t len)
{
register char *end = path + len - 1;
@@ -1150,7 +1150,7 @@
/* Note that on Win32 CWD is per drive (heritage from CP/M).
* This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C:
drive.
*/
- if ((2 <= len) && isalpha(path[0]) && (':' == path[1])) {
+ if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' ==
path[1])) {
/* Skip over the drive spec (if any) so as not to change */
path += 2;
if (2 == len) {
@@ -1158,14 +1158,14 @@
* It would be more consistent to return "c:."
* but that would require making the string *longer*.
*/
- return;
+ return len;
}
}
#endif
- if (len <= 0) {
+ if (len == 0) {
/* Illegal use of this function */
- return;
+ return 0;
}
/* Strip trailing slashes */
@@ -1176,7 +1176,7 @@
/* The path only contained slashes */
path[0] = DEFAULT_SLASH;
path[1] = '\0';
- return;
+ return 1;
}
/* Strip filename */
@@ -1187,7 +1187,7 @@
/* No slash found, therefore return '.' */
path[0] = '.';
path[1] = '\0';
- return;
+ return 1;
}
/* Strip slashes which came before the file name */
@@ -1197,9 +1197,11 @@
if (end < path) {
path[0] = DEFAULT_SLASH;
path[1] = '\0';
- return;
+ return 1;
}
*(end+1) = '\0';
+
+ return (size_t)(end + 1 - path);
}
/* }}} */
@@ -1209,16 +1211,17 @@
{
zval **str;
char *ret;
-
+ size_t ret_len;
+
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(str);
ret = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
- php_dirname(ret, Z_STRLEN_PP(str));
+ ret_len = php_dirname(ret, Z_STRLEN_PP(str));
- RETURN_STRING(ret, 0);
+ RETURN_STRINGL(ret, ret_len, 0);
}
/* }}} */
Index: php4/tests/run-test/test007.phpt
Index: php4/TODO
diff -u php4/TODO:1.141 php4/TODO:1.142
--- php4/TODO:1.141 Sat Apr 12 17:29:49 2003
+++ php4/TODO Sat Apr 12 17:53:46 2003
@@ -140,7 +140,6 @@
* NOT binary safe:
strtok()
basename()
- dirname()
ext/wddx
--------
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php