diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2012-12-23 21:25:24 +0100 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2012-12-29 17:26:22 +0100 |
commit | d8fd06c37de94d78eb37af93177de7c3040cf1f2 (patch) | |
tree | 6505d5945220cc9541c2302a83ac4641f4238491 /libavutil/avstring.c | |
parent | c73c87b41298ff81b5a86569b0f680a556fc1a21 (diff) | |
download | ffmpeg-d8fd06c37de94d78eb37af93177de7c3040cf1f2.tar.gz |
avstring: add av_basename and av_dirname
Thread safe version of the common basename and dirname.
Diffstat (limited to 'libavutil/avstring.c')
-rw-r--r-- | libavutil/avstring.c | 41 |
1 files changed, 41 insertions, 0 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" |