# endif
#endif
+#include "dirname.h"
+
/* Return the leading directories part of PATH,
allocated with malloc. If out of memory, return 0.
Assumes that trailing slashes have already been
removed. */
char *
-dirname (char *path)
+dir_name (const char *path)
{
char *newpath;
char *slash;
else
{
/* Remove any trailing slashes from the result. */
+#ifdef MSDOS
+ char *lim = (path[0] >= 'A' && path[0] <= 'z' && path[1] == ':')
+ ? path + 2 : path;
+
+ /* If canonicalized "d:/path", leave alone the root case "d:/". */
+ while (slash > lim && *slash == '/')
+ --slash;
+#else
while (slash > path && *slash == '/')
--slash;
+#endif
length = slash - path + 1;
}