[FFmpeg-devel,v1] avformat/utils: simplify the ff_mkdir_p with SEPARATOR

Submitted by lance.lmwang@gmail.com on Nov. 8, 2019, 3:39 p.m.

Details

Message ID 20191108153904.30142-1-lance.lmwang@gmail.com
State New
Headers show

Commit Message

lance.lmwang@gmail.com Nov. 8, 2019, 3:39 p.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/utils.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8196442..e634f15 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4843,35 +4843,32 @@  void av_url_split(char *proto, int proto_size,
     }
 }
 
+#if HAVE_DOS_PATHS
+#define SEPARATOR '\\'
+#else
+#define SEPARATOR '/'
+#endif
+
 int ff_mkdir_p(const char *path)
 {
     int ret = 0;
     char *temp = av_strdup(path);
     char *pos = temp;
-    char tmp_ch = '\0';
 
     if (!path || !temp) {
         return -1;
     }
 
-    if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
-        pos++;
-    } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
-        pos += 2;
-    }
-
-    for ( ; *pos != '\0'; ++pos) {
-        if (*pos == '/' || *pos == '\\') {
-            tmp_ch = *pos;
+    for ( ; *pos; ++pos) {
+        if (*pos == SEPARATOR) {
+            /* Temporarily truncate */
             *pos = '\0';
-            ret = mkdir(temp, 0755);
-            *pos = tmp_ch;
+            ret += mkdir(temp, 0755);
+            *pos = SEPARATOR;
         }
     }
 
-    if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
-        ret = mkdir(temp, 0755);
-    }
+    ret += mkdir(temp, 0755);
 
     av_free(temp);
     return ret;