1 /*
2 * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include <fcntl.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <unistd.h>
12
13 #include "cdda.h"
14 #include "cddb.h"
15
16
17 extern const char* __progname;
18
19
20 extern "C" status_t
user_memcpy(void * dest,const void * source,size_t length)21 user_memcpy(void *dest, const void *source, size_t length)
22 {
23 memcpy(dest, source, length);
24 return B_OK;
25 }
26
27
28 extern "C" void
dprintf(const char * format,...)29 dprintf(const char* format, ...)
30 {
31 va_list args;
32 va_start(args, format);
33 vprintf(format, args);
34 fflush(stdout);
35 va_end(args);
36 }
37
38
39 int
main(int argc,char ** argv)40 main(int argc, char** argv)
41 {
42 if (argc < 2)
43 return -1;
44 int fd = open(argv[1], O_RDONLY);
45 if (fd < 0)
46 return -1;
47
48 uint8 buffer[1024];
49 scsi_toc_toc *toc = (scsi_toc_toc *)buffer;
50
51 status_t status = read_table_of_contents(fd, toc, sizeof(buffer));
52 if (status != B_OK) {
53 fprintf(stderr, "%s: Retrieving TOC failed: %s\n", __progname,
54 strerror(status));
55 return -1;
56 }
57
58 cdtext text;
59 read_cdtext(fd, text);
60
61 uint32 id = compute_cddb_disc_id(*toc);
62 printf("CDDB disc ID: %lx\n", id);
63
64 close(fd);
65 }
66