Skip to content

Commit e34e572

Browse files
author
twojstaryzdomu
committed
Use va_list for die_format, replaced remaining error code with die_format
1 parent 5caaf7d commit e34e572

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bchunk.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
#define _GNU_SOURCE
22+
#include <stdarg.h>
2223
#include <stdio.h>
2324
#include <stdlib.h>
2425
#include <string.h>
@@ -127,9 +128,12 @@ void free_all(void)
127128
free(cuefile);
128129
}
129130

130-
void die_format(int status, char *format, char *error)
131+
void die_format(int status, char *format, ...)
131132
{
132-
fprintf(stderr, format, error);
133+
va_list args;
134+
va_start(args, format);
135+
vfprintf(stderr, format, args);
136+
va_end(args);
133137
free_all();
134138
exit(status);
135139
}
@@ -196,8 +200,7 @@ void parse_args(int argc, char *argv[])
196200
basefile = strdup(argv[i]);
197201
break;
198202
default:
199-
fprintf(stderr, "Gratuitous argument %s\n%s", argv[i], USAGE);
200-
exit(1);
203+
die_format(1, "Gratuitous argument %s\n%s", argv[i], USAGE);
201204
}
202205
}
203206
}
@@ -411,8 +414,7 @@ int writetrack(FILE *bf, struct track_t *track)
411414
fflush(stdout);
412415

413416
if (ferror(bf)) {
414-
fprintf(stderr, " Could not read from %s: %s\n", binfile, strerror(errno));
415-
exit(4);
417+
die_format(4, " Could not read from %s: %s\n", binfile, strerror(errno));
416418
}
417419
if (fclose(f))
418420
die_format(4, " Could not fclose track file: %s\n", strerror(errno));

0 commit comments

Comments
 (0)