0005-hurd.patch 9.17 KB
Newer Older
1 2 3
From: Svante Signell <svante.signell@telia.com>
Date: Tue, 22 Apr 2014 11:47:57 +0200
Subject: hurd
4

5 6 7 8 9 10 11 12 13 14 15 16 17 18
libdvdread FTBFS on hurd-i386 due to PATH_MAX usage,
which is not defined on GNU/Hurd.
The attached patch fixes these problems by using
dynamic buffer allocation.

Closes: #640803

Signed-off-by: Matteo F. Vescovi <mfvescovi@gmail.com>
---
 src/dvd_reader.c | 62 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 14 deletions(-)

diff --git a/src/dvd_reader.c b/src/dvd_reader.c
index 170b911..fbdabb0 100644
Benjamin Drung's avatar
Benjamin Drung committed
19 20
--- a/src/dvd_reader.c
+++ b/src/dvd_reader.c
21 22 23 24 25 26 27 28 29
@@ -29,6 +29,7 @@
 #include <stdio.h>          /* fprintf */
 #include <errno.h>          /* errno, EIN* */
 #include <string.h>         /* memcpy, strlen */
+#define _GNU_SOURCE         /* Hurd support */
 #include <unistd.h>         /* chdir, getcwd */
 #include <limits.h>         /* PATH_MAX */
 #include <dirent.h>         /* opendir, readdir */
@@ -436,6 +437,12 @@ dvd_reader_t *DVDOpen( const char *ppath )
30 31 32 33 34 35 36 37 38 39 40 41
         if( chdir( path_copy ) == -1 ) {
           goto DVDOpen_error;
         }
