]> git.sesse.net Git - ffmpeg/commitdiff
avstring: add av_basename and av_dirname
authorLuca Barbato <lu_zero@gentoo.org>
Sun, 23 Dec 2012 20:25:24 +0000 (21:25 +0100)
committerLuca Barbato <lu_zero@gentoo.org>
Sat, 29 Dec 2012 16:26:22 +0000 (17:26 +0100)
Thread safe version of the common basename and dirname.

Changelog
doc/APIchanges
libavutil/avstring.c
libavutil/avstring.h
libavutil/version.h

index 8dfffcfcd69189643920bf95155033a0e3c6d928..b5950219a3536adf44c6f7c664f9fd96d09fefe7 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,9 @@ Entries are sorted chronologically from oldest to youngest within each release,
 releases are sorted from youngest to oldest.
 
 version <next>:
+- av_basename and av_dirname
+
+version 9_beta3:
 - ashowinfo audio filter
 - 24-bit FLAC encoding
 - audio volume filter
index 1c6247ef56391b9d2564952ae317fc3013dc93c2..a5a0bea1fcc92c8c2f1c3c87b637240791bdf374 100644 (file)
@@ -13,6 +13,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2012-xx-xx - xxxxxxx - lavu 52.2.1 - avstring.h
+  Add av_basename() and av_dirname().
+
 2012-xx-xx - xxxxxxx - lavu 52.2.0 - audioconvert.h
   Rename audioconvert.h to channel_layout.h. audioconvert.h is now deprecated.
 
index c14832e7b99a38f9875c769049f017be4f1d1711..2c88bd3d5b300c2172abe7729f3c40ade420f30d 100644 (file)
@@ -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"
index ed4e465cbce749564706469fa417d764cd824d6e..acd6610d38fc0998fcfe4f1bab4f92ad50ddc7cd 100644 (file)
@@ -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);
+
 /**
  * @}
  */
index f69c73e929c17b03e720ee09fd3d7370ef512f1a..1dbb11ca21e8e3484e7e1cdb2e1373fd0358bd90 100644 (file)
@@ -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, \