secaddr end;
unsigned i, j;
- open_dvd(file, (flags&F_FIX) ? O_RDWR : O_RDONLY, &fd, 0);
+ if (open_dvd(file, (flags&F_FIX) ? O_RDWR : O_RDONLY, &fd, 0))
+ { set_status(2); goto end; }
blksz = SECTORSZ; volsz = device_size(fd, file, &blksz);
if (SECTORSZ != 2048)
{ gripe(2, "device sector size %d /= 2048", blksz); goto end; }
progress_init(&progress);
for (i = optind; i < argc; i++) {
- open_dvd(argv[i], O_RDONLY, 0, &dvd);
+ if (open_dvd(argv[i], O_RDONLY, 0, &dvd)) exit(2);
for (j = 0; j < 100; j++) {
kick_vob(j, 0);
setlocale(LC_ALL, "");
progress_init(&progress);
- open_dvd(argv[optind], O_RDONLY, 0, &dvd);
+ if (open_dvd(argv[optind], O_RDONLY, 0, &dvd)) exit(2);
css = dvdcss_open(argv[optind]);
if (!css)
bail_syserr(errno, "failed to attach CSS machinery to `%s'",
char id[MAXIDSZ];
int i, opt, st = 0;
unsigned f = 0, dif = 0;
- static dvd_reader_t *dvd;
+ static dvd_reader_t *dvd = 0;
#define f_bogus 1u
set_prog(argv[0]);
progress_init(&progress);
for (i = optind; i < argc; i++) {
- open_dvd(argv[i], O_RDONLY, 0, &dvd);
- if (dvd_id(id, dvd, dif, argv[i]))
+ if (open_dvd(argv[i], O_RDONLY, 0, &dvd) ||
+ dvd_id(id, dvd, dif, argv[i]))
st = 2;
else {
if (argc - optind > 1) printf("%s: ", argv[i]);
printf("%s\n", id);
}
- DVDClose(dvd);
+ DVDClose(dvd); dvd = 0;
}
progress_free(&progress);
if (f&f_bogus) { usage(stderr); exit(2); }
setlocale(LC_ALL, "");
progress_init(&progress);
- dvdfn = argv[optind]; open_dvd(dvdfn, O_RDONLY, 0, &dvd);
+ dvdfn = argv[optind]; if (open_dvd(dvdfn, O_RDONLY, 0, &dvd)) exit(2);
vmgi = ifoOpenVMGI(dvd);
if (!vmgi) bail("failed to open vmgi for `%s'", dvdfn);
#endif
}
- open_dvd(device, O_RDONLY, &dvdfd, &dvd);
+ if (open_dvd(device, O_RDONLY, &dvdfd, &dvd)) exit(2);
blksz = SECTORSZ; volsz = device_size(dvdfd, device, &blksz);
if (blksz != SECTORSZ)
device, volsz, SECTORSZ);
if (f&f_checkid) {
- open_dvd(outfile, O_RDONLY, 0, &dvd_out);
+ if (open_dvd(outfile, O_RDONLY, 0, &dvd_out)) exit(2);
if (dvd_id(id_in, dvd, DIF_MUSTIFOHASH, device) ||
dvd_id(id_out, dvd_out, DIF_MUSTIFOHASH, device))
exit(2);
static const dvd_logger_cb logger = { logfn };
#endif
-void open_dvd(const char *device, int mode,
- int *fd_out, dvd_reader_t **dvd_out)
+int open_dvd(const char *device, int mode,
+ int *fd_out, dvd_reader_t **dvd_out)
{
- int fd;
- dvd_reader_t *dvd;
- int bannerp = 0;
+ int fd = -1;
+ dvd_reader_t *dvd = 0;
+ int bannerp = 0, rc;
for (;;) {
fd = open(device, mode);
sit(0.2);
}
if (bannerp) hide_banner();
- if (fd < 0) bail_syserr(errno, "failed to open device `%s'", device);
+
+ if (fd < 0) {
+ moan_syserr(errno, "failed to open device `%s'", device);
+ rc = -1; goto end;
+ }
+
if (dvd_out) {
#ifdef notdef
dvd = DVDOpen2(0, &logger, device);
#else
dvd = DVDOpen(device);
#endif
- if (!dvd) bail("failed to open DVD on `%s'", device);
- *dvd_out = dvd;
+ if (!dvd) {
+ moan("failed to open DVD on `%s'", device);
+ rc = -1; goto end;
+ }
}
- if (fd_out) *fd_out = fd;
- else close(fd);
+
+ if (fd_out) { *fd_out = fd; fd = -1; }
+ if (dvd_out) { *dvd_out = dvd; dvd = 0; }
+ rc = 0;
+
+end:
+ if (fd >= 0) close(fd);
+ DVDClose(dvd);
+ return (rc);
}
void store_filename(char *buf, ident id)
/*----- DVD utilities -----------------------------------------------------*/
-extern void open_dvd(const char *device, int mode,
- int *fd_out, dvd_reader_t **dvd_out);
+extern int open_dvd(const char *device, int mode,
+ int *fd_out, dvd_reader_t **dvd_out);
/* Open the DEVICE. If FD_OUT is not null, then open a file
* descriptor onto the device, with the given open(2)-style MODE,
* storing the descriptor in *FD_OUT; if DVD_OUT is not null, then
* open a `libdvdread' handle onto the devie and store it in
* *DVD_OUT. If both are null, then why are you calling this
- * function?
+ * function? Returns 0 on success or -1 on failure.
*
* If DEVICE refers to an actual block device, and no medium is
* currently inserted, then put up a banner prompting the user and
- * wait for a medium to be inserted. Other problems are reported as
- * fatal errors.
+ * wait for a medium to be inserted. Other problems are reported to
+ * stderr.
*/
enum { RAW, IFO, VOB, BUP };