Better error messages and main switch reordering

This commit is contained in:
Matteo Bini 2023-09-23 13:45:48 +02:00
parent 5618a48742
commit 57231aabfc
1 changed files with 12 additions and 12 deletions

View File

@ -50,13 +50,13 @@ copy_dir(const char path[])
dir = bd_open_dir(bluray, path);
if (dir == NULL) {
fprintf(stderr, "Can't open dir %s on Blu-ray\n", path);
fprintf(stderr, "Can't open Blu-ray dir %s.\n", path);
return 0;
}
if (strcmp(path, "") != 0 &&
mkdir(path, 0755) == -1 && errno != EEXIST) {
fprintf(stderr, "Can't create dir %s on disk\n", path);
fprintf(stderr, "Can't create destination dir %s.\n", path);
return 0;
}
@ -66,7 +66,7 @@ copy_dir(const char path[])
read = dir->read(dir, dirent);
if (read == -1) {
break;
//fprintf(stderr, "Can't read dir %s on Blu-ray\n", path);
//fprintf(stderr, "Can't read Blu-ray dir %s.\n", path);
//return 0;
}
@ -104,12 +104,12 @@ copy_file(const char src[], const char dst[])
src_file = bd_open_file_dec(bluray, src);
if (src_file == NULL) {
fprintf(stderr, "Can't open file %s on Blu-ray\n", src);
fprintf(stderr, "Can't open Blu-ray file %s.\n", src);
return 0;
}
dst_file = fopen(dst, "w");
if (dst_file == NULL) {
fprintf(stderr, "Can't open file %s on disk\n", dst);
fprintf(stderr, "Can't open destination file %s.\n", dst);
return 0;
}
@ -120,14 +120,14 @@ copy_file(const char src[], const char dst[])
for (i = 0; i < read && read > 0; i++) {
written = fputc(bytes[i], dst_file);
if (written == EOF) {
fprintf(stderr, "Write error on %s, on disk\n", dst);
fprintf(stderr, "Destination write error on %s.\n", dst);
return 0;
}
}
}
while (read > 0);
if (read < 0) {
fprintf(stderr, "Read error on %s, on Blu-ray\n", src);
fprintf(stderr, "Blu-ray read error on %s.\n", src);
}
fclose(dst_file);
@ -159,15 +159,15 @@ main(int argc, char *argv[])
open_bluray(argv[1], argv[2]);
switch (argc) {
case 5:
success = copy_file(argv[3], argv[4]);
case 3:
success = copy_dir("");
break;
case 4:
basename(dst, argv[3]);
success = copy_file(argv[3], dst);
break;
case 3:
success = copy_dir("");
case 5:
success = copy_file(argv[3], argv[4]);
break;
}
@ -181,7 +181,7 @@ open_bluray(const char device[], const char keyfile[])
{
bluray = bd_open(device, keyfile);
if (bluray == NULL) {
fprintf(stderr, "Can't open device %s\n", device);
fprintf(stderr, "Can't open device %s.\n", device);
exit(1);
}
}