From: Preston L. Bannister Date: Thu, 16 May 2002 16:04:45 +0000 (+0000) Subject: Adjust dirname() on Win32 to match CWD per drive semantics. X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b2ab5f66d1feb5ec3722ca8bb337e62634f9340;p=php Adjust dirname() on Win32 to match CWD per drive semantics. --- diff --git a/ext/standard/string.c b/ext/standard/string.c index 5453daac86..87e57ce90d 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1095,14 +1095,28 @@ PHP_FUNCTION(basename) /* }}} */ /* {{{ php_dirname - * - * 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 - */ + Returns directory name component of path */ PHPAPI void php_dirname(char *path, int len) { register char *end = path + len - 1; +#ifdef PHP_WIN32 + /* 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])) { + /* Skip over the drive spec (if any) so as not to change */ + path += 2; + if (2 == len) { + /* Return "c:" on Win32 for dirname("c:"). + * It would be more consistent to return "c:." + * but that would require making the string *longer*. + */ + return; + } + } +#endif + if (len <= 0) { /* Illegal use of this function */ return;