[libbluray-devel] caching: check for windows path separator

hpi1 git at videolan.org
Fri Jul 1 18:03:27 CEST 2016


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Jun 26 19:28:04 2016 +0300| [fcb1fd982b74efba38ff80e466bad0bf76ea97a3] | committer: hpi1

caching: check for windows path separator

Simplify and add error checking

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=fcb1fd982b74efba38ff80e466bad0bf76ea97a3
---

 src/libbluray/disc/disc.c |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c
index defa084..71585b7 100644
--- a/src/libbluray/disc/disc.c
+++ b/src/libbluray/disc/disc.c
@@ -453,9 +453,20 @@ int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_pa
     BD_FILE_H *fp_in;
     BD_FILE_H *fp_out;
     int64_t    got;
+    size_t     size;
 
-    if (rel_path[strlen(rel_path) - 1] == '/') {
-        file_mkdirs(cache_path);
+    if (!cache_path || !cache_path[0]) {
+        return -1;
+    }
+
+    /* make sure cache directory exists */
+    if (file_mkdirs(cache_path) < 0) {
+        return -1;
+    }
+
+    /* plain directory ? */
+    size = strlen(rel_path);
+    if (rel_path[size - 1] == '/' || rel_path[size - 1] == '\\') {
         return 0;
     }
 
@@ -466,9 +477,6 @@ int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_pa
         return -1;
     }
 
-    /* make sure path exists */
-    file_mkdirs(cache_path);
-
     /* output file in local filesystem */
     fp_out = file_open(cache_path, "wb");
     if (!fp_out) {



More information about the libbluray-devel mailing list