From 151e04b3fe5d64f0fe0601f4cc8afae01e42b04c Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Sat, 18 Jan 2020 03:33:44 +0000 Subject: 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 Relnotes: yes --- sys/geom/label/g_label.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c index c37ca3511890..13639aedf7b2 100644 --- a/sys/geom/label/g_label.c +++ b/sys/geom/label/g_label.c @@ -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 -- cgit v1.2.3