diff mbox

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

Message ID 20191202045106.27737-2-lance.lmwang@gmail.com
State New
Headers show

Commit Message

Lance Wang Dec. 2, 2019, 4:51 a.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Please tested by below command(Mac or Linux):
./ffmpeg -i ~/Movies/input.mp4  -use_localtime 1 -use_localtime_mkdir 1 -hls_segment_filename 'hls/t\e\s\t/%Y%m%d/file-%Y%m%d-%s.ts' ./out.m3u8
Master:
$ ls hls/
t       t\e     t\e\s   t\e\s\t

After applied the patch:
$ ls hls/
t\e\s\t


Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavformat/utils.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 03a3705200..0a94515e0e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4843,32 +4843,36 @@  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 (*temp == '/' || *temp == '\\')
+    if (*temp == SEPARATOR)
         pos++;
-    else if (*temp == '.' && (*(temp+1) == '/' || *(temp+1) == '\\'))
+    else if (*temp == '.' && *(temp+1) == SEPARATOR)
         pos += 2;
 
     for ( ; *pos != '\0'; ++pos) {
-        if (*pos == '/' || *pos == '\\') {
-            tmp_ch = *pos;
+        if (*pos == SEPARATOR) {
             *pos = '\0';
             ret = mkdir(temp, 0755);
-            *pos = tmp_ch;
+            *pos = SEPARATOR;
         }
     }
 
-    if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
+    if (*(pos - 1) != SEPARATOR) {
         ret = mkdir(temp, 0755);
     }