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;
	int rc = 0;

	if (!(chn->flags & BLKID_SUBLKS_LABEL))
		return 0;

	v = blkid_probe_assign_value(pr, name);
	if (!v)
		return -ENOMEM;

	v->data = blkid_encode_alloc(len, &v->len);
	if (!v->data)
		rc = -ENOMEM;

	if (!rc) {
		blkid_encode_to_utf8(enc, v->data, v->len, 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)
			return 0;
	}

	blkid_probe_free_value(v);
	return rc;
}
int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
				size_t len, int enc)
{
	struct blkid_chain *chn = blkid_probe_get_chain(pr);
	struct blkid_prval *v;
	int rc = 0;

	if ((chn->flags & BLKID_SUBLKS_LABELRAW) &&
	    (rc = blkid_probe_set_value(pr, "LABEL_RAW", label, len)) < 0)
		return rc;

	if (!(chn->flags & BLKID_SUBLKS_LABEL))
		return 0;

	v = blkid_probe_assign_value(pr, "LABEL");
	if (!v)
		return -ENOMEM;

	v->data = blkid_encode_alloc(len, &v->len);
	if (!v->data)
		rc = -ENOMEM;
	if (!rc) {
		blkid_encode_to_utf8(enc, v->data, v->len, label, len);
		v->len = blkid_rtrim_whitespace(v->data) + 1;
		if (v->len > 1)
			return 0;
	}

	blkid_probe_free_value(v);
	return rc;
}
Beispiel #3
0
int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
				size_t len, int enc)
{
	struct blkid_chain *chn = blkid_probe_get_chain(pr);
	struct blkid_prval *v;

	if ((chn->flags & BLKID_SUBLKS_LABELRAW) &&
	    blkid_probe_set_value(pr, "LABEL_RAW", label, len) < 0)
		return -1;
	if (!(chn->flags & BLKID_SUBLKS_LABEL))
		return 0;
	v = blkid_probe_assign_value(pr, "LABEL");
	if (!v)
		return -1;

	blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
	v->len = blkid_rtrim_whitespace(v->data) + 1;
	if (v->len == 1)
		blkid_probe_reset_last_value(pr);
	return 0;
}