From 6b2ab5f66d1feb5ec3722ca8bb337e62634f9340 Mon Sep 17 00:00:00 2001 From: "Preston L. Bannister" Date: Thu, 16 May 2002 16:04:45 +0000 Subject: [PATCH] Adjust dirname() on Win32 to match CWD per drive semantics. --- ext/standard/string.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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; -- 2.50.1