summaryrefslogtreecommitdiff
path: root/multimedia/lsdvd/patches/patch-ab
blob: 66b798fdc9a863aacb729f54822ecf8e6bae252c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
$NetBSD: patch-ab,v 1.5 2009/08/23 15:06:37 wiz Exp $

--- lsdvd.c.orig	2006-03-02 13:48:11.000000000 +0000
+++ lsdvd.c
@@ -13,6 +13,7 @@
  *  2003-04-19  Cleanups get_title_name, added dvdtime2msec, added helper macros,
  *			  output info structures in form of a Perl module, by Henk Vergonet.
  */
+#include <stdint.h>
 #include <dvdread/ifo_read.h>
 #include <string.h>
 #include <sys/stat.h>
@@ -131,19 +132,26 @@ int get_title_name(const char* dvd_devic
 		return -1;
 	}
 
-	if ( fseek(filehandle, 32808, SEEK_SET )) {
+	if ( fseek(filehandle, 32768, SEEK_SET )) {
 		fclose(filehandle);
 		fprintf(stderr, "Couldn't seek in %s for title\n", dvd_device);
 		strcpy(title, "unknown");
 		return -1;
 	}
 
-	if ( 32 != (i = fread(title, 1, 32, filehandle)) ) {
+	{
+	#define DVD_SEC_SIZ 2048
+	char tempBuf[ DVD_SEC_SIZ ];
+
+	if ( DVD_SEC_SIZ != fread(tempBuf, 1, DVD_SEC_SIZ, filehandle) ) {
 		fclose(filehandle);
 		fprintf(stderr, "Couldn't read enough bytes for title.\n");
 		strcpy(title, "unknown");
 		return -1;
 	}
+	snprintf( title, 32, "%s", tempBuf + 40 );
+	i=32;
+	}
 
 	fclose (filehandle);
 
@@ -239,6 +247,7 @@ int main(int argc, char *argv[])
 	int has_title = 0, ret = 0;
 	int max_length = 0, max_track = 0;
 	struct stat dvd_stat;
+	struct dvd_info dvd_info;
 
 	program_name = argv[0];
 
@@ -276,6 +285,9 @@ int main(int argc, char *argv[])
 		fprintf(stderr, "Can't find device %s\n", dvd_device);
 		return 1;
 	}
+
+	/* On at least NetBSD this fails if called after DVDOpen */
+	has_title = get_title_name(dvd_device, title);
 	
 	dvd = DVDOpen(dvd_device);
 	if( !dvd ) {
@@ -305,12 +317,8 @@ int main(int argc, char *argv[])
 		return 5;
 	}
 
-	has_title = get_title_name(dvd_device, title);
-
 	vmgi_mat = ifo_zero->vmgi_mat;
 
-	struct dvd_info dvd_info;
-		
 	dvd_info.discinfo.device = dvd_device;
 	dvd_info.discinfo.disc_title = has_title ? "unknown" : title;
 	dvd_info.discinfo.vmg_id =  vmgi_mat->vmg_identifier;
@@ -409,14 +417,16 @@ int main(int argc, char *argv[])
 
 		cell = 0;
 		if (opt_c) {
+			int ms;
+
 			dvd_info.titles[j].chapter_count = pgc->nr_of_programs;
 			dvd_info.titles[j].chapters = calloc(dvd_info.titles[j].chapter_count, sizeof(*dvd_info.titles[j].chapters));
 
-						int ms;
 			for (i=0; i<pgc->nr_of_programs; i++)
 			{	   
+				int next;
 				ms=0;
-				int next = pgc->program_map[i+1];   
+				next = pgc->program_map[i+1];   
 				if (i == pgc->nr_of_programs - 1) next = pgc->nr_of_cells + 1;
 
 				while (cell < next - 1)