X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/dvdrip/blobdiff_plain/0049c6b5106e540f8fe6d91016de35fe9082bff9..9b86c33fd71be1d0310c6e32e12b8fb16c55f690:/lib.c diff --git a/lib.c b/lib.c index 69532e8..80b1507 100644 --- a/lib.c +++ b/lib.c @@ -109,6 +109,57 @@ void store_filename(char *buf, ident id) } } +static char *copy_string(char *p, const char *q) +{ + while (*q) *p++ = *q++; + *p = 0; return (p); +} + +static char *copy_hex(char *p, const unsigned char *q, size_t sz) +{ + while (sz) { + sprintf(p, "%02x", *q); + p += 2; q++; sz--; + } + return (p); +} + +int dvd_id(char *p, dvd_reader_t *dvd, unsigned f, const char *file) +{ + char volid[33]; + unsigned char volsetid[16], discid[16]; + int rc; + size_t n; + + rc = DVDUDFVolumeInfo(dvd, + volid, sizeof(volid), + volsetid, sizeof(volsetid)); + if (!rc) { + p = copy_string(p, volid); + *p++ = '-'; + for (n = sizeof(volsetid); n && !volsetid[n - 1]; n--); + p = copy_hex(p, volsetid, n); + } else if (f&DIF_MUSTVOLINF) { + if (file) moan("failed to read volume info for `%s'", file); + else moan("failed to read volume info"); + return (-1); + } else + p = copy_string(p, ""); + + *p++ = ':'; + rc = DVDDiscID(dvd, discid); + if (!rc) + p = copy_hex(p, discid, sizeof(discid)); + else if (f&DIF_MUSTIFOHASH) { + if (file) moan("failed to determine disc id of `%s'", file); + else moan("failed to determine disc id"); + return (-1); + } else + p = copy_string(p, ""); + + return (0); +} + struct progress_state progress = PROGRESS_STATE_INIT; static struct banner_progress_item banner_progress;