Default output to stdout if no output directory was specified
@@ -206,27 +206,24 @@ void usage_formats()
FILE * open_outfile(const char * cid_name, const char * binlog_name, const char * out_dir, const char * out_ext)
{
- int ret = 0;
+ if (out_dir == NULL) {
+ return stdout;
+ }
char filename[512];
- if (ret == 0) {
- if (out_dir != NULL) {
- ret = picoquic_sprintf(filename, sizeof(filename), NULL, "%s%c%s.%s",
+ int ret = picoquic_sprintf(filename, sizeof(filename), NULL, "%s%c%s.%s",
out_dir, PICOQUIC_FILE_SEPARATOR, cid_name, out_ext);
- } else {
- ret = picoquic_sprintf(filename, sizeof(filename), NULL, "%s.%s",
- cid_name, out_ext);
- }
+
if (ret != 0) {
DBG_PRINTF("Cannot format file name for connection %s in file %s", cid_name, binlog_name);
- }
+ return NULL;
}
- if (ret == 0) {
- return picoquic_file_open(filename, "w");
- } else {
- return NULL;
+ FILE * f = picoquic_file_open(filename, "w");
+ if (f == NULL) {
+ fprintf(stderr, "Could not open '%s' for writing (err=%d)", filename, errno);
}
+ return f;
}
int convert_csv(const picoquic_connection_id_t * cid, void * ptr)
@@ -626,8 +623,13 @@ int convert_qlog(const picoquic_connection_id_t* cid, void* ptr)
ret = -1;
}
+ FILE * f_txtlog = open_outfile(cid_name, appctx->binlog_name, appctx->out_dir, "qlog");
+ if (f_txtlog == NULL) {
+ return -1;
+ }
+
svg_context_t qlog;
- qlog.f_txtlog = open_outfile(cid_name, appctx->binlog_name, appctx->out_dir, "qlog");
+ qlog.f_txtlog = f_txtlog;
qlog.f_template = appctx->f_template;
qlog.cid_name = cid_name;
qlog.start_time = appctx->log_time;
