From 0161be992edc39ba8d11d34e8d33ef2588a7bf6d Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 1 Jul 2014 23:39:22 -0500 Subject: [PATCH] bsdstubs: add strtok_r() from musl if unavailable on a platform (closes #66) --- bsdstubs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ bsdstubs.h | 4 ++++ configure.ac | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bsdstubs.c b/bsdstubs.c index 66e9f92..178102d 100644 --- a/bsdstubs.c +++ b/bsdstubs.c @@ -125,3 +125,45 @@ char *strndup(const char *src, size_t len) } #endif + +#ifndef HAVE_STRTOK_R +/* + * Copyright (c) 2005-2014 Rich Felker + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +char *strtok_r(char *s, const char *sep, char **p) +{ + if (!s && !(s = *p)) + return NULL; + + s += strspn(s, sep); + if (!*s) + return *p = 0; + *p = s + strcspn(s, sep); + + if (**p) + *(*p)++ = 0; + else + *p = 0; + return s; +} +#endif diff --git a/bsdstubs.h b/bsdstubs.h index 629cd5f..2cd9e29 100644 --- a/bsdstubs.h +++ b/bsdstubs.h @@ -31,4 +31,8 @@ extern size_t strlcat(char *dst, const char *src, size_t siz); extern char *strndup(const char *src, size_t len); #endif +#ifndef HAVE_STRTOK_R +extern char *strtok_r(char *s, const char *sep, char **p); +#endif + #endif diff --git a/configure.ac b/configure.ac index 3068996..9ee65aa 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ AC_PREREQ([2.68]) AC_INIT([pkgconf], [0.9.6], [http://github.com/pkgconf/pkgconf/issues]) AC_CONFIG_SRCDIR([pkg.c]) AC_CONFIG_HEADERS([config.h]) -AC_CHECK_FUNCS([strlcpy strlcat strndup]) +AC_CHECK_FUNCS([strlcpy strlcat strndup strtok_r]) AC_ARG_ENABLE([strict],