+const char *bt_ctf_get_enum_str(const struct bt_definition *field)
+{
+ const struct definition_enum *def_enum;
+ const struct declaration_enum *decl_enum;
+ GArray *array;
+ const char *ret;
+
+ if (!field || bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) != CTF_TYPE_ENUM) {
+ bt_ctf_field_set_error(-EINVAL);
+ return NULL;
+ }
+ def_enum = container_of(field, const struct definition_enum, p);
+ decl_enum = def_enum->declaration;
+ if (bt_get_int_signedness(&def_enum->integer->p)) {
+ array = bt_enum_int_to_quark_set(decl_enum,
+ bt_get_signed_int(&def_enum->integer->p));
+ } else {
+ array = bt_enum_uint_to_quark_set(decl_enum,
+ bt_get_unsigned_int(&def_enum->integer->p));
+ }
+ if (!array) {
+ bt_ctf_field_set_error(-ENOENT);
+ return NULL;
+ }
+
+ if (array->len == 0) {
+ g_array_unref(array);
+ bt_ctf_field_set_error(-ENOENT);
+ return NULL;
+ }
+ /* Return first string. Arbitrary choice. */
+ ret = g_quark_to_string(g_array_index(array, GQuark, 0));
+ g_array_unref(array);