$NetBSD: patch-aa,v 1.2 2009/08/22 22:05:24 abs Exp $

--- dvdbackup.c.orig	2002-08-05 07:08:39.000000000 +0100
+++ dvdbackup.c
@@ -20,6 +20,7 @@
 
 
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/errno.h>
@@ -782,7 +783,7 @@ titles_info_t * DVDGetInfo(dvd_reader_t 
 	 to consider the second one a feature title we are doing two checks (biggest  + biggest - second) /second == 1
 	 and biggest%second * 3 < biggest */
 
-	if ( CheckSizeArray(size_size_array, 0, 1)  == 1 ) {
+	if ( title_sets > 1 && CheckSizeArray(size_size_array, 0, 1)  == 1 ) {
 		/* We have a dual DVD with two feature films - now lets see if they have the same amount of chapters*/
 
 		chapters_1 = 0;
@@ -1519,30 +1520,32 @@ int DVDGetTitleName(const char *device, 
 {
 	/* Variables for filehandel and title string interaction */
 
-	int  filehandle, i, last;
+	FILE *filehandle;
+	int i, last;
 
 	/* Open DVD device */
 
-	if ( !(filehandle = open(device, O_RDONLY)) ) {
+	if ( !(filehandle = fopen(device, "r")) ) {
 		fprintf(stderr, "Can't open secified device %s - check your DVD device\n", device);
 		return(1);
 	}
 
 	/* Seek to title of first track, which is at (track_no * 32768) + 40 */
 
-	if ( 32808 != lseek(filehandle, 32808, SEEK_SET) ) {
-		close(filehandle);
+	if ( fseek(filehandle, 32808, SEEK_SET) ) {
+		fclose(filehandle);
 		fprintf(stderr, "Can't seek DVD device %s - check your DVD device\n", device);
 		return(1);
 	}
 
 	/* Read the DVD-Video title */
 
-	if ( 32 != read(filehandle, title, 32)) {
-		close(filehandle);
+	if ( 32 != fread(title, 1, 32, filehandle)) {
+		fclose(filehandle);
 		fprintf(stderr, "Can't read title from DVD device %s\n", device);
 		return(1);
 	}
+	fclose(filehandle);
 
 	/* Terminate the title string */
 
@@ -2464,6 +2467,10 @@ int main(int argc, char *argv[]){
 #endif
 
 
+	/* On at least NetBSD5 we cannot fopen the dvd device during DVDOpen */
+	if (provided_title_name == NULL)
+		DVDGetTitleName(dvd,title_name);
+
 	_dvd = DVDOpen(dvd);
 	if(!_dvd) exit(-1);
 
@@ -2476,7 +2483,7 @@ int main(int argc, char *argv[]){
 
 
 	if(provided_title_name == NULL) {
-		if (DVDGetTitleName(dvd,title_name) != 0) {
+		if (title_name[0] == 0) {
 			fprintf(stderr,"You must provide a title name when you read your DVD-Video structure direct from the HD\n");
 			DVDClose(_dvd);
 			exit(1);
