aboutsummaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/avstring.c41
-rw-r--r--libavutil/avstring.h16
-rw-r--r--libavutil/version.h2
3 files changed, 58 insertions, 1 deletions
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index c14832e7b9..2c88bd3d5b 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -25,6 +25,8 @@
#include <string.h>
#include <ctype.h>
#include "avstring.h"
+#include "config.h"
+#include "common.h"
#include "mem.h"
int av_strstart(const char *str, const char *pfx, const char **ptr)
@@ -156,6 +158,45 @@ int av_strncasecmp(const char *a, const char *b, size_t n)
return c1 - c2;
}
+const char *av_basename(const char *path)
+{
+ char *p = strrchr(path, '/');
+
+#if HAVE_DOS_PATHS
+ char *q = strrchr(path, '\\');
+ char *d = strchr(path, ':');
+
+ p = FFMAX3(p, q, d);
+#endif
+
+ if (!p)
+ return path;
+
+ return p + 1;
+}
+
+const char *av_dirname(char *path)
+{
+ char *p = strrchr(path, '/');
+
+#if HAVE_DOS_PATHS
+ char *q = strrchr(path, '\\');
+ char *d = strchr(path, ':');
+
+ d = d ? d + 1 : d;
+
+ p = FFMAX3(p, q, d);
+#endif
+
+ if (!p)
+ return ".";
+
+ *p = '\0';
+
+ return path;
+}
+
+
#ifdef TEST
#include "common.h"
diff --git a/libavutil/avstring.h b/libavutil/avstring.h
index ed4e465cbc..acd6610d38 100644
--- a/libavutil/avstring.h
+++ b/libavutil/avstring.h
@@ -168,6 +168,22 @@ int av_strcasecmp(const char *a, const char *b);
*/
int av_strncasecmp(const char *a, const char *b, size_t n);
+
+/**
+ * Thread safe basename.
+ * @param path the path, on DOS both \ and / are considered separators.
+ * @return pointer to the basename substring.
+ */
+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.
+ */
+const char *av_dirname(char *path);
+
/**
* @}
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index f69c73e929..1dbb11ca21 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -37,7 +37,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 2
+#define LIBAVUTIL_VERSION_MINOR 3
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \