CACHE_LIMITER_FUNC(public)
{
char buf[MAX_STR + 1];
+ struct timeval tv;
time_t now;
- time(&now);
- now += PS(cache_expire) * 60;
+ gettimeofday(&tv, NULL);
+ now = tv.tv_sec + PS(cache_expire) * 60;
#define EXPIRES "Expires: "
memcpy(buf, EXPIRES, sizeof(EXPIRES) - 1);
strcpy_gmt(buf + sizeof(EXPIRES) - 1, &now);
last_modified(TSRMLS_C);
}
-
+
CACHE_LIMITER_FUNC(private)
{
char buf[MAX_STR + 1];
smart_str_appends(&ncookie, PS(id));
if (PS(cookie_lifetime) > 0) {
- date_fmt = php_std_date(time(NULL) + PS(cookie_lifetime));
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ date_fmt = php_std_date(tv.tv_sec + PS(cookie_lifetime));
smart_str_appends(&ncookie, COOKIE_EXPIRES);
smart_str_appends(&ncookie, date_fmt);
PHP_MINIT(crypt) (INIT_FUNC_ARGS_PASSTHRU);
#endif
-#ifdef ZTS
PHP_MINIT(lcg) (INIT_FUNC_ARGS_PASSTHRU);
-#endif
PHP_MINIT(dir) (INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(syslog) (INIT_FUNC_ARGS_PASSTHRU);
PHP_RINIT(crypt) (INIT_FUNC_ARGS_PASSTHRU);
#endif
-#ifndef ZTS
PHP_RINIT(lcg) (INIT_FUNC_ARGS_PASSTHRU);
-#endif
PHP_RINIT(filestat) (INIT_FUNC_ARGS_PASSTHRU);
PHP_RINIT(syslog) (INIT_FUNC_ARGS_PASSTHRU);
#include <unistd.h>
#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+
#ifdef ZTS
int lcg_globals_id;
#else
static php_lcg_globals lcg_globals;
-static int php_lcg_initialized = 0;
#endif
#define MODMULT(a, b, c, m, s) q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m
-double php_combined_lcg(TSRMLS_D)
+PHPAPI double php_combined_lcg(TSRMLS_D)
{
php_int32 q;
php_int32 z;
MODMULT(52774, 40692, 3791, 2147483399L, LCG(s2));
z = LCG(s1) - LCG(s2);
- if(z < 1) {
+ if (z < 1) {
z += 2147483562;
}
return z * 4.656613e-10;
}
-static void lcg_init_globals(php_lcg_globals *lcg_globals_p TSRMLS_DC)
+static void lcg_seed(TSRMLS_D)
{
- LCG(s1) = 1;
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == 0) {
+ LCG(s1) = tv.tv_sec ^ (~tv.tv_usec);
+ } else {
+ LCG(s1) = 1;
+ }
#ifdef ZTS
LCG(s2) = (long) tsrm_thread_id();
#else
LCG(s2) = (long) getpid();
#endif
+
+ LCG(seeded) = 1;
+}
+
+static void lcg_init_globals(php_lcg_globals *lcg_globals_p TSRMLS_DC)
+{
+ LCG(seeded) = 0;
}
-#ifdef ZTS
PHP_MINIT_FUNCTION(lcg)
{
+#ifdef ZTS
ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
+#else
+ lcg_init_globals(&lcg_globals);
+#endif
return SUCCESS;
}
-#else
+
PHP_RINIT_FUNCTION(lcg)
{
- if (!php_lcg_initialized) {
- lcg_init_globals(&lcg_globals TSRMLS_CC);
- php_lcg_initialized = 1;
+ if (!LCG(seeded)) {
+ lcg_seed(TSRMLS_C);
}
return SUCCESS;
}
-#endif
/* {{{ proto double lcg_value()
Returns a value from the combined linear congruential generator */
typedef struct {
php_int32 s1;
php_int32 s2;
+ int seeded;
} php_lcg_globals;
-double php_combined_lcg(TSRMLS_D);
+PHPAPI double php_combined_lcg(TSRMLS_D);
PHP_FUNCTION(lcg_value);
-#ifdef ZTS
PHP_MINIT_FUNCTION(lcg);
+PHP_RINIT_FUNCTION(lcg);
+
+#ifdef ZTS
#define LCG(v) TSRMG(lcg_globals_id, php_lcg_globals *, v)
#else
-PHP_RINIT_FUNCTION(lcg);
#define LCG(v) (lcg_globals.v)
#endif