diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-08-09 17:27:35 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-08-09 17:30:15 -0700 |
commit | 3886467f386732598647a2d3209777ba8d8d7baa (patch) | |
tree | cc240f735afa1073dbdc0bb442f015d358ff7a0c /src/common/compat.c | |
parent | 6423091f071dc7c843d0fd02ac32b880b7754b24 (diff) | |
download | tor-3886467f386732598647a2d3209777ba8d8d7baa.tar.gz tor-3886467f386732598647a2d3209777ba8d8d7baa.zip |
Add a new tor_strtok_r for platforms that don't have one, plus tests.
I don't think we actually use (or plan to use) strtok_r in a reentrant
way anywhere in our code, but would be nice not to have to think about
whether we're doing it.
Diffstat (limited to 'src/common/compat.c')
-rw-r--r-- | src/common/compat.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index d62b1ce1f4..29425c2492 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -398,6 +398,37 @@ const char TOR_TOLOWER_TABLE[256] = { 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, }; +/** Implementation of strtok_r for platforms whose coders haven't figured out + * how to write one. Hey guys! You can use this code here for free! */ +char * +tor_strtok_r_impl(char *str, const char *sep, char **lasts) +{ + char *cp, *start; + if (str) + start = cp = *lasts = str; + else if (!*lasts) + return NULL; + else + start = cp = *lasts; + + tor_assert(*sep); + if (sep[1]) { + while (*cp && !strchr(sep, *cp)) + ++cp; + } else { + tor_assert(strlen(sep) == 1); + cp = strchr(cp, *sep); + } + + if (!cp || !*cp) { + *lasts = NULL; + } else { + *cp++ = '\0'; + *lasts = cp; + } + return start; +} + #ifdef MS_WINDOWS /** Take a filename and return a pointer to its final element. This * function is called on __FILE__ to fix a MSVC nit where __FILE__ |