1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-11-29 05:57:37 +02:00

lavu: add av_strtok()

The function strtok_r() is part of the POSIX.1 specification, but is not
available on some platforms. We provide an internal implementation, so we
do not need to rely on a platform implementation.
This commit is contained in:
Stefano Sabatini
2011-10-15 00:14:37 +02:00
parent 88bdf7471f
commit b35e9e19e9
7 changed files with 64 additions and 14 deletions

View File

@@ -160,6 +160,35 @@ char *av_get_token(const char **buf, const char *term)
return ret;
}
char *av_strtok(char *s, const char *delim, char **saveptr)
{
char *tok;
if (!s && !(s = *saveptr))
return NULL;
/* skip leading delimiters */
s += strspn(s, delim);
/* s now points to the first non delimiter char, or to the end of the string */
if (!*s) {
*saveptr = NULL;
return NULL;
}
tok = s++;
/* skip non delimiters */
s += strcspn(s, delim);
if (*s) {
*s = 0;
*saveptr = s+1;
} else {
*saveptr = NULL;
}
return tok;
}
#ifdef TEST
#undef printf