int blkid_probe_set_id_label(blkid_probe pr, const char *name, unsigned char *data, size_t len) { 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; rc = blkid_probe_value_set_data(v, data, len); if (!rc) { /* remove white spaces */ 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_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_id_label(blkid_probe pr, const char *name, unsigned char *data, size_t len) { 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; if (len >= BLKID_PROBVAL_BUFSIZ) len = BLKID_PROBVAL_BUFSIZ - 1; /* make a space for \0 */ memcpy(v->data, data, len); v->data[len] = '\0'; /* remove white spaces */ 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); /* ignore empty */ return 0; }