From: Sascha Schumann Date: Fri, 26 Nov 1999 17:33:53 +0000 (+0000) Subject: - move strtok_r into reentrancy.c X-Git-Tag: PRE_RETURN_REF_PATCH~232 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=524f0b1b0ab408777d16002a5909f0cfc9e9d58b;p=php - move strtok_r into reentrancy.c - add rand_r() --- diff --git a/Makefile.am b/Makefile.am index 8fb1b5e82b..4007b242dd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,7 +11,7 @@ libphp4_la_SOURCES = \ configuration-parser.y configuration-scanner.l request_info.c \ safe_mode.c fopen-wrappers.c php3_realpath.c alloca.c \ php_ini.c SAPI.c rfc1867.c dlist.c php_content_types.c strlcpy.c \ - strlcat.c mergesort.c strtok_r.c reentrancy.c + strlcat.c mergesort.c reentrancy.c libphp4_la_DEPENDENCIES = \ libzend/libzend.la \ diff --git a/configure.in b/configure.in index ec309aa053..2529264452 100644 --- a/configure.in +++ b/configure.in @@ -312,6 +312,7 @@ memmove \ mmap \ putenv \ random \ +rand_r \ regcomp \ rint \ setitimer \ @@ -330,6 +331,7 @@ strdup \ strerror \ strftime \ strstr \ +strtok_r \ symlink \ tempnam \ tzset \ @@ -339,7 +341,7 @@ utime \ vsnprintf \ ) -AC_REPLACE_FUNCS(strlcat strlcpy strtok_r getopt) +AC_REPLACE_FUNCS(strlcat strlcpy getopt) AC_FUNC_UTIME_NULL AC_FUNC_ALLOCA dnl## OLDLIBS=$LIBS; LIBS="" diff --git a/main/php_reentrancy.h b/main/php_reentrancy.h index eaf5e37751..4e7aad2441 100644 --- a/main/php_reentrancy.h +++ b/main/php_reentrancy.h @@ -60,8 +60,21 @@ char *asctime_r(const struct tm *tm, char *buf); struct tm *gmtime_r(const time_t *const timep, struct tm *p_tm); #endif +#if !defined(HAVE_STRTOK_R) +#define strtok_r php_strtok_r +char *strtok_r(char *s, const char *delim, char **last); +#endif + +#if !defined(HAVE_RAND_R) +#define rand_r php_rand_r +int rand_r(unsigned int *seed); +#endif + +#if !defined(ZTS) +#undef PHP_NEED_REENTRANCY +#endif -#if defined(ZTS) && defined(PHP_NEED_REENTRANCY) +#if defined(PHP_NEED_REENTRANCY) void reentrancy_startup(void); void reentrancy_shutdown(void); #else diff --git a/main/reentrancy.c b/main/reentrancy.c index b04ea475fa..ef597165ed 100644 --- a/main/reentrancy.c +++ b/main/reentrancy.c @@ -28,7 +28,6 @@ enum { NUMBER_OF_LOCKS }; - #if defined(ZTS) #include @@ -118,7 +117,7 @@ struct tm *gmtime_r(const time_t *const timep, struct tm *p_tm) #endif -#if defined(PHP_NEED_REENTRANCY) && defined(ZTS) +#if defined(PHP_NEED_REENTRANCY) void reentrancy_shutdown(void) { @@ -139,3 +138,173 @@ void reentrancy_shutdown(void) } #endif + +#ifndef HAVE_RAND_R + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Posix rand_r function added May 1999 by Wes Peters . + */ + +#include +#include + +static int +do_rand(unsigned long *ctx) +{ + return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)RAND_MAX + 1)); +} + + +int +rand_r(unsigned int *ctx) +{ + u_long val = (u_long) *ctx; + *ctx = do_rand(&val); + return (int) *ctx; +} + +#endif + + +#ifndef HAVE_STRTOK_R + +/* + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notices, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notices, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * + * This product includes software developed by Softweyr LLC, the + * University of California, Berkeley, and its contributors. + * + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE + * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +char * +strtok_r(char *s, const char *delim, char **last) +{ + char *spanp; + int c, sc; + char *tok; + + if (s == NULL && (s = *last) == NULL) + { + return NULL; + } + + /* + * Skip (span) leading delimiters (s += strspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = (char *)delim; (sc = *spanp++) != 0; ) + { + if (c == sc) + { + goto cont; + } + } + + if (c == 0) /* no non-delimiter characters */ + { + *last = NULL; + return NULL; + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) + { + c = *s++; + spanp = (char *)delim; + do + { + if ((sc = *spanp++) == c) + { + if (c == 0) + { + s = NULL; + } + else + { + char *w = s - 1; + *w = '\0'; + } + *last = s; + return tok; + } + } + while (sc != 0); + } + /* NOTREACHED */ +} + +#endif diff --git a/strtok_r.c b/strtok_r.c deleted file mode 100644 index 76e33a4f1c..0000000000 --- a/strtok_r.c +++ /dev/null @@ -1,113 +0,0 @@ -#include "php_config.h" - -#ifndef HAVE_STRTOK_R - -/* - * Copyright (c) 1998 Softweyr LLC. All rights reserved. - * - * strtok_r, from Berkeley strtok - * Oct 13, 1998 by Wes Peters - * - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notices, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notices, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Softweyr LLC, the - * University of California, Berkeley, and its contributors. - * - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE - * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -char * -strtok_r(char *s, const char *delim, char **last) -{ - char *spanp; - int c, sc; - char *tok; - - if (s == NULL && (s = *last) == NULL) - { - return NULL; - } - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0; ) - { - if (c == sc) - { - goto cont; - } - } - - if (c == 0) /* no non-delimiter characters */ - { - *last = NULL; - return NULL; - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) - { - c = *s++; - spanp = (char *)delim; - do - { - if ((sc = *spanp++) == c) - { - if (c == 0) - { - s = NULL; - } - else - { - char *w = s - 1; - *w = '\0'; - } - *last = s; - return tok; - } - } - while (sc != 0); - } - /* NOTREACHED */ -} - -#endif