[FFmpeg-devel] [PATCH v2 2/2] avformat/utils: simplify the ff_mkdir_p with SEPARATOR

Hendrik Leppkes h.leppkes at gmail.com
Sun Dec 1 18:33:16 EET 2019


On Sun, Dec 1, 2019 at 3:08 PM <lance.lmwang at gmail.com> wrote:
>
> From: Limin Wang <lance.lmwang at gmail.com>
>
> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
> ---
>  libavformat/utils.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 579e6d6..993e6d2 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -4843,12 +4843,17 @@ 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;
> @@ -4856,19 +4861,18 @@ int ff_mkdir_p(const char *path)
>
>      if (*temp == '.')
>          pos++;
> -    if (*temp == '/' || *temp == '\\')
> +    if (*temp == SEPARATOR)
>          pos++;
>
>      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);
>      }

I think there is some value to be able to specify a path with both
kinds of slashes. For example, most of everything else on Windows will
accept normal slashes, in addition to the default backslash.

- Hendrik


More information about the ffmpeg-devel mailing list