+#ifdef __GLIBC__
+        new_path = get_current_dir_name();
+        if(new_path == NULL) {
+          goto DVDOpen_error;
+        }
+#else
         new_path = malloc(PATH_MAX+1);
         if(!new_path) {
           goto DVDOpen_error;
42
@@ -443,6 +450,7 @@ dvd_reader_t *DVDOpen( const char *ppath )
43 44 45 46 47 48 49
         if( getcwd( new_path, PATH_MAX ) == NULL ) {
           goto DVDOpen_error;
         }
+#endif
         retval = fchdir( cdir );
         close( cdir );
         cdir = -1;
50
@@ -658,17 +666,23 @@ static dvd_file_t *DVDOpenFileUDF( dvd_reader_t *dvd, char *filename )
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
  *     or -1 on file not found.
  *     or -2 on path not found.
  */
-static int findDirFile( const char *path, const char *file, char *filename )
+static int findDirFile( const char *path, const char *file, char **filename )
 {
   DIR *dir;
   struct dirent *ent;
+  *filename = NULL;
 
   dir = opendir( path );
   if( !dir ) return -2;
 
   while( ( ent = readdir( dir ) ) != NULL ) {
     if( !strcasecmp( ent->d_name, file ) ) {
-      sprintf( filename, "%s%s%s", path,
+      *filename = malloc( strlen( path ) + 1 + strlen( ent->d_name ) + 1 );
+      if( *filename == NULL ) {
+        closedir(dir);
+        return -1;
+      }
+      sprintf( *filename, "%s%s%s", path,
                ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
                ent->d_name );
       closedir(dir);
76
@@ -679,9 +693,9 @@ static int findDirFile( const char *path, const char *file, char *filename )
77 78 79 80 81 82 83 84 85 86 87
   return -1;
 }
 
-static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
+static int findDVDFile( dvd_reader_t *dvd, const char *file, char **filename )
 {
-  char video_path[ PATH_MAX + 1 ];
+  char *video_path = NULL;
   const char *nodirfile;
   int ret;
 
88
@@ -695,6 +709,8 @@ static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
89 90 91 92 93 94 95 96
   ret = findDirFile( dvd->path_root, nodirfile, filename );
   if( ret < 0 ) {
     /* Try also with adding the path, just in case. */
+    video_path = malloc( strlen( dvd->path_root ) + 10 + 1 );
+    if( video_path == NULL ) return 0;
     sprintf( video_path, "%s/VIDEO_TS/", dvd->path_root );
     ret = findDirFile( video_path, nodirfile, filename );
     if( ret < 0 ) {
97
@@ -702,9 +718,11 @@ static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
98 99 100 101 102 103 104 105 106 107 108
       sprintf( video_path, "%s/video_ts/", dvd->path_root );
       ret = findDirFile( video_path, nodirfile, filename );
       if( ret < 0 ) {
+        free( video_path );
         return 0;
       }
     }
+    free( video_path );
   }
 
   return 1;
109
@@ -715,20 +733,22 @@ static int findDVDFile( dvd_reader_t *dvd, const char *file, char *filename )
110 111 112 113 114 115 116 117 118 119 120 121
  */
 static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
 {
-  char full_path[ PATH_MAX + 1 ];
+  char *full_path = NULL;
   dvd_file_t *dvd_file;
   struct stat fileinfo;
   dvd_input_t dev;
 
   /* Get the full path of the file. */
-  if( !findDVDFile( dvd, filename, full_path ) ) {
+  if( !findDVDFile( dvd, filename, &full_path ) ) {
122
     fprintf( stderr, "libdvdread:DVDOpenFilePath:findDVDFile %s failed\n", filename );
123 124 125 126 127 128
+    free( full_path );
     return NULL;
   }
 
   dev = dvdinput_open( full_path );
   if( !dev ) {
129
     fprintf( stderr, "libdvdread:DVDOpenFilePath:dvdinput_open %s failed\n", full_path );
130 131 132 133
+    free( full_path );
     return NULL;
   }
 
134
@@ -736,6 +756,7 @@ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
135
   if( !dvd_file ) {
136
     fprintf( stderr, "libdvdread:DVDOpenFilePath:dvd_file malloc failed\n" );
137 138 139 140 141
     dvdinput_close(dev);
+    free( full_path );
     return NULL;
   }
   dvd_file->dvd = dvd;
142
@@ -747,6 +768,7 @@ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
143 144 145 146 147
 
   if( stat( full_path, &fileinfo ) < 0 ) {
     fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
+    free( full_path );
     free( dvd_file );
148
     dvdinput_close( dev );
149
     return NULL;
150
@@ -755,6 +777,7 @@ static dvd_file_t *DVDOpenFilePath( dvd_reader_t *dvd, char *filename )
151 152 153 154 155 156 157
   dvd_file->title_devs[ 0 ] = dev;
   dvd_file->filesize = dvd_file->title_sizes[ 0 ];
 
+  free( full_path );
   return dvd_file;
 }
 
158
@@ -810,7 +833,7 @@ static dvd_file_t *DVDOpenVOBUDF( dvd_reader_t *dvd, int title, int menu )
159 160 161 162 163 164 165 166
 static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
-  char full_path[ PATH_MAX + 1 ];
+  char *full_path = NULL;
   struct stat fileinfo;
   dvd_file_t *dvd_file;
   int i;
167
@@ -833,13 +856,15 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
     } else {
       sprintf( filename, "VTS_%02i_0.VOB", title );
     }
-    if( !findDVDFile( dvd, filename, full_path ) ) {
+    if( !findDVDFile( dvd, filename, &full_path ) ) {
+      free( full_path );
       free( dvd_file );
       return NULL;
     }
 
     dev = dvdinput_open( full_path );
     if( dev == NULL ) {
+      free( full_path );
       free( dvd_file );
       return NULL;
     }
184
@@ -847,6 +872,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
185 186 187 188 189 190 191
     if( stat( full_path, &fileinfo ) < 0 ) {
       fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
       dvdinput_close(dev);
+      free( full_path );
       free( dvd_file );
       return NULL;
     }
192
@@ -859,7 +885,7 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
193 194 195 196 197 198 199 200
     for( i = 0; i < TITLES_MAX; ++i ) {
 
       sprintf( filename, "VTS_%02i_%i.VOB", title, i + 1 );
-      if( !findDVDFile( dvd, filename, full_path ) ) {
+      if( !findDVDFile( dvd, filename, &full_path ) ) {
         break;
       }
 
201
@@ -874,11 +900,13 @@ static dvd_file_t *DVDOpenVOBPath( dvd_reader_t *dvd, int title, int menu )
202 203 204 205 206 207 208 209
       dvd_file->filesize += dvd_file->title_sizes[ i ];
     }
     if( !dvd_file->title_devs[ 0 ] ) {
+      free( full_path );
       free( dvd_file );
       return NULL;
     }
   }
210
 
211 212 213 214
+  free( full_path );
   return dvd_file;
 }
 
215
@@ -1000,7 +1028,7 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
216 217 218 219 220 221 222 223
                                int menu, dvd_stat_t *statbuf )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
-  char full_path[ PATH_MAX + 1 ];
+  char *full_path = NULL;
   struct stat fileinfo;
   off_t tot_size;
   off_t parts_size[ 9 ];
224
@@ -1012,11 +1040,14 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
225 226 227 228
   else
     sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
 
-  if( !findDVDFile( dvd, filename, full_path ) )
229
+  if( !findDVDFile( dvd, filename, &full_path ) ) {
230 231
+    free( full_path );
     return -1;
232
+  }
233 234 235 236 237 238 239
 
   if( stat( full_path, &fileinfo ) < 0 ) {
     fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
+    free( full_path );
     return -1;
   }
 
240
@@ -1028,7 +1059,7 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
241 242 243 244 245 246 247 248
     int cur;
     for( cur = 2; cur < 10; cur++ ) {
       sprintf( filename, "VTS_%02d_%d.VOB", title, cur );
-      if( !findDVDFile( dvd, filename, full_path ) )
+      if( !findDVDFile( dvd, filename, &full_path ) )
         break;
 
       if( stat( full_path, &fileinfo ) < 0 ) {
249
@@ -1047,6 +1078,7 @@ static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
250 251 252 253 254 255 256
   for( n = 0; n < nr_parts; n++ )
     statbuf->parts_size[ n ] = parts_size[ n ];
 
+  free( full_path );
   return 0;
 }
 
257
@@ -1055,7 +1087,7 @@ int DVDFileStat( dvd_reader_t *dvd, int titlenum,
258 259 260 261 262 263 264 265
                  dvd_read_domain_t domain, dvd_stat_t *statbuf )
 {
   char filename[ MAX_UDF_FILE_NAME_LEN ];
-  char full_path[ PATH_MAX + 1 ];
+  char *full_path = NULL;
   struct stat fileinfo;
   uint32_t size;
 
266
@@ -1111,17 +1143,19 @@ int DVDFileStat( dvd_reader_t *dvd, int titlenum,
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
       return 0;
     }
   } else {
-    if( findDVDFile( dvd, filename, full_path ) ) {
+    if( findDVDFile( dvd, filename, &full_path ) ) {
       if( stat( full_path, &fileinfo ) < 0 )
         fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
       else {
         statbuf->size = fileinfo.st_size;
         statbuf->nr_parts = 1;
         statbuf->parts_size[ 0 ] = statbuf->size;
+        free( full_path );
         return 0;
       }
     }
   }
+  free( full_path );
   return -1;
 }