X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fdirname.c;h=cf62de7a042f4a19cbe2c720720e8a76d7f53869;hb=3bf5fcd0fcf3cc28fdf1ef589ec6360428680ef6;hp=c539efbe81728829e71b37aa26b26ede94259e6b;hpb=cf42d3e5e80be6bf7093a3ca9be0d04033eaf527;p=gnulib.git diff --git a/lib/dirname.c b/lib/dirname.c index c539efbe8..cf62de7a0 100644 --- a/lib/dirname.c +++ b/lib/dirname.c @@ -33,13 +33,15 @@ char *malloc (); # 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; @@ -55,8 +57,17 @@ dirname (char *path) 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; }