summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2002-12-20 16:34:42 +0000
committerMarcus Boerger <helly@php.net>2002-12-20 16:34:42 +0000
commit26038795f8fd381c943216cac69c229ef2af0a99 (patch)
treed0f6b4b3f3aeb02f9b8b1f7122321c79ca66d138 /ext
parent740ee5df1c98a8bfe65e8c423fff9709a0950e34 (diff)
downloadphp-git-26038795f8fd381c943216cac69c229ef2af0a99.tar.gz
-disable uniqid() when required lib functions not available
-emit an error when uniqid() will fail -make more_entropy parameter default to true for CYGWIN
Diffstat (limited to 'ext')
-rw-r--r--ext/standard/basic_functions.c3
-rw-r--r--ext/standard/uniqid.c22
-rw-r--r--ext/standard/uniqid.h2
3 files changed, 17 insertions, 10 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index a78e5393df..5558eb8b7b 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -515,7 +515,10 @@ function_entry basic_functions[] = {
PHP_FE(getrusage, NULL)
#endif
+#ifdef HAVE_GETTIMEOFDAY
PHP_FE(uniqid, NULL)
+#endif
+
PHP_FE(quoted_printable_decode, NULL)
PHP_FE(convert_cyr_string, NULL)
PHP_FE(get_current_user, NULL)
diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c
index feff29949c..7ab0ece36e 100644
--- a/ext/standard/uniqid.c
+++ b/ext/standard/uniqid.c
@@ -40,11 +40,15 @@
/* {{{ proto string uniqid(string prefix [, bool more_entropy])
Generates a unique ID */
+#ifdef HAVE_GETTIMEOFDAY
PHP_FUNCTION(uniqid)
{
-#ifdef HAVE_GETTIMEOFDAY
char *prefix;
+#if defined(__CYGWIN__)
+ zend_bool more_entropy = 1;
+#else
zend_bool more_entropy = 0;
+#endif
char uniqid[138];
int sec, usec, argc, prefix_len;
struct timeval tv;
@@ -57,17 +61,21 @@ PHP_FUNCTION(uniqid)
/* Do some bounds checking since we are using a char array. */
if (prefix_len > 114) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The prefix to uniqid should not be more than 114 characters.");
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "The prefix to uniqid should not be more than 114 characters.");
return;
}
#if HAVE_USLEEP && !defined(PHP_WIN32)
if (!more_entropy) {
+#if defined(__CYGWIN__)
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "You must use 'more entropy' under CYGWIN.");
+ return;
+#endif
usleep(1);
}
#endif
gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
sec = (int) tv.tv_sec;
- usec = (int) (tv.tv_usec % 1000000);
+ usec = (int) (tv.tv_usec % 0x100000);
/* The max value usec can have is 0xF423F, so we use only five hex
* digits for usecs.
@@ -79,16 +87,10 @@ PHP_FUNCTION(uniqid)
}
RETURN_STRING(uniqid, 1);
-#endif
}
+#endif
/* }}} */
-function_entry uniqid_functions[] = {
- PHP_FE(uniqid, NULL)
- {NULL, NULL, NULL}
-};
-
-
/*
* Local variables:
* tab-width: 4
diff --git a/ext/standard/uniqid.h b/ext/standard/uniqid.h
index 352a75ff82..65e1f046c4 100644
--- a/ext/standard/uniqid.h
+++ b/ext/standard/uniqid.h
@@ -21,6 +21,8 @@
#ifndef UNIQID_H
#define UNIQID_H
+#ifdef HAVE_GETTIMEOFDAY
PHP_FUNCTION(uniqid);
+#endif
#endif /* UNIQID_H */