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
This commit is contained in:
Conrad Meyer 2020-01-18 03:33:44 +00:00
parent de8dd262c4
commit 151e04b3fe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=356861

View File

@ -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