Skip to content

Commit

Permalink
fix #303 (#308)
Browse files Browse the repository at this point in the history
* fix #303

* update to latest main
  • Loading branch information
liquidaty authored Nov 28, 2024
1 parent 0382dff commit ab33988
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/flatten.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ struct flatten_data {
const char *output_filename;

FILE *in;
const char *input_path;
FILE *out;
const char *input_path;

zsv_csv_writer csv_writer;

Expand Down Expand Up @@ -607,9 +607,6 @@ static void flatten_cleanup(struct flatten_data *data) {
if (data->in && data->in != stdin)
fclose(data->in);

if (data->out && data->out != stdout)
fclose(data->out);

struct flatten_column_name_and_ix *cnxlist[] = {&data->row_id_column, &data->column_name_column, &data->value_column};
for (int i = 0; i < 3; i++) {
struct flatten_column_name_and_ix *cnx = cnxlist[i];
Expand All @@ -625,6 +622,8 @@ static void flatten_cleanup(struct flatten_data *data) {

FREEIF(data->agg_output_cols_vector);
zsv_writer_delete(data->csv_writer);
if (data->out && data->out != stdout)
fclose(data->out);
}

int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *opts,
Expand Down Expand Up @@ -722,7 +721,7 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op
}
}

if (!(data.out = data.output_filename ? fopen(data.output_filename, "wb") : stdout))
if (!(data.out = writer_opts.stream = data.output_filename ? fopen(data.output_filename, "wb") : stdout))
err = zsv_printerr(1, "Unable to open %s for writing", data.output_filename);

int passes = data.column_name_column.name || !data.have_agg ? 2 : 1;
Expand Down

0 comments on commit ab33988

Please sign in to comment.