]> granicus.if.org Git - handbrake/commitdiff
libhb: clean up handling dir directory separator
authorjstebbins <jstebbins.hb@gmail.com>
Sat, 22 Feb 2014 05:21:04 +0000 (05:21 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Sat, 22 Feb 2014 05:21:04 +0000 (05:21 +0000)
title->name was getting set to an empty string in some cases due to
looking for the wrong directory separator.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6057 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/bd.c
libhb/dvd.c
libhb/dvdnav.c
libhb/ports.c
libhb/ports.h
libhb/stream.c

index 9cd9d6ef112f6f75dcf38d3ecd18eb042bfc9c05..586a1fa7b0d265cd9fe9ddee8936927419096968 100644 (file)
@@ -253,11 +253,14 @@ hb_title_t * hb_bd_title_scan( hb_bd_t * d, int tt, uint64_t min_duration )
     char * p_cur, * p_last = d->path;
     for( p_cur = d->path; *p_cur; p_cur++ )
     {
-        if( p_cur[0] == '/' && p_cur[1] )
+        if( IS_DIR_SEP(p_cur[0]) && p_cur[1] )
         {
             p_last = &p_cur[1];
         }
     }
+    char *dot_term = strrchr(p_last, '.');
+    if (dot_term)
+        *dot_term = '\0';
     snprintf( title->name, sizeof( title->name ), "%s", p_last );
     strncpy( title->path, d->path, 1024 );
     title->path[1023] = 0;
index 7fb3830fbbdac3b5d60b36c3f09268394c78e0b9..628585b31c4ca1e0764c04ebb667ba3c5ed922c9 100644 (file)
@@ -187,11 +187,14 @@ static hb_title_t * hb_dvdread_title_scan( hb_dvd_t * e, int t, uint64_t min_dur
         char * p_cur, * p_last = d->path;
         for( p_cur = d->path; *p_cur; p_cur++ )
         {
-            if( p_cur[0] == '/' && p_cur[1] )
+            if( IS_DIR_SEP(p_cur[0]) && p_cur[1] )
             {
                 p_last = &p_cur[1];
             }
         }
+        char *dot_term = strrchr(p_last, '.');
+        if (dot_term)
+            *dot_term = '\0';
         snprintf( title->name, sizeof( title->name ), "%s", p_last );
     }
 
index 888289b60b8260e86ddcba15de831b6596a888be..081116c3b19c18c608c0448d6bdd7c90ca66963b 100644 (file)
@@ -334,11 +334,14 @@ static hb_title_t * hb_dvdnav_title_scan( hb_dvd_t * e, int t, uint64_t min_dura
         char * p_cur, * p_last = d->path;
         for( p_cur = d->path; *p_cur; p_cur++ )
         {
-            if( p_cur[0] == '/' && p_cur[1] )
+            if( IS_DIR_SEP(p_cur[0]) && p_cur[1] )
             {
                 p_last = &p_cur[1];
             }
         }
+        char *dot_term = strrchr(p_last, '.');
+        if (dot_term)
+            *dot_term = '\0';
         snprintf( title->name, sizeof( title->name ), "%s", p_last );
     }
 
index 6348ceb9dfbfc1ff6d1cfd7b692e676be2f8e6b5..bb7c235a2a0b37442a5caa6d8c65c5f38781506e 100644 (file)
@@ -626,6 +626,27 @@ struct dirent * hb_readdir(HB_DIR *dir)
 #endif
 }
 
+void hb_rewinddir(HB_DIR *dir)
+{
+#ifdef SYS_MINGW
+    _wrewinddir(dir->wdir);
+#else
+    return rewinddir(dir);
+#endif
+}
+
+char * hb_strr_dir_sep(const char *path)
+{
+#ifdef SYS_MINGW
+    char *sep = strrchr(path, '/');
+    if (sep == NULL)
+        sep = strrchr(path, '\\');
+    return sep;
+#else
+    return strrchr(path, '/');
+#endif
+}
+
 /************************************************************************
  * hb_mkdir
  ************************************************************************
index f55cac8c97dfa6f1c69ef09a15bf12dd7f57b5a7..771a233a7f10310d429f282fe621e7f7ae22cb28 100644 (file)
 
 #if defined(_WIN32)
 #define DIR_SEP_STR "\\"
+#define DIR_SEP_CHAR '\\'
+#define IS_DIR_SEP(c) (c == '\\' || c == '/')
 #else
 #define DIR_SEP_STR "/"
+#define DIR_SEP_CHAR '/'
+#define IS_DIR_SEP(c) (c == '/')
 #endif
 
+
 /************************************************************************
  * CPU info utilities
  ***********************************************************************/
@@ -66,10 +71,12 @@ typedef struct stat hb_stat_t;
 
 HB_DIR* hb_opendir(char *path);
 int hb_closedir(HB_DIR *dir);
+void hb_rewinddir(HB_DIR *dir);
 struct dirent * hb_readdir(HB_DIR *dir);
 int hb_mkdir(char * name);
 int hb_stat(const char *path, hb_stat_t *sb);
 FILE * hb_fopen(const char *path, const char *mode);
+char * hb_strr_dir_sep(const char *path);
 
 #ifdef __LIBHB__
 
index 43f155fd4b90cf38bbf7205c9ec7eeee02f14db1..a48d339f1f0f8524a17ee4e9092248348c75cf2a 100644 (file)
@@ -1042,7 +1042,7 @@ hb_title_t * hb_stream_title_scan(hb_stream_t *stream, hb_title_t * title)
     title->index = 1;
 
     // Copy part of the stream path to the title name
-    char *sep = strrchr(stream->path, '/');
+    char *sep = hb_strr_dir_sep(stream->path);
     if (sep)
         strcpy(title->name, sep+1);
     char *dot_term = strrchr(title->name, '.');
@@ -5361,7 +5361,7 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream, hb_title_t *title )
     title->index = 1;
 
     // Copy part of the stream path to the title name
-    char *sep = strrchr(stream->path, '/');
+    char *sep = hb_strr_dir_sep(stream->path);
     if (sep)
         strcpy(title->name, sep+1);
     char *dot_term = strrchr(title->name, '.');