public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: /dev/disk/by-id: Remove leading spaces from identify fields
@ 2023-11-08 19:41 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-11-08 19:41 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7863c07a9282b7aed358c5783976296adfa63505
commit 7863c07a9282b7aed358c5783976296adfa63505
Author: Christian Franke <christian.franke@t-online.de>
AuthorDate: Wed Nov 8 17:03:57 2023 +0100
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Nov 8 20:28:44 2023 +0100
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>
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/dev_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 <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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-11-08 19:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-08 19:41 [newlib-cygwin/main] Cygwin: /dev/disk/by-id: Remove leading spaces from identify fields Corinna Vinschen
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).