From b61922b5e7b4d7ec5ed960c3d842886b5a97f549 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 7 May 2011 01:37:07 -0400 Subject: [PATCH] Provide sane defaults Signed-off-by: Mathieu Desnoyers --- converter/babeltrace.c | 17 +++++++---------- formats/ctf-text/ctf-text.c | 2 ++ formats/ctf/ctf.c | 34 ++++------------------------------ 3 files changed, 13 insertions(+), 40 deletions(-) diff --git a/converter/babeltrace.c b/converter/babeltrace.c index c888ec60..cc7eabc4 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -164,17 +164,16 @@ int main(int argc, char **argv) printf_verbose("Converting from file: %s\n", opt_input_path); printf_verbose("Converting from format: %s\n", - opt_input_format ? : ""); + opt_input_format ? : "ctf "); printf_verbose("Converting to file: %s\n", opt_output_path ? : ""); printf_verbose("Converting to format: %s\n", - opt_output_format ? : "ctf"); + opt_output_format ? : "text "); - if (!opt_input_format) { - fprintf(stdout, "[error] Input format autodetection not implemented yet.\n\n"); - usage(stdout); - exit(EXIT_FAILURE); - } + if (!opt_input_format) + opt_input_format = "ctf"; + if (!opt_output_format) + opt_output_format = "text"; fmt_read = bt_lookup_format(g_quark_from_static_string(opt_input_format)); if (!fmt_read) { fprintf(stdout, "[error] Format \"%s\" is not supported.\n\n", @@ -197,12 +196,10 @@ int main(int argc, char **argv) goto error_td_read; } - if (!opt_output_path) - opt_output_path = "/dev/stdout"; td_write = fmt_write->open_trace(opt_output_path, O_WRONLY); if (!td_write) { fprintf(stdout, "Error opening trace \"%s\" for writing.\n\n", - opt_output_path); + opt_output_path ? : ""); goto error_td_write; } diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index 2e9509e7..8d84c37f 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -66,6 +66,8 @@ struct trace_descriptor *ctf_text_open_trace(const char *path, int flags) switch (flags & O_ACCMODE) { case O_WRONLY: + if (!path) + path = "/dev/stdout"; fp = fopen(path, "w"); if (!fp) goto error; diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index e375039b..08834e97 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -573,30 +573,6 @@ error: return ret; } -static -int ctf_open_trace_write(struct ctf_trace *td, const char *path, int flags) -{ - int ret; - - ret = mkdir(path, S_IRWXU|S_IRWXG); - if (ret) - return ret; - - /* Open trace directory */ - td->dir = opendir(path); - if (!td->dir) { - fprintf(stdout, "[error] Unable to open trace directory.\n"); - ret = -ENOENT; - goto error; - } - - - return 0; - -error: - return ret; -} - struct trace_descriptor *ctf_open_trace(const char *path, int flags) { struct ctf_trace *td; @@ -606,6 +582,10 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags) switch (flags & O_ACCMODE) { case O_RDONLY: + if (!path) { + fprintf(stdout, "[error] Path missing for input CTF trace.\n"); + goto error; + } ret = ctf_open_trace_read(td, path, flags); if (ret) goto error; @@ -613,12 +593,6 @@ struct trace_descriptor *ctf_open_trace(const char *path, int flags) case O_WRONLY: fprintf(stdout, "[error] Opening CTF traces for output is not supported yet.\n"); goto error; -#if 0 - ret = ctf_open_trace_write(td, path, flags); - if (ret) - goto error; -#endif //0 - break; default: fprintf(stdout, "[error] Incorrect open flags.\n"); goto error; -- 2.34.1