summaryrefslogtreecommitdiff
path: root/libavutil/avstring.c
diff options
context:
space:
mode:
authorLimin Wang <lance.lmwang@gmail.com>2019-09-24 19:23:58 +0800
committerSteven Liu <lq@chinaffmpeg.org>2019-10-08 14:12:43 +0800
commita77fb510c2684a43980c79ff85ff36e094cae63c (patch)
tree7b1878c4e9ae07bab2f2032ac15a3000be6579e2 /libavutil/avstring.c
parent985ed65117c7c82255bb0931442725aa6e5f6967 (diff)
downloadffmpeg-a77fb510c2684a43980c79ff85ff36e094cae63c.tar.gz
avutil/avstring: support input path as a null pointer or empty string
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 description 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: Steven Liu <lq@chinaffmpeg.org> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
Diffstat (limited to 'libavutil/avstring.c')
-rw-r--r--libavutil/avstring.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 4c068f5bc5..76a13ba3b5 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;