summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorSteven Liu <lq@chinaffmpeg.org>2018-09-22 22:10:09 +0800
committerSteven Liu <lq@chinaffmpeg.org>2018-09-25 21:57:49 +0800
commitbb660800a55f5171f77316941afe2e62534ee72c (patch)
tree274900744b0200566d8fc5f9a1d0cdc5226caddd /libavformat/utils.c
parenta7429d853de04d2f2984afdba36ebac3937651fb (diff)
avformat/utils: move mkdir_p to utils
Because it will be used by avformat/segment.c or other module which need to automatically create sub-directories operation. Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index c95aaa2fd6..c973a7e0c5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4797,6 +4797,40 @@ void av_url_split(char *proto, int proto_size,
}
}
+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;
+ *pos = '\0';
+ ret = mkdir(temp, 0755);
+ *pos = tmp_ch;
+ }
+ }
+
+ if ((*(pos - 1) != '/') || (*(pos - 1) != '\\')) {
+ ret = mkdir(temp, 0755);
+ }
+
+ av_free(temp);
+ return ret;
+}
+
char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
{
int i;