From 9057f0376ea389c66bc9a3f19790ccc193e1de60 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Fri, 18 Nov 2016 11:41:58 -0500 Subject: [PATCH] use GString instead of non-portable char[PATH/NAME_MAX] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- plugins/writer/write.c | 7 +++---- plugins/writer/writer.c | 15 +++++++++++++-- plugins/writer/writer.h | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/writer/write.c b/plugins/writer/write.c index 442c0c48..05f30dd9 100644 --- a/plugins/writer/write.c +++ b/plugins/writer/write.c @@ -649,11 +649,11 @@ struct bt_ctf_writer *insert_new_writer( enum bt_component_status ret; snprintf(trace_name, PATH_MAX, "%s/%s_%03d", - writer_component->base_path, - writer_component->trace_name_base, + writer_component->base_path->str, + writer_component->trace_name_base->str, writer_component->trace_id++); printf_verbose("CTF-Writer creating trace in %s\n", trace_name); - + ctf_writer = bt_ctf_writer_create(trace_name); if (!ctf_writer) { fprintf(writer_component->err, "[error] %s in %s:%d\n", @@ -1094,7 +1094,6 @@ enum bt_component_status writer_output_event( __FILE__, __LINE__); goto end_put_event_class; } -// printf("%s\n", event_name); stream = bt_ctf_event_get_stream(event); if (!stream) { diff --git a/plugins/writer/writer.c b/plugins/writer/writer.c index c9ec3479..a01b5c4a 100644 --- a/plugins/writer/writer.c +++ b/plugins/writer/writer.c @@ -45,6 +45,8 @@ void destroy_writer_component_data(struct writer_component *writer_component) g_hash_table_destroy(writer_component->stream_map); g_hash_table_destroy(writer_component->stream_class_map); g_hash_table_destroy(writer_component->trace_map); + g_string_free(writer_component->base_path, true); + g_string_free(writer_component->trace_name_base, true); } static @@ -90,7 +92,12 @@ struct writer_component *create_writer_component(void) writer_component->err = stderr; writer_component->trace_id = 0; - snprintf(writer_component->trace_name_base, NAME_MAX, "trace"); + writer_component->trace_name_base = g_string_new("trace"); + if (!writer_component->trace_name_base) { + g_free(writer_component); + writer_component = NULL; + goto end; + } /* * Reader to writer corresponding structures. @@ -233,7 +240,11 @@ enum bt_component_status writer_component_init( goto error; } - strncpy(writer_component->base_path, path, PATH_MAX); + writer_component->base_path = g_string_new(path); + if (!writer_component) { + ret = BT_COMPONENT_STATUS_ERROR; + goto error; + } ret = bt_component_set_destroy_cb(component, destroy_writer_component); diff --git a/plugins/writer/writer.h b/plugins/writer/writer.h index 2b44435f..939a12c8 100644 --- a/plugins/writer/writer.h +++ b/plugins/writer/writer.h @@ -33,8 +33,8 @@ #include struct writer_component { - char base_path[PATH_MAX]; - char trace_name_base[NAME_MAX]; + GString *base_path; + GString *trace_name_base; /* For the directory name suffix. */ int trace_id; /* Map between struct bt_ctf_trace and struct bt_ctf_writer. */ -- 2.34.1