const char *fmt, ...);
extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
+extern size_t blkid_rtrim_whitespace(unsigned char *str);
/* filter bitmap macros */
#define blkid_bmp_wordsize (8 * sizeof(unsigned long))
static void set_string(unsigned char *item, size_t max,
const unsigned char *data, size_t len)
{
- int i;
-
if (len >= max)
len = max - 1;
memcpy(item, data, len);
item[len] = '\0';
- /* remove trailing whitespace */
- i = strlen((char *) item);
- while (i--) {
- if (!isspace(item[i]))
- break;
- }
- item[++i] = '\0';
+ blkid_rtrim_whitespace(item);
}
int blkid_partition_set_name(blkid_partition par,
{
if (!par)
return -1;
+
blkid_encode_to_utf8(enc, par->name, sizeof(par->name), name, len);
+ blkid_rtrim_whitespace(par->name);
return 0;
}
* @data: pointer to return value data or NULL
* @len: pointer to return value length or NULL
*
+ * Note, the @len returns length of the @data, including the terminating
+ * '\0' character.
+ *
* Returns: 0 on success, or -1 in case of error.
*/
int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
* @data: pointer to return value data or NULL
* @len: pointer to return value length or NULL
*
+ * Note, the @len returns length of the @data, including the terminating
+ * '\0' character.
+ *
* Returns: 0 on success, or -1 in case of error.
*/
int blkid_probe_lookup_value(blkid_probe pr, const char *name,
#endif
}
+
+/* Removes whitespace from the right-hand side of a string (trailing
+ * whitespace).
+ *
+ * Returns size of the new string (without \0).
+ */
+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;
+}
+
{
struct blkid_chain *chn = blkid_probe_get_chain(pr);
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 = strlen((char *) v->data);
- 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 = blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+ blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+ v->len = blkid_rtrim_whitespace(v->data) + 1;
return 0;
}