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