mirror of
https://github.com/fmang/opustags.git
synced 2025-01-16 05:03:13 +01:00
check before overwriting
This commit is contained in:
parent
c158a3ed78
commit
48b9e7b931
26
opustags.c
26
opustags.c
@ -3,6 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <ogg/ogg.h>
|
||||
|
||||
typedef struct {
|
||||
@ -151,12 +152,16 @@ int write_page(ogg_page *og, FILE *stream){
|
||||
|
||||
int main(int argc, char **argv){
|
||||
const char *path_in, *path_out = NULL;
|
||||
int overwrite = 0;
|
||||
int c;
|
||||
while((c = getopt(argc, argv, "o:")) != -1){
|
||||
while((c = getopt(argc, argv, "o:y")) != -1){
|
||||
switch(c){
|
||||
case 'o':
|
||||
path_out = optarg;
|
||||
break;
|
||||
case 'y':
|
||||
overwrite = 1;
|
||||
break;
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -166,20 +171,27 @@ int main(int argc, char **argv){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
path_in = argv[optind];
|
||||
FILE *in = fopen(path_in, "r");
|
||||
if(!in){
|
||||
perror("fopen");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
FILE *out = NULL;
|
||||
if(path_out != NULL){
|
||||
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");
|
||||
fclose(in);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
FILE *in = fopen(path_in, "r");
|
||||
if(!in){
|
||||
perror("fopen");
|
||||
if(out)
|
||||
fclose(out);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
ogg_sync_state oy;
|
||||
ogg_stream_state os, enc;
|
||||
ogg_page og;
|
||||
|
Loading…
x
Reference in New Issue
Block a user