mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-01-06 14:15:29 +01:00
avstring: add av_basename and av_dirname
Thread safe version of the common basename and dirname.
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user