public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: /dev/disk/by-id: Remove leading spaces from identify fields
Date: Wed, 8 Nov 2023 17:40:10 +0100	[thread overview]
Message-ID: <52791a04-ceb6-7b88-fb41-21d971e69b44@t-online.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Minor improvement, avoids "/dev/disk/by-id/sata-VENDOR_MODEL_______SERIAL".

-- 
Regards,
Christian


[-- Attachment #2: 0001-Cygwin-dev-disk-by-id-Remove-leading-spaces-from-ide.patch --]
[-- Type: text/plain, Size: 1989 bytes --]

From 9927cd46435da97d234b0c7e97b5fc2a9b7632d1 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Wed, 8 Nov 2023 17:03:57 +0100
Subject: [PATCH] Cygwin: /dev/disk/by-id: Remove leading spaces from identify
 fields

Various drives align the serial number to the right of the fixed
length field.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 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/dev_disk.cc
index fcd0de651..11b24042f 100644
--- a/winsup/cygwin/fhandler/dev_disk.cc
+++ b/winsup/cygwin/fhandler/dev_disk.cc
@@ -14,27 +14,33 @@ details. */
 #include <wctype.h>
 #include <winioctl.h>
 
-/* 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 = -1, i;
-  for (i = 0; s[i]; i++)
+  int first = 0;
+  while (s[first] == ' ')
+    first++;
+  int last = -1, i;
+  for (i = 0; s[first + i]; i++)
     {
-      char c = s[i];
+      char c = s[first + i];
       if (c != ' ')
-	lastspace = -1;
-      else if (lastspace < 0)
-	lastspace = i;
-      if (('0' <= c && c <= '9') || c == '.' || c == '-'
-	  || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'))
+	last = -1;
+      else if (last < 0)
+	last = i;
+      if (!(('0' <= c && c <= '9') || c == '.' || c == '-'
+	  || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')))
+	c = '_';
+      else if (!first)
 	continue;
-      s[i] = '_';
+      s[i] = c;
     }
-  if (lastspace >= 0)
-    s[(i = lastspace)] = '\0';
-  return i;
+  if (last < 0)
+    last = i;
+  s[last] = '\0';
+  return last;
 }
 
 /* Fetch storage properties and create the ID string.
-- 
2.42.1


             reply	other threads:[~2023-11-08 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08 16:40 Christian Franke [this message]
2023-11-08 19:42 ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52791a04-ceb6-7b88-fb41-21d971e69b44@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).