Cygwin: dirname: fix handling of leading slashes

Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/xbd_chap04.html:

  "A pathname that begins with two successive slashes may be interpreted
   in an implementation-defined manner, although more than two leading
   slashes shall be treated as a single slash."

So more than 2 leading slashes are supposed to be folded into one,
which our dirname neglected.  Fix that.

Fixes: 24e8fc6872 ("* cygwin.din (basename): Export.")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-03-29 10:18:23 +02:00
parent 27376c60a9
commit 2898a359b8
2 changed files with 4 additions and 1 deletions

View File

@ -5120,7 +5120,7 @@ dirname (char *path)
return strcpy (buf, "."); return strcpy (buf, ".");
if (isalpha (path[0]) && path[1] == ':') if (isalpha (path[0]) && path[1] == ':')
bs += 2; bs += 2;
else if (strspn (path, "/\\") > 1) else if (strspn (path, "/\\") == 2)
++bs; ++bs;
c = strrchr (bs, '/'); c = strrchr (bs, '/');
if ((d = strrchr (c ?: bs, '\\')) > c) if ((d = strrchr (c ?: bs, '\\')) > c)

View File

@ -6,3 +6,6 @@ Bug Fixes
- kill(1): don't print spurious error message. - kill(1): don't print spurious error message.
Addresses: https://cygwin.com/pipermail/cygwin/2023-March/253291.html Addresses: https://cygwin.com/pipermail/cygwin/2023-March/253291.html
- Align behaviour of dirname in terms of leading slashes to POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html