[FFmpeg-devel,v2,2/2] avutil/avstring: replace with system interface if dirname and basename functions are detected

Submitted by lance.lmwang@gmail.com on Oct. 9, 2019, 9:10 a.m.

Details

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

Commit Message

lance.lmwang@gmail.com Oct. 9, 2019, 9:10 a.m.
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 configure            |  4 ++++
 libavutil/avstring.c | 13 ++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/configure b/configure
index 8413826..5296a4c 100755
--- a/configure
+++ b/configure
@@ -2188,6 +2188,8 @@  SYSTEM_FUNCS="
     clock_gettime
     closesocket
     CommandLineToArgvW
+    dirname
+    basename
     fcntl
     getaddrinfo
     gethrtime
@@ -5980,6 +5982,8 @@  check_func  access
 check_func_headers stdlib.h arc4random
 check_lib   clock_gettime time.h clock_gettime || check_lib clock_gettime time.h clock_gettime -lrt
 check_func  fcntl
+check_func_headers libgen.h dirname
+check_func_headers libgen.h basename
 check_func  fork
 check_func  gethrtime
 check_func  getopt
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 76a13ba..66654fb 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -19,12 +19,15 @@ 
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include <stdarg.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#if defined(HAVE_DIRNAME) || defined(HAVE_BASENAME)
+#include <libgen.h>
+#endif
 
-#include "config.h"
 #include "common.h"
 #include "mem.h"
 #include "avassert.h"
@@ -257,6 +260,9 @@  char *av_strireplace(const char *str, const char *from, const char *to)
 
 const char *av_basename(const char *path)
 {
+#if HAVE_BASENAME
+    return  basename((char*)path);
+#else
     char *p;
 
     if (!path || *path == '\0')
@@ -274,10 +280,14 @@  const char *av_basename(const char *path)
         return path;
 
     return p + 1;
+#endif
 }
 
 const char *av_dirname(char *path)
 {
+#if HAVE_DIRNAME
+    return dirname(path);
+#else
     char *p = path ? strrchr(path, '/') : NULL;
 
 #if HAVE_DOS_PATHS
@@ -295,6 +305,7 @@  const char *av_dirname(char *path)
     *p = '\0';
 
     return path;
+#endif
 }
 
 char *av_append_path_component(const char *path, const char *component)