From: hno <> Date: Tue, 22 Jan 2008 22:34:27 +0000 (+0000) Subject: Use our own strwordtok instead of strtok_r. Not only is it portable, but also underst... X-Git-Tag: BASIC_TPROXY4~164 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=659491857008e9607e1aa99866ecb152f210a762;p=thirdparty%2Fsquid.git Use our own strwordtok instead of strtok_r. Not only is it portable, but also understands quoting and escaping --- diff --git a/configure.in b/configure.in index 824dbf0f2d..fbeb6ecc09 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ dnl Configuration input file for Squid dnl -dnl $Id: configure.in,v 1.495 2008/01/18 07:04:16 amosjeffries Exp $ +dnl $Id: configure.in,v 1.496 2008/01/22 15:34:27 hno Exp $ dnl dnl dnl @@ -11,7 +11,7 @@ AM_CONFIG_HEADER(include/autoconf.h) AC_CONFIG_AUX_DIR(cfgaux) AC_CONFIG_SRCDIR([src/main.cc]) AM_INIT_AUTOMAKE([tar-ustar]) -AC_REVISION($Revision: 1.495 $)dnl +AC_REVISION($Revision: 1.496 $)dnl AC_PREFIX_DEFAULT(/usr/local/squid) AM_MAINTAINER_MODE @@ -2619,7 +2619,6 @@ AC_REPLACE_FUNCS(\ getaddrinfo \ getnameinfo \ strerror \ - strtok_r \ tempnam \ ) diff --git a/include/strtok_r.h b/include/strtok_r.h deleted file mode 100644 index 59bb2c4af3..0000000000 --- a/include/strtok_r.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Split string into tokens - Copyright (C) 2004-2005 Free Software Foundation, Inc. - Written by Simon Josefsson. - - 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef STRTOK_R_H -#define STRTOK_R_H - -/* Get strtok_r declaration, if available. */ -#include - -/* 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" - - This is a variant of strtok() that is multithread-safe. - - For the POSIX documentation for this function, see: - http://www.opengroup.org/susv3xsh/strtok.html - - Caveat: It modifies the original string. - Caveat: These functions cannot be used on constant strings. - Caveat: The identity of the delimiting character is lost. - Caveat: It doesn't work with multibyte strings unless all of the delimiter - characters are ASCII characters < 0x30. - - See also strsep(). -*/ -SQUIDCEXTERN char *strtok_r(char *s, const char *sep, char **lasts); - -#endif /* STRTOK_R_H */ diff --git a/lib/strtok_r.c b/lib/strtok_r.c deleted file mode 100644 index e06600db1d..0000000000 --- a/lib/strtok_r.c +++ /dev/null @@ -1,74 +0,0 @@ -/* Reentrant string tokenizer. Generic version. - Copyright (C) 1991,1996-1999,2001,2004 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 2, 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, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#undef strtok_r -#undef __strtok_r - -#ifndef _LIBC -/* Get specification. */ -# include "strtok_r.h" -# 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; -} diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 300005bb47..5b419f1996 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.537 2008/01/19 07:11:34 amosjeffries Exp $ + * $Id: cache_cf.cc,v 1.538 2008/01/22 15:34:28 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -210,10 +210,10 @@ parseManyConfigFiles(char* files, int depth) { int error_count = 0; char* saveptr = NULL; - char* file = strtok_r(files, w_space, &saveptr); + char* file = strwordtok(files, &saveptr); while (file != NULL) { error_count += parseOneConfigFile(file, depth); - file = strtok_r(NULL, w_space, &saveptr); + file = strwordtok(NULL, &saveptr); } return error_count; } diff --git a/src/squid.h b/src/squid.h index 9932e0d3a7..646917cea6 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.270 2008/01/20 17:11:15 serassio Exp $ + * $Id: squid.h,v 1.271 2008/01/22 15:34:28 hno Exp $ * * AUTHOR: Duane Wessels * @@ -388,10 +388,6 @@ extern "C" #include "strtoll.h" #endif -#if !HAVE_STRTOK_R -#include "strtok_r.h" -#endif - #if !HAVE_INITGROUPS #include "initgroups.h" #endif