X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fdirname.c;h=cf62de7a042f4a19cbe2c720720e8a76d7f53869;hb=226d63000a25c5f20ceecd610457b32d867909c7;hp=56b66e65c581c084b6d064ce03d8dc93112eb70b;hpb=67f394c1d2be473276ccd5e071f986511a13e212;p=gnulib.git diff --git a/lib/dirname.c b/lib/dirname.c index 56b66e65c..cf62de7a0 100644 --- a/lib/dirname.c +++ b/lib/dirname.c @@ -33,14 +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 (path) - char *path; +dir_name (const char *path) { char *newpath; char *slash; @@ -56,8 +57,17 @@ dirname (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; }