summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-01-27 22:37:03 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-01-27 22:37:03 +0100
commit63e14992cdc710f3322f205485efb3aad4c6465f (patch)
tree8bc15ad2eb1da6225e10a3a20260b84761324055
parent96a1ad7b7d57655f10433b05589a1d558197253b (diff)
downloadgnutls-63e14992cdc710f3322f205485efb3aad4c6465f.tar.gz
Added strtok_r.
-rw-r--r--gl/Makefile.am11
-rw-r--r--gl/m4/gnulib-cache.m43
-rw-r--r--gl/m4/gnulib-comp.m49
-rw-r--r--gl/m4/strtok_r.m474
-rw-r--r--gl/strtok_r.c76
5 files changed, 171 insertions, 2 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 7cd0816c03..1da9139353 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close connect error extensions func gendocs getaddrinfo getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close connect error extensions func gendocs getaddrinfo getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strtok_r strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings
AUTOMAKE_OPTIONS = 1.5 gnits
@@ -1886,6 +1886,15 @@ EXTRA_libgnu_la_SOURCES += strnlen.c
## end gnulib module strnlen
+## begin gnulib module strtok_r
+
+
+EXTRA_DIST += strtok_r.c
+
+EXTRA_libgnu_la_SOURCES += strtok_r.c
+
+## end gnulib module strtok_r
+
## begin gnulib module strverscmp
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 337e9db63a..4c8191678e 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -27,7 +27,7 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close connect error extensions func gendocs getaddrinfo getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings
+# gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lock-tests --avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alloca alphasort argp base64 bind byteswap c-ctype close connect error extensions func gendocs getaddrinfo getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple minmax netdb netinet_in pmccabe2html progname read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf socket sockets socklen stdint strcase strtok_r strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf warnings
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gl/override])
@@ -80,6 +80,7 @@ gl_MODULES([
socklen
stdint
strcase
+ strtok_r
strverscmp
sys_socket
sys_stat
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 8736550d5c..599aae65fd 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -289,6 +289,7 @@ AC_DEFUN([gl_EARLY],
# Code from module strndup:
# Code from module strnlen:
# Code from module strnlen-tests:
+ # Code from module strtok_r:
# Code from module strverscmp:
# Code from module strverscmp-tests:
# Code from module symlink:
@@ -780,6 +781,12 @@ if test $HAVE_DECL_STRNLEN = 0 || test $REPLACE_STRNLEN = 1; then
gl_PREREQ_STRNLEN
fi
gl_STRING_MODULE_INDICATOR([strnlen])
+gl_FUNC_STRTOK_R
+if test $HAVE_STRTOK_R = 0 || test $REPLACE_STRTOK_R = 1; then
+ AC_LIBOBJ([strtok_r])
+ gl_PREREQ_STRTOK_R
+fi
+gl_STRING_MODULE_INDICATOR([strtok_r])
gl_FUNC_STRVERSCMP
if test $HAVE_STRVERSCMP = 0; then
AC_LIBOBJ([strverscmp])
@@ -1260,6 +1267,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/strncasecmp.c
lib/strndup.c
lib/strnlen.c
+ lib/strtok_r.c
lib/strverscmp.c
lib/sys_select.in.h
lib/sys_socket.in.h
@@ -1432,6 +1440,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/strings_h.m4
m4/strndup.m4
m4/strnlen.m4
+ m4/strtok_r.m4
m4/strverscmp.m4
m4/symlink.m4
m4/sys_ioctl_h.m4
diff --git a/gl/m4/strtok_r.m4 b/gl/m4/strtok_r.m4
new file mode 100644
index 0000000000..60e33a695f
--- /dev/null
+++ b/gl/m4/strtok_r.m4
@@ -0,0 +1,74 @@
+# strtok_r.m4 serial 13
+dnl Copyright (C) 2002-2004, 2006-2007, 2009-2012 Free Software Foundation,
+dnl Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STRTOK_R],
+[
+ dnl The strtok_r() declaration in lib/string.in.h uses 'restrict'.
+ AC_REQUIRE([AC_C_RESTRICT])
+
+ AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CHECK_FUNCS([strtok_r])
+ if test $ac_cv_func_strtok_r = yes; then
+ HAVE_STRTOK_R=1
+ dnl glibc 2.7 has a bug in strtok_r that causes a segmentation fault
+ dnl when the second argument to strtok_r is a constant string that has
+ dnl exactly one byte and compiling with optimization. This bug is, for
+ dnl example, present in the glibc 2.7-18 package in Debian "lenny".
+ dnl See <http://sources.redhat.com/bugzilla/show_bug.cgi?id=5614>.
+ AC_CACHE_CHECK([whether strtok_r works], [gl_cv_func_strtok_r_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[
+ #ifndef __OPTIMIZE__
+ # define __OPTIMIZE__ 1
+ #endif
+ #undef __OPTIMIZE_SIZE__
+ #undef __NO_INLINE__
+ #include <stdlib.h>
+ #include <string.h>
+ ]],
+ [[static const char dummy[] = "\177\01a";
+ char delimiters[] = "xxxxxxxx";
+ char *save_ptr = (char *) dummy;
+ strtok_r (delimiters, "x", &save_ptr);
+ strtok_r (NULL, "x", &save_ptr);
+ return 0;
+ ]])
+ ],
+ [gl_cv_func_strtok_r_works=yes],
+ [gl_cv_func_strtok_r_works=no],
+ [
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on glibc systems.
+ *-gnu*) gl_cv_func_strtok_r_works="guessing no";;
+ *) gl_cv_func_strtok_r_works="guessing yes";;
+ esac
+changequote([,])dnl
+ ])
+ ])
+ case "$gl_cv_func_strtok_r_works" in
+ *no)
+ dnl We could set REPLACE_STRTOK_R=1 here, but it's only the macro
+ dnl version in <bits/string2.h> which is wrong. The code compiled
+ dnl into libc is fine.
+ UNDEFINE_STRTOK_R=1
+ ;;
+ esac
+ else
+ HAVE_STRTOK_R=0
+ fi
+ AC_CHECK_DECLS_ONCE([strtok_r])
+ if test $ac_cv_have_decl_strtok_r = no; then
+ HAVE_DECL_STRTOK_R=0
+ fi
+])
+
+# Prerequisites of lib/strtok_r.c.
+AC_DEFUN([gl_PREREQ_STRTOK_R], [
+ :
+])
diff --git a/gl/strtok_r.c b/gl/strtok_r.c
new file mode 100644
index 0000000000..e1499bcefa
--- /dev/null
+++ b/gl/strtok_r.c
@@ -0,0 +1,76 @@
+/* Reentrant string tokenizer. Generic version.
+ Copyright (C) 1991, 1996-1999, 2001, 2004, 2007, 2009-2012 Free Software
+ Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#ifdef _LIBC
+# undef strtok_r
+# undef __strtok_r
+#else
+# define __strtok_r strtok_r
+# define __rawmemchr strchr
+#endif
+
+/* Parse S into tokens separated by characters in DELIM.
+ If S is NULL, the saved pointer in SAVE_PTR is used as
+ the next starting point. For example:
+ char s[] = "-abc-=-def";
+ char *sp;
+ x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
+ x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
+ x = strtok_r(NULL, "=", &sp); // x = NULL
+ // s = "abc\0-def\0"
+*/
+char *
+__strtok_r (char *s, const char *delim, char **save_ptr)
+{
+ char *token;
+
+ if (s == NULL)
+ s = *save_ptr;
+
+ /* Scan leading delimiters. */
+ s += strspn (s, delim);
+ if (*s == '\0')
+ {
+ *save_ptr = s;
+ return NULL;
+ }
+
+ /* Find the end of the token. */
+ token = s;
+ s = strpbrk (token, delim);
+ if (s == NULL)
+ /* This token finishes the string. */
+ *save_ptr = __rawmemchr (token, '\0');
+ else
+ {
+ /* Terminate the token and make *SAVE_PTR point past it. */
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+ return token;
+}
+#ifdef weak_alias
+libc_hidden_def (__strtok_r)
+weak_alias (__strtok_r, strtok_r)
+#endif