From: Pali Rohár Date: Mon, 15 Dec 2014 15:31:18 +0000 (+0100) Subject: libblkid: superblocks: Add function blkid_probe_set_utf8_id_label for setting utf8... X-Git-Tag: v2.26-rc1~63^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e9d4d4ab6e5ff5700136a6f2f935ab71bfbaced;p=thirdparty%2Futil-linux.git libblkid: superblocks: Add function blkid_probe_set_utf8_id_label for setting utf8 id label --- diff --git a/libblkid/src/superblocks/superblocks.c b/libblkid/src/superblocks/superblocks.c index 80bd6e596f..975181d4c5 100644 --- a/libblkid/src/superblocks/superblocks.c +++ b/libblkid/src/superblocks/superblocks.c @@ -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); diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h index 3bbfb9c192..238a9ff1b3 100644 --- a/libblkid/src/superblocks/superblocks.h +++ b/libblkid/src/superblocks/superblocks.h @@ -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 */