Skip to content

Commit

Permalink
Abort further processing if output file already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
twojstaryzdomu committed Jun 30, 2022
1 parent 567794c commit ecd586c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@
the output filenames as done by default in earlier releases.

Sealed various memory leaks. Refactored exit statements.

Abort further processing if output file already exists.
17 changes: 14 additions & 3 deletions bchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"\tGodmar Back <[email protected]>, Colas Nahaboo <[email protected]>\n" \
"\tMatthew Green <[email protected]> & twojstaryzdomu <@github.com>.\n" \
"\tReleased under the GNU GPL, version 2 or later (at your option).\n\n"

#define HINT "\nUse '-t' to include track # in output filename. " \
"Remaining tracks were not processed\n"

#define CUELLEN 1024
#define SECTLEN 2352
Expand Down Expand Up @@ -332,10 +335,15 @@ int writetrack(FILE *bf, struct track_t *track)
int16_t i;
float fl;

printf("%2d: %s ", track->num, track->output);
if (!(f = fopen(track->output, "wbx"))) {
if (errno == EEXIST)
die_format(5, "%2d: skipped: output file %s already exists, aborting\n%s",
track->num, track->output, HINT);
else
die_format(4, " Could not fopen track file: %s\n", strerror(errno));
}

if (!(f = fopen(track->output, "wb")))
die_format(4, " Could not fopen track file: %s\n", strerror(errno));
printf("%2d: %s ", track->num, track->output);

if (fseek(bf, track->start, SEEK_SET))
die_format(4, " Could not fseek to track location: %s\n", strerror(errno));
Expand Down Expand Up @@ -463,6 +471,9 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
die(4, "set_output(): asprintf() failed, out of memory\n");
free(bname);
bname = NULL;
if (strcmp(track->output, track->file) == 0)
die_format(5, "%2d: skipped: output file %s same as input file, aborting\n%s",
track->num, track->output, HINT);
return 1;
}

Expand Down

0 comments on commit ecd586c

Please sign in to comment.