cvs: php4 /ext/standard string.c

From: Date: Thu, 16 May 2002 16:04:45 +0000
Subject: cvs: php4 /ext/standard string.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11954@lists.php.net to get a copy of this message
pbannister Thu May 16 12:04:46 2002 EDT Modified files: /php4/ext/standard string.c Log: Adjust dirname() on Win32 to match CWD per drive semantics. Index: php4/ext/standard/string.c diff -u php4/ext/standard/string.c:1.273 php4/ext/standard/string.c:1.274 --- php4/ext/standard/string.c:1.273 Thu May 16 10:42:22 2002 +++ php4/ext/standard/string.c Thu May 16 12:04:45 2002 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.273 2002/05/16 14:42:22 rasmus Exp $ */ +/* $Id: string.c,v 1.274 2002/05/16 16:04:45 pbannister Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -1095,13 +1095,27 @@ /* }}} */ /* {{{ 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 */

« previous php.cvs (#11954) next »