From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 340AB3858C41; Wed, 8 Nov 2023 19:41:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 340AB3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1699472513; bh=9aJqubqd6HKoKHAmjVDS5qM1+/eTBk65Gdra+3v+3rc=; h=From:To:Subject:Date:From; b=x4yJ+YecfIfvTn3Da2OD+NQIieCFJXy35t927FbpOcueZFULaR/+hq/0iT8Z11K6Z 1cyh8L+Bzb+5sMWWr3/m8UI8n+AihG2AqOKCpI7d2Vr/d7ofk2Wv016hcF3ffLLUUJ 3oxyizcfMEdIrX3bBnOPfFrPC+WMj2Qa5G1cLcew= 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/main] Cygwin: /dev/disk/by-id: Remove leading spaces from identify fields X-Act-Checkin: newlib-cygwin X-Git-Author: Christian Franke X-Git-Refname: refs/heads/main X-Git-Oldrev: 7236f22f713a923759ec7a98b4572c1910beb730 X-Git-Newrev: 7863c07a9282b7aed358c5783976296adfa63505 Message-Id: <20231108194153.340AB3858C41@sourceware.org> Date: Wed, 8 Nov 2023 19:41:53 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7863c07a928= 2b7aed358c5783976296adfa63505 commit 7863c07a9282b7aed358c5783976296adfa63505 Author: Christian Franke AuthorDate: Wed Nov 8 17:03:57 2023 +0100 Commit: Corinna Vinschen CommitDate: Wed Nov 8 20:28:44 2023 +0100 Cygwin: /dev/disk/by-id: Remove leading spaces from identify fields =20 Various drives align the serial number to the right of the fixed length field. =20 Signed-off-by: Christian Franke Diff: --- winsup/cygwin/fhandler/dev_disk.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/fhandler/dev_disk.cc b/winsup/cygwin/fhandler/de= v_disk.cc index fcd0de651b79..11b24042f54a 100644 --- a/winsup/cygwin/fhandler/dev_disk.cc +++ b/winsup/cygwin/fhandler/dev_disk.cc @@ -14,27 +14,33 @@ details. */ #include #include =20 -/* Replace non-printing and unexpected characters, remove trailing spaces, - return remaining string length. */ +/* Replace spaces, non-printing and unexpected characters. Remove + leading and trailing spaces. Return remaining string length. */ static int sanitize_id_string (char *s) { - int lastspace =3D -1, i; - for (i =3D 0; s[i]; i++) + int first =3D 0; + while (s[first] =3D=3D ' ') + first++; + int last =3D -1, i; + for (i =3D 0; s[first + i]; i++) { - char c =3D s[i]; + char c =3D s[first + i]; if (c !=3D ' ') - lastspace =3D -1; - else if (lastspace < 0) - lastspace =3D i; - if (('0' <=3D c && c <=3D '9') || c =3D=3D '.' || c =3D=3D '-' - || ('A' <=3D c && c <=3D 'Z') || ('a' <=3D c && c <=3D 'z')) + last =3D -1; + else if (last < 0) + last =3D i; + if (!(('0' <=3D c && c <=3D '9') || c =3D=3D '.' || c =3D=3D '-' + || ('A' <=3D c && c <=3D 'Z') || ('a' <=3D c && c <=3D 'z'))) + c =3D '_'; + else if (!first) continue; - s[i] =3D '_'; + s[i] =3D c; } - if (lastspace >=3D 0) - s[(i =3D lastspace)] =3D '\0'; - return i; + if (last < 0) + last =3D i; + s[last] =3D '\0'; + return last; } =20 /* Fetch storage properties and create the ID string.