]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: superblocks: Add function blkid_probe_set_utf8_id_label for setting utf8...
authorPali Rohár <pali.rohar@gmail.com>
Mon, 15 Dec 2014 15:31:18 +0000 (16:31 +0100)
committerPali Rohár <pali.rohar@gmail.com>
Mon, 15 Dec 2014 15:31:18 +0000 (16:31 +0100)
libblkid/src/superblocks/superblocks.c
libblkid/src/superblocks/superblocks.h

index 80bd6e596f3d0d42465acd17c353340256259e46..975181d4c50c6746c01aa0232052c159ea6f620e 100644 (file)
@@ -590,6 +590,29 @@ int blkid_probe_set_id_label(blkid_probe pr, const char *name,
        return 0;
 }
 
+int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
+                            unsigned char *data, size_t len, int enc)
+{
+       struct blkid_chain *chn = blkid_probe_get_chain(pr);
+       struct blkid_prval *v;
+
+       if (!(chn->flags & BLKID_SUBLKS_LABEL))
+               return 0;
+
+       v = blkid_probe_assign_value(pr, name);
+       if (!v)
+               return -1;
+
+       blkid_encode_to_utf8(enc, v->data, sizeof(v->data), data, len);
+       v->len = blkid_rtrim_whitespace(v->data) + 1;
+       if (v->len > 1)
+               v->len = blkid_ltrim_whitespace(v->data) + 1;
+
+       if (v->len <= 1)
+               blkid_probe_reset_last_value(pr);
+       return 0;
+}
+
 int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
 {
        struct blkid_chain *chn = blkid_probe_get_chain(pr);
index 3bbfb9c1920407e879c7febb5b4e3f049ce80140..238a9ff1b3f996c4faab660e819bd0f8b43827af 100644 (file)
@@ -95,5 +95,7 @@ extern int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const ch
 
 extern int blkid_probe_set_id_label(blkid_probe pr, const char *name,
                             unsigned char *data, size_t len);
+extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
+                            unsigned char *data, size_t len, int enc);
 
 #endif /* _BLKID_SUPERBLOCKS_H */