From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9F038385840F; Wed, 29 Mar 2023 08:25:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F038385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680078345; bh=P5vvkBwKgP/On//fLsKv72FYblDubH04kG+J/LyCXv4=; h=From:To:Subject:Date:From; b=Q4z3Zp2ImL4n+dWYEoFVfXuCbAZoHH81Vgq8SofmlqphZlWhnnpFIdbfaH7glQH8P YTznEHO8ldFXnndhm6mgpw99rG5j+7R/p5NgriqIZyopp3DweqcsZY0cl0ufaZunP5 8GUcYPvVppW5cslk8c0KJAh6OzXwTxaLeWsDRvFU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_4-branch] Cygwin: dirname: fix handling of leading slashes X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/cygwin-3_4-branch X-Git-Oldrev: e9b1d1ce7f3f20af2860695ab947124219ca6531 X-Git-Newrev: 2bc5e1f6f35bbafd5de62d532d6a77b6292bed8a Message-Id: <20230329082545.9F038385840F@sourceware.org> Date: Wed, 29 Mar 2023 08:25:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D2bc5e1f6f35= bbafd5de62d532d6a77b6292bed8a commit 2bc5e1f6f35bbafd5de62d532d6a77b6292bed8a Author: Corinna Vinschen AuthorDate: Wed Mar 29 10:18:23 2023 +0200 Commit: Corinna Vinschen CommitDate: Wed Mar 29 10:23:13 2023 +0200 Cygwin: dirname: fix handling of leading slashes =20 Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/xbd_chap0= 4.html: =20 "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." =20 So more than 2 leading slashes are supposed to be folded into one, which our dirname neglected. Fix that. =20 Fixes: 24e8fc6872a3b ("* cygwin.din (basename): Export.") Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/path.cc | 2 +- winsup/cygwin/release/3.4.7 | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 97099af892d5..5b3df20dd321 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -5219,7 +5219,7 @@ dirname (char *path) return strcpy (buf, "."); if (isalpha (path[0]) && path[1] =3D=3D ':') bs +=3D 2; - else if (strspn (path, "/\\") > 1) + else if (strspn (path, "/\\") =3D=3D 2) ++bs; c =3D strrchr (bs, '/'); if ((d =3D strrchr (c ?: bs, '\\')) > c) diff --git a/winsup/cygwin/release/3.4.7 b/winsup/cygwin/release/3.4.7 index a121d81b62fa..2c305ec5f320 100644 --- a/winsup/cygwin/release/3.4.7 +++ b/winsup/cygwin/release/3.4.7 @@ -6,3 +6,6 @@ Bug Fixes =20 - kill(1): don't print spurious error message. 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