[FFmpeg-devel,v3] avutil/avstring: support input path is a null pointer or empty string

Submitted by lance.lmwang@gmail.com on Sept. 20, 2019, 2:53 a.m.

Details

Message ID 20190920025338.4436-1-lance.lmwang@gmail.com
State Accepted
Commit a77fb510c2684a43980c79ff85ff36e094cae63c
Headers show

Commit Message

lance.lmwang@gmail.com Sept. 20, 2019, 2:53 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Linux and OSX systems support basename and dirname via <libgen.h>, I plan to
make the wrapper interface conform to the standard interface first.
If it is feasible, I will continue to modify it to call the system interface
if there is already a system call interface.

You can get more descrioption about the system interface by below command:
 "man 3 basename"

Reviewed-by: Marton Balint <cus@passwd.hu>
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavutil/avstring.c | 12 ++++++++----
 libavutil/avstring.h | 13 +++++++++----
 2 files changed, 17 insertions(+), 8 deletions(-)

Comments

lance.lmwang@gmail.com Sept. 24, 2019, 10:30 a.m.
ping, please help to push the patchset.

On Fri, Sep 20, 2019 at 10:53:38AM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Linux and OSX systems support basename and dirname via <libgen.h>, I plan to
> make the wrapper interface conform to the standard interface first.
> If it is feasible, I will continue to modify it to call the system interface
> if there is already a system call interface.
> 
> You can get more descrioption about the system interface by below command:
>  "man 3 basename"
> 
> Reviewed-by: Marton Balint <cus@passwd.hu>
> Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavutil/avstring.c | 12 ++++++++----
>  libavutil/avstring.h | 13 +++++++++----
>  2 files changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> index 4c068f5..76a13ba 100644
> --- a/libavutil/avstring.c
> +++ b/libavutil/avstring.c
> @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char *from, const char *to)
>  
>  const char *av_basename(const char *path)
>  {
> -    char *p = strrchr(path, '/');
> +    char *p;
>  
> +    if (!path || *path == '\0')
> +        return ".";
> +
> +    p = strrchr(path, '/');
>  #if HAVE_DOS_PATHS
>      char *q = strrchr(path, '\\');
>      char *d = strchr(path, ':');
> @@ -274,11 +278,11 @@ const char *av_basename(const char *path)
>  
>  const char *av_dirname(char *path)
>  {
> -    char *p = strrchr(path, '/');
> +    char *p = path ? strrchr(path, '/') : NULL;
>  
>  #if HAVE_DOS_PATHS
> -    char *q = strrchr(path, '\\');
> -    char *d = strchr(path, ':');
> +    char *q = path ? strrchr(path, '\\') : NULL;
> +    char *d = path ? strchr(path, ':')  : NULL;
>  
>      d = d ? d + 1 : d;
>  
> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> index 37dd4e2..274335c 100644
> --- a/libavutil/avstring.h
> +++ b/libavutil/avstring.h
> @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char *from, const char *to);
>  
>  /**
>   * Thread safe basename.
> - * @param path the path, on DOS both \ and / are considered separators.
> + * @param path the string to parse, on DOS both \ and / are considered separators.
>   * @return pointer to the basename substring.
> + * If path does not contain a slash, the function returns a copy of path.
> + * If path is a NULL pointer or points to an empty string, a pointer
> + * to a string "." is returned.
>   */
>  const char *av_basename(const char *path);
>  
>  /**
>   * Thread safe dirname.
> - * @param path the path, on DOS both \ and / are considered separators.
> - * @return the path with the separator replaced by the string terminator or ".".
> - * @note the function may change the input string.
> + * @param path the string to parse, on DOS both \ and / are considered separators.
> + * @return A pointer to a string that's the parent directory of path.
> + * If path is a NULL pointer or points to an empty string, a pointer
> + * to a string "." is returned.
> + * @note the function may modify the contents of the path, so copies should be passed.
>   */
>  const char *av_dirname(char *path);
>  
> -- 
> 2.9.5
>
Paul B Mahol Sept. 24, 2019, 10:33 a.m.
On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
>
> ping, please help to push the patchset.

There are typos in patch.

>
> On Fri, Sep 20, 2019 at 10:53:38AM +0800, lance.lmwang@gmail.com wrote:
>> From: Limin Wang <lance.lmwang@gmail.com>
>>
>> Linux and OSX systems support basename and dirname via <libgen.h>, I plan
>> to
>> make the wrapper interface conform to the standard interface first.
>> If it is feasible, I will continue to modify it to call the system
>> interface
>> if there is already a system call interface.
>>
>> You can get more descrioption about the system interface by below command:
>>  "man 3 basename"
>>
>> Reviewed-by: Marton Balint <cus@passwd.hu>
>> Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
>> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
>> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> ---
>>  libavutil/avstring.c | 12 ++++++++----
>>  libavutil/avstring.h | 13 +++++++++----
>>  2 files changed, 17 insertions(+), 8 deletions(-)
>>
>> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
>> index 4c068f5..76a13ba 100644
>> --- a/libavutil/avstring.c
>> +++ b/libavutil/avstring.c
>> @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char
>> *from, const char *to)
>>
>>  const char *av_basename(const char *path)
>>  {
>> -    char *p = strrchr(path, '/');
>> +    char *p;
>>
>> +    if (!path || *path == '\0')
>> +        return ".";
>> +
>> +    p = strrchr(path, '/');
>>  #if HAVE_DOS_PATHS
>>      char *q = strrchr(path, '\\');
>>      char *d = strchr(path, ':');
>> @@ -274,11 +278,11 @@ const char *av_basename(const char *path)
>>
>>  const char *av_dirname(char *path)
>>  {
>> -    char *p = strrchr(path, '/');
>> +    char *p = path ? strrchr(path, '/') : NULL;
>>
>>  #if HAVE_DOS_PATHS
>> -    char *q = strrchr(path, '\\');
>> -    char *d = strchr(path, ':');
>> +    char *q = path ? strrchr(path, '\\') : NULL;
>> +    char *d = path ? strchr(path, ':')  : NULL;
>>
>>      d = d ? d + 1 : d;
>>
>> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
>> index 37dd4e2..274335c 100644
>> --- a/libavutil/avstring.h
>> +++ b/libavutil/avstring.h
>> @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char
>> *from, const char *to);
>>
>>  /**
>>   * Thread safe basename.
>> - * @param path the path, on DOS both \ and / are considered separators.
>> + * @param path the string to parse, on DOS both \ and / are considered
>> separators.
>>   * @return pointer to the basename substring.
>> + * If path does not contain a slash, the function returns a copy of path.
>> + * If path is a NULL pointer or points to an empty string, a pointer
>> + * to a string "." is returned.
>>   */
>>  const char *av_basename(const char *path);
>>
>>  /**
>>   * Thread safe dirname.
>> - * @param path the path, on DOS both \ and / are considered separators.
>> - * @return the path with the separator replaced by the string terminator
>> or ".".
>> - * @note the function may change the input string.
>> + * @param path the string to parse, on DOS both \ and / are considered
>> separators.
>> + * @return A pointer to a string that's the parent directory of path.
>> + * If path is a NULL pointer or points to an empty string, a pointer
>> + * to a string "." is returned.
>> + * @note the function may modify the contents of the path, so copies
>> should be passed.
>>   */
>>  const char *av_dirname(char *path);
>>
>> --
>> 2.9.5
>>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
lance.lmwang@gmail.com Sept. 24, 2019, 10:52 a.m.
On Tue, Sep 24, 2019 at 12:33:05PM +0200, Paul B Mahol wrote:
> On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
> >
> > ping, please help to push the patchset.
> 
> There are typos in patch.

Sorry, I'm not native English and have no clue where it is,
so please help point out where is it?  I'll fix it or the 
commiter help to fix it directly.

Maybe the patch subject  "is" should be "as"?

> 
> >
> > On Fri, Sep 20, 2019 at 10:53:38AM +0800, lance.lmwang@gmail.com wrote:
> >> From: Limin Wang <lance.lmwang@gmail.com>
> >>
> >> Linux and OSX systems support basename and dirname via <libgen.h>, I plan
> >> to
> >> make the wrapper interface conform to the standard interface first.
> >> If it is feasible, I will continue to modify it to call the system
> >> interface
> >> if there is already a system call interface.
> >>
> >> You can get more descrioption about the system interface by below command:
> >>  "man 3 basename"
> >>
> >> Reviewed-by: Marton Balint <cus@passwd.hu>
> >> Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
> >> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
> >> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> >> ---
> >>  libavutil/avstring.c | 12 ++++++++----
> >>  libavutil/avstring.h | 13 +++++++++----
> >>  2 files changed, 17 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> >> index 4c068f5..76a13ba 100644
> >> --- a/libavutil/avstring.c
> >> +++ b/libavutil/avstring.c
> >> @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char
> >> *from, const char *to)
> >>
> >>  const char *av_basename(const char *path)
> >>  {
> >> -    char *p = strrchr(path, '/');
> >> +    char *p;
> >>
> >> +    if (!path || *path == '\0')
> >> +        return ".";
> >> +
> >> +    p = strrchr(path, '/');
> >>  #if HAVE_DOS_PATHS
> >>      char *q = strrchr(path, '\\');
> >>      char *d = strchr(path, ':');
> >> @@ -274,11 +278,11 @@ const char *av_basename(const char *path)
> >>
> >>  const char *av_dirname(char *path)
> >>  {
> >> -    char *p = strrchr(path, '/');
> >> +    char *p = path ? strrchr(path, '/') : NULL;
> >>
> >>  #if HAVE_DOS_PATHS
> >> -    char *q = strrchr(path, '\\');
> >> -    char *d = strchr(path, ':');
> >> +    char *q = path ? strrchr(path, '\\') : NULL;
> >> +    char *d = path ? strchr(path, ':')  : NULL;
> >>
> >>      d = d ? d + 1 : d;
> >>
> >> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> >> index 37dd4e2..274335c 100644
> >> --- a/libavutil/avstring.h
> >> +++ b/libavutil/avstring.h
> >> @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char
> >> *from, const char *to);
> >>
> >>  /**
> >>   * Thread safe basename.
> >> - * @param path the path, on DOS both \ and / are considered separators.
> >> + * @param path the string to parse, on DOS both \ and / are considered
> >> separators.
> >>   * @return pointer to the basename substring.
> >> + * If path does not contain a slash, the function returns a copy of path.
> >> + * If path is a NULL pointer or points to an empty string, a pointer
> >> + * to a string "." is returned.
> >>   */
> >>  const char *av_basename(const char *path);
> >>
> >>  /**
> >>   * Thread safe dirname.
> >> - * @param path the path, on DOS both \ and / are considered separators.
> >> - * @return the path with the separator replaced by the string terminator
> >> or ".".
> >> - * @note the function may change the input string.
> >> + * @param path the string to parse, on DOS both \ and / are considered
> >> separators.
> >> + * @return A pointer to a string that's the parent directory of path.
> >> + * If path is a NULL pointer or points to an empty string, a pointer
> >> + * to a string "." is returned.
> >> + * @note the function may modify the contents of the path, so copies
> >> should be passed.
> >>   */
> >>  const char *av_dirname(char *path);
> >>
> >> --
> >> 2.9.5
> >>
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Paul B Mahol Sept. 24, 2019, 11:05 a.m.
On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
> On Tue, Sep 24, 2019 at 12:33:05PM +0200, Paul B Mahol wrote:
>> On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
>> >
>> > ping, please help to push the patchset.
>>
>> There are typos in patch.
>
> Sorry, I'm not native English and have no clue where it is,
> so please help point out where is it?  I'll fix it or the
> commiter help to fix it directly.

 descrioption

>
> Maybe the patch subject  "is" should be "as"?
>
>>
>> >
>> > On Fri, Sep 20, 2019 at 10:53:38AM +0800, lance.lmwang@gmail.com wrote:
>> >> From: Limin Wang <lance.lmwang@gmail.com>
>> >>
>> >> Linux and OSX systems support basename and dirname via <libgen.h>, I
>> >> plan
>> >> to
>> >> make the wrapper interface conform to the standard interface first.
>> >> If it is feasible, I will continue to modify it to call the system
>> >> interface
>> >> if there is already a system call interface.
>> >>
>> >> You can get more descrioption about the system interface by below
>> >> command:
>> >>  "man 3 basename"
>> >>
>> >> Reviewed-by: Marton Balint <cus@passwd.hu>
>> >> Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
>> >> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
>> >> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
>> >> ---
>> >>  libavutil/avstring.c | 12 ++++++++----
>> >>  libavutil/avstring.h | 13 +++++++++----
>> >>  2 files changed, 17 insertions(+), 8 deletions(-)
>> >>
>> >> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
>> >> index 4c068f5..76a13ba 100644
>> >> --- a/libavutil/avstring.c
>> >> +++ b/libavutil/avstring.c
>> >> @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char
>> >> *from, const char *to)
>> >>
>> >>  const char *av_basename(const char *path)
>> >>  {
>> >> -    char *p = strrchr(path, '/');
>> >> +    char *p;
>> >>
>> >> +    if (!path || *path == '\0')
>> >> +        return ".";
>> >> +
>> >> +    p = strrchr(path, '/');
>> >>  #if HAVE_DOS_PATHS
>> >>      char *q = strrchr(path, '\\');
>> >>      char *d = strchr(path, ':');
>> >> @@ -274,11 +278,11 @@ const char *av_basename(const char *path)
>> >>
>> >>  const char *av_dirname(char *path)
>> >>  {
>> >> -    char *p = strrchr(path, '/');
>> >> +    char *p = path ? strrchr(path, '/') : NULL;
>> >>
>> >>  #if HAVE_DOS_PATHS
>> >> -    char *q = strrchr(path, '\\');
>> >> -    char *d = strchr(path, ':');
>> >> +    char *q = path ? strrchr(path, '\\') : NULL;
>> >> +    char *d = path ? strchr(path, ':')  : NULL;
>> >>
>> >>      d = d ? d + 1 : d;
>> >>
>> >> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
>> >> index 37dd4e2..274335c 100644
>> >> --- a/libavutil/avstring.h
>> >> +++ b/libavutil/avstring.h
>> >> @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char
>> >> *from, const char *to);
>> >>
>> >>  /**
>> >>   * Thread safe basename.
>> >> - * @param path the path, on DOS both \ and / are considered
>> >> separators.
>> >> + * @param path the string to parse, on DOS both \ and / are considered
>> >> separators.
>> >>   * @return pointer to the basename substring.
>> >> + * If path does not contain a slash, the function returns a copy of
>> >> path.
>> >> + * If path is a NULL pointer or points to an empty string, a pointer
>> >> + * to a string "." is returned.
>> >>   */
>> >>  const char *av_basename(const char *path);
>> >>
>> >>  /**
>> >>   * Thread safe dirname.
>> >> - * @param path the path, on DOS both \ and / are considered
>> >> separators.
>> >> - * @return the path with the separator replaced by the string
>> >> terminator
>> >> or ".".
>> >> - * @note the function may change the input string.
>> >> + * @param path the string to parse, on DOS both \ and / are considered
>> >> separators.
>> >> + * @return A pointer to a string that's the parent directory of path.
>> >> + * If path is a NULL pointer or points to an empty string, a pointer
>> >> + * to a string "." is returned.
>> >> + * @note the function may modify the contents of the path, so copies
>> >> should be passed.
>> >>   */
>> >>  const char *av_dirname(char *path);
>> >>
>> >> --
>> >> 2.9.5
>> >>
>> > _______________________________________________
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel@ffmpeg.org
>> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> >
>> > To unsubscribe, visit link above, or email
>> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
lance.lmwang@gmail.com Sept. 24, 2019, 11:10 a.m.
On Tue, Sep 24, 2019 at 01:05:41PM +0200, Paul B Mahol wrote:
> On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
> > On Tue, Sep 24, 2019 at 12:33:05PM +0200, Paul B Mahol wrote:
> >> On 9/24/19, Limin Wang <lance.lmwang@gmail.com> wrote:
> >> >
> >> > ping, please help to push the patchset.
> >>
> >> There are typos in patch.
> >
> > Sorry, I'm not native English and have no clue where it is,
> > so please help point out where is it?  I'll fix it or the
> > commiter help to fix it directly.
> 
>  descrioption
Oh, it's true. I'll update to fix it. Thanks you.
> 
> >
> > Maybe the patch subject  "is" should be "as"?
> >
> >>
> >> >
> >> > On Fri, Sep 20, 2019 at 10:53:38AM +0800, lance.lmwang@gmail.com wrote:
> >> >> From: Limin Wang <lance.lmwang@gmail.com>
> >> >>
> >> >> Linux and OSX systems support basename and dirname via <libgen.h>, I
> >> >> plan
> >> >> to
> >> >> make the wrapper interface conform to the standard interface first.
> >> >> If it is feasible, I will continue to modify it to call the system
> >> >> interface
> >> >> if there is already a system call interface.
> >> >>
> >> >> You can get more descrioption about the system interface by below
> >> >> command:
> >> >>  "man 3 basename"
> >> >>
> >> >> Reviewed-by: Marton Balint <cus@passwd.hu>
> >> >> Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
> >> >> Reviewed-by: Liu Steven <lq@chinaffmpeg.org>
> >> >> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> >> >> ---
> >> >>  libavutil/avstring.c | 12 ++++++++----
> >> >>  libavutil/avstring.h | 13 +++++++++----
> >> >>  2 files changed, 17 insertions(+), 8 deletions(-)
> >> >>
> >> >> diff --git a/libavutil/avstring.c b/libavutil/avstring.c
> >> >> index 4c068f5..76a13ba 100644
> >> >> --- a/libavutil/avstring.c
> >> >> +++ b/libavutil/avstring.c
> >> >> @@ -257,8 +257,12 @@ char *av_strireplace(const char *str, const char
> >> >> *from, const char *to)
> >> >>
> >> >>  const char *av_basename(const char *path)
> >> >>  {
> >> >> -    char *p = strrchr(path, '/');
> >> >> +    char *p;
> >> >>
> >> >> +    if (!path || *path == '\0')
> >> >> +        return ".";
> >> >> +
> >> >> +    p = strrchr(path, '/');
> >> >>  #if HAVE_DOS_PATHS
> >> >>      char *q = strrchr(path, '\\');
> >> >>      char *d = strchr(path, ':');
> >> >> @@ -274,11 +278,11 @@ const char *av_basename(const char *path)
> >> >>
> >> >>  const char *av_dirname(char *path)
> >> >>  {
> >> >> -    char *p = strrchr(path, '/');
> >> >> +    char *p = path ? strrchr(path, '/') : NULL;
> >> >>
> >> >>  #if HAVE_DOS_PATHS
> >> >> -    char *q = strrchr(path, '\\');
> >> >> -    char *d = strchr(path, ':');
> >> >> +    char *q = path ? strrchr(path, '\\') : NULL;
> >> >> +    char *d = path ? strchr(path, ':')  : NULL;
> >> >>
> >> >>      d = d ? d + 1 : d;
> >> >>
> >> >> diff --git a/libavutil/avstring.h b/libavutil/avstring.h
> >> >> index 37dd4e2..274335c 100644
> >> >> --- a/libavutil/avstring.h
> >> >> +++ b/libavutil/avstring.h
> >> >> @@ -274,16 +274,21 @@ char *av_strireplace(const char *str, const char
> >> >> *from, const char *to);
> >> >>
> >> >>  /**
> >> >>   * Thread safe basename.
> >> >> - * @param path the path, on DOS both \ and / are considered
> >> >> separators.
> >> >> + * @param path the string to parse, on DOS both \ and / are considered
> >> >> separators.
> >> >>   * @return pointer to the basename substring.
> >> >> + * If path does not contain a slash, the function returns a copy of
> >> >> path.
> >> >> + * If path is a NULL pointer or points to an empty string, a pointer
> >> >> + * to a string "." is returned.
> >> >>   */
> >> >>  const char *av_basename(const char *path);
> >> >>
> >> >>  /**
> >> >>   * Thread safe dirname.
> >> >> - * @param path the path, on DOS both \ and / are considered
> >> >> separators.
> >> >> - * @return the path with the separator replaced by the string
> >> >> terminator
> >> >> or ".".
> >> >> - * @note the function may change the input string.
> >> >> + * @param path the string to parse, on DOS both \ and / are considered
> >> >> separators.
> >> >> + * @return A pointer to a string that's the parent directory of path.
> >> >> + * If path is a NULL pointer or points to an empty string, a pointer
> >> >> + * to a string "." is returned.
> >> >> + * @note the function may modify the contents of the path, so copies
> >> >> should be passed.
> >> >>   */
> >> >>  const char *av_dirname(char *path);
> >> >>
> >> >> --
> >> >> 2.9.5
> >> >>
> >> > _______________________________________________
> >> > ffmpeg-devel mailing list
> >> > ffmpeg-devel@ffmpeg.org
> >> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >> >
> >> > To unsubscribe, visit link above, or email
> >> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Patch hide | download patch | download mbox

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 4c068f5..76a13ba 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -257,8 +257,12 @@  char *av_strireplace(const char *str, const char *from, const char *to)
 
 const char *av_basename(const char *path)
 {
-    char *p = strrchr(path, '/');
+    char *p;
 
+    if (!path || *path == '\0')
+        return ".";
+
+    p = strrchr(path, '/');
 #if HAVE_DOS_PATHS
     char *q = strrchr(path, '\\');
     char *d = strchr(path, ':');
@@ -274,11 +278,11 @@  const char *av_basename(const char *path)
 
 const char *av_dirname(char *path)
 {
-    char *p = strrchr(path, '/');
+    char *p = path ? strrchr(path, '/') : NULL;
 
 #if HAVE_DOS_PATHS
-    char *q = strrchr(path, '\\');
-    char *d = strchr(path, ':');
+    char *q = path ? strrchr(path, '\\') : NULL;
+    char *d = path ? strchr(path, ':')  : NULL;
 
     d = d ? d + 1 : d;
 
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index 37dd4e2..274335c 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -274,16 +274,21 @@  char *av_strireplace(const char *str, const char *from, const char *to);
 
 /**
  * Thread safe basename.
- * @param path the path, on DOS both \ and / are considered separators.
+ * @param path the string to parse, on DOS both \ and / are considered separators.
  * @return pointer to the basename substring.
+ * If path does not contain a slash, the function returns a copy of path.
+ * If path is a NULL pointer or points to an empty string, a pointer
+ * to a string "." is returned.
  */
 const char *av_basename(const char *path);
 
 /**
  * Thread safe dirname.
- * @param path the path, on DOS both \ and / are considered separators.
- * @return the path with the separator replaced by the string terminator or ".".
- * @note the function may change the input string.
+ * @param path the string to parse, on DOS both \ and / are considered separators.
+ * @return A pointer to a string that's the parent directory of path.
+ * If path is a NULL pointer or points to an empty string, a pointer
+ * to a string "." is returned.
+ * @note the function may modify the contents of the path, so copies should be passed.
  */
 const char *av_dirname(char *path);