-BT_HIDDEN
-int validate_identifier(const char *input_string)
-{
- int ret = 0;
- char *string = NULL;
- char *save_ptr, *token;
-
- if (!input_string || input_string[0] == '\0') {
- ret = -1;
- goto end;
- }
-
- string = strdup(input_string);
- if (!string) {
- ret = -1;
- goto end;
- }
-
- token = strtok_r(string, " ", &save_ptr);
- while (token) {
- if (g_hash_table_lookup_extended(reserved_keywords_set,
- GINT_TO_POINTER(g_quark_from_string(token)),
- NULL, NULL)) {
- ret = -1;
- goto end;
- }
-
- token = strtok_r(NULL, " ", &save_ptr);
- }
-end:
- free(string);
- return ret;
-}
-
-BT_HIDDEN
-struct bt_ctf_field_type *get_field_type(enum field_type_alias alias)
-{
- unsigned int alignment, size;
- struct bt_ctf_field_type *field_type;
-
- if (alias >= NR_FIELD_TYPE_ALIAS) {
- return NULL;
- }
-
- alignment = field_type_aliases_alignments[alias];
- size = field_type_aliases_sizes[alias];
- field_type = bt_ctf_field_type_integer_create(size);
- bt_ctf_field_type_set_alignment(field_type, alignment);
- return field_type;
-}
-
-static
-int init_trace_packet_header(struct bt_ctf_writer *writer)
-{
- size_t i;
- int ret = 0;
- struct bt_ctf_field *trace_packet_header = NULL,
- *magic = NULL, *uuid_array = NULL;
- struct bt_ctf_field_type *_uint32_t =
- get_field_type(FIELD_TYPE_ALIAS_UINT32_T);
- struct bt_ctf_field_type *_uint8_t =
- get_field_type(FIELD_TYPE_ALIAS_UINT8_T);
- struct bt_ctf_field_type *trace_packet_header_type =
- bt_ctf_field_type_structure_create();
- struct bt_ctf_field_type *uuid_array_type =
- bt_ctf_field_type_array_create(_uint8_t, 16);
-
- if (!trace_packet_header_type || !uuid_array_type) {
- ret = -1;
- goto end;
- }
-
- ret = bt_ctf_field_type_set_byte_order(_uint32_t,
- (writer->byte_order == LITTLE_ENDIAN ?
- BT_CTF_BYTE_ORDER_LITTLE_ENDIAN :
- BT_CTF_BYTE_ORDER_BIG_ENDIAN));
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
- _uint32_t, "magic");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
- uuid_array_type, "uuid");
- if (ret) {
- goto end;
- }
-
- ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type,
- _uint32_t, "stream_id");
- if (ret) {
- goto end;
- }
-
- trace_packet_header = bt_ctf_field_create(trace_packet_header_type);
- if (!trace_packet_header) {
- ret = -1;
- goto end;
- }
-
- magic = bt_ctf_field_structure_get_field(trace_packet_header, "magic");
- ret = bt_ctf_field_unsigned_integer_set_value(magic, 0xC1FC1FC1);
- if (ret) {
- goto end;
- }
-
- uuid_array = bt_ctf_field_structure_get_field(trace_packet_header,
- "uuid");
- for (i = 0; i < 16; i++) {
- struct bt_ctf_field *uuid_element =
- bt_ctf_field_array_get_field(uuid_array, i);
- ret = bt_ctf_field_unsigned_integer_set_value(uuid_element,
- writer->uuid[i]);
- bt_ctf_field_put(uuid_element);
- if (ret) {
- goto end;
- }
- }
-
- bt_ctf_field_type_put(writer->trace_packet_header_type);
- bt_ctf_field_put(writer->trace_packet_header);
- writer->trace_packet_header_type = trace_packet_header_type;
- writer->trace_packet_header = trace_packet_header;
-end:
- bt_ctf_field_type_put(uuid_array_type);
- bt_ctf_field_type_put(_uint32_t);
- bt_ctf_field_type_put(_uint8_t);
- bt_ctf_field_put(magic);
- bt_ctf_field_put(uuid_array);
- if (ret) {
- bt_ctf_field_type_put(trace_packet_header_type);
- bt_ctf_field_put(trace_packet_header);
- }
-
- return ret;
-}
-
-static
-void environment_variable_destroy(struct environment_variable *var)
-{
- g_string_free(var->name, TRUE);
- g_string_free(var->value, TRUE);
- g_free(var);
-}
-