X-Git-Url: https://git.distorted.org.uk/~mdw/dvdrip/blobdiff_plain/12ade065b04ab2710a7984b695a8644d713c3988..8ed763a58ec8c9f402d2ee30164c59a613afba93:/dvd-sector-copy.c diff --git a/dvd-sector-copy.c b/dvd-sector-copy.c index f1f6d4e..ee89f2a 100644 --- a/dvd-sector-copy.c +++ b/dvd-sector-copy.c @@ -95,8 +95,8 @@ static void put_menu(dvd_reader_t *dvd, unsigned title) store_filename(fn, id); start = UDFFindFile(dvd, fn, &len); if (!start) return; #ifdef DEBUG - printf(";; %8"PRIuSEC" .. %-8"PRIuSEC": %s\n", - start, start + SECTORS(len), fn); + printf(";; %8"PRIuSEC" .. %-8"PRIuSEC": %s\n", + start, start + SECTORS(len), fn); #endif put_file(id, start, start + SECTORS(len)); } @@ -487,9 +487,9 @@ static ssize_t recovery_read_buffer(struct recoverybuf *r, #endif } } else if (pos > r->pos + r->end) { - r->pos = pos; r->start = r->end = 0; + r->pos = pos; r->start = r->end = 0; #ifdef DEBUG - show_recovery_buffer_map(r, "cleared; beyond previous region"); + show_recovery_buffer_map(r, "cleared; beyond previous region"); #endif } else if (pos + want > r->pos + r->sz) { diff = (pos + want) - (r->pos + r->sz); @@ -805,41 +805,6 @@ static void emit(secaddr start, secaddr end) #undef BUFSECTORS } -struct buf { - char *p; - size_t n, sz; -}; -#define BUF_INIT { 0, 0, 0 } -#define BUF_REWIND(b) do { (b)->n = 0; } while (0) -#define BUF_FREE(b) do { \ - buf *_b = (b); \ - free(_b->p); _b->p = 0; _b->n = _b->sz = 0; \ -} while (0) -#define BUF_PUTC(b, ch) do { \ - struct buf *_b = (b); \ - if (_b->n >= _b->sz) { \ - _b->sz = _b->sz ? 2*_b->sz : 32; \ - _b->p = realloc(_b->p, _b->sz); \ - if (!_b->p) bail("out of memory allocating %zu bytes", _b->sz); \ - } \ - _b->p[_b->n] = (ch); \ -} while (0) - -static int read_line(FILE *fp, struct buf *b) -{ - int ch; - - ch = getc(fp); - if (ch == EOF) - return (-1); - else if (ch != '\n') do { - BUF_PUTC(b, ch); b->n++; - ch = getc(fp); - } while (ch != EOF && ch != '\n'); - BUF_PUTC(b, 0); - return (0); -} - #define PRF_HYPHEN 1u static int parse_range(const char *p, unsigned f, secaddr *start_out, secaddr *end_out) @@ -1002,7 +967,7 @@ int main(int argc, char *argv[]) bail_syserr(errno, "failed to open ranges file `%s'", optarg); i = 0; last = -1; for (;;) { - BUF_REWIND(&buf); if (read_line(fp, &buf)) break; + buf_rewind(&buf); if (read_line(fp, &buf)) break; p = buf.p; i++; while (ISSPACE(*p)) p++; if (!*p || *p == '#') continue; @@ -1028,7 +993,7 @@ int main(int argc, char *argv[]) bail_syserr(errno, "failed to open bad-blocks file `%s'", optarg); i = 0; last = -1; for (;;) { - BUF_REWIND(&buf); if (read_line(fp, &buf)) break; + buf_rewind(&buf); if (read_line(fp, &buf)) break; p = buf.p; i++; while (ISSPACE(*p)) p++; if (!*p || *p == '#') continue; @@ -1078,7 +1043,7 @@ int main(int argc, char *argv[]) #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) @@ -1088,7 +1053,7 @@ int main(int argc, char *argv[]) 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);