]> granicus.if.org Git - php/commitdiff
- move strtok_r into reentrancy.c
authorSascha Schumann <sas@php.net>
Fri, 26 Nov 1999 17:33:53 +0000 (17:33 +0000)
committerSascha Schumann <sas@php.net>
Fri, 26 Nov 1999 17:33:53 +0000 (17:33 +0000)
- add rand_r()

Makefile.am
configure.in
main/php_reentrancy.h
main/reentrancy.c
strtok_r.c [deleted file]

index 8fb1b5e82bc75215731a50386104946d4567dabc..4007b242dd1cdcfb3d9289d758cb7f27065f6682 100644 (file)
@@ -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 \
index ec309aa053c2db2f39ef2f5005c4d85c2d9362cd..2529264452a204829db41ece848a05e5391d8e69 100644 (file)
@@ -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=""
index eaf5e37751b8a3e53f82bb8eac66995890b703cf..4e7aad2441525d46a1108fe4e840ea4ee52ae01a 100644 (file)
@@ -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
index b04ea475fa8db61430bef52a164ad0167527b904..ef597165ed1710ec86d7b6e699450b38fabdef42 100644 (file)
@@ -28,7 +28,6 @@ enum {
        NUMBER_OF_LOCKS
 };
 
-
 #if defined(ZTS)
 
 #include <TSRM.h>
@@ -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 <wes@softweyr.com>.
+ */
+
+#include <sys/types.h>
+#include <stdlib.h>
+
+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 <wes@softweyr.com>
+ *
+ * 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 <stddef.h>
+#include <string.h>
+
+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 (file)
index 76e33a4..0000000
+++ /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 <wes@softweyr.com>
- *
- * 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 <stddef.h>
-#include <string.h>
-
-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