[FFmpeg-devel] [PATCH v3 3/3] avutil/avstring: replace with system interface if dirname and basename functions are detected
lance.lmwang at gmail.com
lance.lmwang at gmail.com
Wed Oct 23 18:55:17 EEST 2019
From: Limin Wang <lance.lmwang at gmail.com>
Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
configure | 4 ++++
libavutil/avstring.c | 13 ++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
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)
--
2.6.4
More information about the ffmpeg-devel
mailing list