summaryrefslogtreecommitdiff
path: root/ext/standard/uniqid.c
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2002-12-20 17:06:25 +0000
committerMarcus Boerger <helly@php.net>2002-12-20 17:06:25 +0000
commitd795243db34109d63f26ffbb9e26f07075092939 (patch)
treea49cde5f0b5e2efacf7b96d7d72f7e7a9f1840ae /ext/standard/uniqid.c
parent8652e8ac27d72e487f502ed193d990098f566ccd (diff)
downloadphp-git-d795243db34109d63f26ffbb9e26f07075092939.tar.gz
@Make uniqid() parameters optional and allow any prefix length. (Marcus)
Diffstat (limited to 'ext/standard/uniqid.c')
-rw-r--r--ext/standard/uniqid.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c
index 05baff3cde..a6c57602b5 100644
--- a/ext/standard/uniqid.c
+++ b/ext/standard/uniqid.c
@@ -38,32 +38,27 @@
#include "php_lcg.h"
#include "uniqid.h"
-/* {{{ proto string uniqid(string prefix [, bool more_entropy])
+/* {{{ proto string uniqid([string prefix , bool more_entropy])
Generates a unique ID */
#ifdef HAVE_GETTIMEOFDAY
PHP_FUNCTION(uniqid)
{
- char *prefix;
+ 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;
+ char *uniqid;
+ int sec, usec, argc, prefix_len = 0;
struct timeval tv;
argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(argc TSRMLS_CC, "s|b", &prefix, &prefix_len,
+ if (zend_parse_parameters(argc TSRMLS_CC, "|sb", &prefix, &prefix_len,
&more_entropy)) {
return;
}
- /* Do some bounds checking since we are using a char array. */
- if (prefix_len > 114) {
- 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__)
@@ -82,12 +77,12 @@ PHP_FUNCTION(uniqid)
* digits for usecs.
*/
if (more_entropy) {
- sprintf(uniqid, "%s%08x%05x%.8f", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
+ spprintf(&uniqid, 0, "%s%08x%05x%.8f", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
} else {
- sprintf(uniqid, "%s%08x%05x", prefix, sec, usec);
+ spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
}
- RETURN_STRING(uniqid, 1);
+ RETURN_STRING(uniqid, 0);
}
#endif
/* }}} */