]> granicus.if.org Git - php/commitdiff
Adjust dirname() on Win32 to match CWD per drive semantics.
authorPreston L. Bannister <pbannister@php.net>
Thu, 16 May 2002 16:04:45 +0000 (16:04 +0000)
committerPreston L. Bannister <pbannister@php.net>
Thu, 16 May 2002 16:04:45 +0000 (16:04 +0000)
ext/standard/string.c

index 5453daac860be96f9902b5a2193c01f97634f887..87e57ce90d9e01d50f0fd96c2367b059206a6acf 100644 (file)
@@ -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;