return blkid_probe_set_value(pr, "USAGE", (unsigned char *) u, strlen(u) + 1);
}
+
+/* Removes whitespace from the right-hand side of a string (trailing
+ * whitespace).
+ *
+ * Returns size of the new string (without \0).
+ */
+static size_t blkid_rtrim_whitespace(unsigned char *str)
+{
+ size_t i = strlen((char *) str);
+
+ while (i--) {
+ if (!isspace(str[i]))
+ break;
+ }
+ str[++i] = '\0';
+ return i;
+}
+
int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
{
struct blkid_prval *v;
- int i;
if (len > BLKID_PROBVAL_BUFSIZ)
len = BLKID_PROBVAL_BUFSIZ;
memcpy(v->data, label, len);
v->data[len] = '\0';
-
- /* remove trailing whitespace */
- i = strnlen((char *) v->data, len);
- while (i--) {
- if (!isspace(v->data[i]))
- break;
- }
- v->data[++i] = '\0';
- v->len = i + 1;
+ v->len = blkid_rtrim_whitespace(v->data) + 1;
return 0;
}
if (!v)
return -1;
- v->len = encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+ encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+ v->len = blkid_rtrim_whitespace(v->data) + 1;
return 0;
}