svn commit: r356861 - head/sys/geom/label

Conrad Meyer cem at FreeBSD.org
Sat Jan 18 03:33:45 UTC 2020


Author: cem
Date: Sat Jan 18 03:33:44 2020
New Revision: 356861
URL: https://svnweb.freebsd.org/changeset/base/356861

Log:
  GEOM label: strip leading/trailing space synthesizing devfs names
  
  %20%20%20 is ugly and doesn't really help make human-readable devfs names.
  
  PR:		243318
  Reported by:	Peter Eriksson <pen AT lysator.liu.se>
  Relnotes:	yes

Modified:
  head/sys/geom/label/g_label.c

Modified: head/sys/geom/label/g_label.c
==============================================================================
--- head/sys/geom/label/g_label.c	Sat Jan 18 02:39:38 2020	(r356860)
+++ head/sys/geom/label/g_label.c	Sat Jan 18 03:33:44 2020	(r356861)
@@ -179,9 +179,25 @@ g_label_mangle_name(char *label, size_t size)
 {
 	struct sbuf *sb;
 	const u_char *c;
+	size_t len, i;
 
+	/* Trim trailing whitespace. */
+	len = strlen(label);
+	for (i = len; i > 0; i--) {
+		if (isspace(label[i - 1]))
+			label[i - 1] = '\0';
+		else
+			break;
+	}
+	if (*label == '\0')
+		return;
+
+
 	sb = sbuf_new(NULL, NULL, size, SBUF_FIXEDLEN);
 	for (c = label; *c != '\0'; c++) {
+		/* Trim leading whitespace. */
+		if (isspace(*c) && sbuf_len(sb) == 0)
+			continue;
 		if (!isprint(*c) || isspace(*c) || *c =='"' || *c == '%')
 			sbuf_printf(sb, "%%%02X", *c);
 		else


More information about the svn-src-head mailing list