From 1021b4394d7258720cf9e3e46ffe95c69af9d85a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 23:31:25 +0100 Subject: [PATCH] check in before out so as not to create empty files --- opustags.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/opustags.c b/opustags.c index e13a9d8..ef92b00 100644 --- a/opustags.c +++ b/opustags.c @@ -258,30 +258,10 @@ int main(int argc, char **argv){ } } } - FILE *out = NULL; - if(path_out != NULL){ - if(strcmp(path_out, "-") == 0) - out = stdout; - else{ - if(!overwrite){ - if(access(path_out, F_OK) == 0){ - fprintf(stderr, "'%s' already exists (use -y to overwrite)\n", path_out); - return EXIT_FAILURE; - } - } - out = fopen(path_out, "w"); - if(!out){ - perror("fopen"); - return EXIT_FAILURE; - } - } - } FILE *in; if(strcmp(path_in, "-") == 0){ if(set_all){ fputs("can't open stdin for input when -S is specified\n", stderr); - if(out) - fclose(out); return EXIT_FAILURE; } in = stdin; @@ -290,10 +270,28 @@ int main(int argc, char **argv){ in = fopen(path_in, "r"); if(!in){ perror("fopen"); - if(out) - fclose(out); return EXIT_FAILURE; } + FILE *out = NULL; + if(path_out != NULL){ + if(strcmp(path_out, "-") == 0) + out = stdout; + else{ + if(!overwrite){ + if(access(path_out, F_OK) == 0){ + fprintf(stderr, "'%s' already exists (use -y to overwrite)\n", path_out); + fclose(in); + return EXIT_FAILURE; + } + } + out = fopen(path_out, "w"); + if(!out){ + perror("fopen"); + fclose(in); + return EXIT_FAILURE; + } + } + } ogg_sync_state oy; ogg_stream_state os, enc; ogg_page og;