@@ -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
@@ -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)