Text: handle output file
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 27 Mar 2017 19:32:52 +0000 (15:32 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:40 +0000 (12:57 -0400)
Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/text/text.c

index 3e2727622dca85cef6309ed2cc99103dac71cc39..78cdaab666ee9c16a6109c1ffcb0012aea0f4362 100644 (file)
@@ -82,6 +82,14 @@ void destroy_text_data(struct text_component *text)
 {
        bt_put(text->input_iterator);
        (void) g_string_free(text->string, TRUE);
+       if (text->out != stdout) {
+               int ret;
+
+               ret = fclose(text->out);
+               if (ret) {
+                       perror("close output file");
+               }
+       }
        g_free(text->options.output_path);
        g_free(text->options.debug_info_dir);
        g_free(text->options.debug_info_target_prefix);
@@ -322,6 +330,28 @@ void warn_wrong_color_param(struct text_component *text)
                "[warning] Accepted values for the \"color\" parameter are:\n    \"always\", \"auto\", \"never\"\n");
 }
 
+static
+enum bt_component_status open_output_file(struct text_component *text)
+{
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!text->options.output_path) {
+               goto end;
+       }
+
+       text->out = fopen(text->options.output_path, "w");
+       if (!text->out) {
+               goto error;
+       }
+
+       goto end;
+
+error:
+       ret = BT_COMPONENT_STATUS_ERROR;
+end:
+       return ret;
+}
+
 static
 enum bt_component_status apply_params(struct text_component *text,
                struct bt_value *params)
@@ -384,6 +414,10 @@ enum bt_component_status apply_params(struct text_component *text,
        if (ret != BT_COMPONENT_STATUS_OK) {
                goto end;
        }
+       ret = open_output_file(text);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto end;
+       }
 
        ret = apply_one_string("debug-info-dir",
                        params,
This page took 0.025394 seconds and 4 git commands to generate.