php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27182 [Patch] uniqid("prefix", 0) now works under recent cygwin
Submitted: 2004-02-08 00:40 UTC Modified: 2013-10-15 11:54 UTC
From: sagawa at sohgoh dot net Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.3.5RC2 OS: CYGWIN_NT-5.1 1.5.7
Private report: No CVE-ID: None
 [2004-02-08 00:40 UTC] sagawa at sohgoh dot net
Description:
------------
According to cygwin-patches(*1) and ChangeLog(*2), Cygwin's usleep now advances system clock(gettimeofday).
*1 .. http://sources.redhat.com/ml/cygwin-patches/2003-q3/msg00178.html
*2 .. http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/winsup/cygwin/signal.cc?cvsroot=src#rev1.48

Therefore I can use uniqid safely when more entropy flag is zero, I made a patch. (but "more entropy flag" is still on by default for backward compatibility)
Unfortunary cygwin doesn't change version for this change, I apply most recent change of CYGWIN_VERSION_API_MINOR.

"String functions [tests/strings/001.phpt]" now pass!

--- php-4.3.5RC2/ext/standard/uniqid.c.orig	2003-01-01 01:35:35.000000000 +0900
+++ php-4.3.5RC2/ext/standard/uniqid.c	2004-02-08 13:01:49.006220800 +0900
@@ -34,6 +34,9 @@
 #else
 #include <sys/time.h>
 #endif
+#if defined(__CYGWIN__)
+#include <cygwin/version.h>
+#endif
 
 #include "php_lcg.h"
 #include "uniqid.h"
@@ -66,7 +69,7 @@
 	}
 #if HAVE_USLEEP && !defined(PHP_WIN32)
 	if (!more_entropy) {
-#if defined(__CYGWIN__)
+#if defined(__CYGWIN__) && (CYGWIN_VERSION_API_MINOR < 91)
 		php_error_docref(NULL TSRMLS_CC, E_ERROR, "You must use 'more entropy' under CYGWIN.");
 		return;
 #else
--- php-4.3.5RC2/tests/strings/001.phpt.orig	2001-03-21 21:47:46.000000000 +0900
+++ php-4.3.5RC2/tests/strings/001.phpt	2004-02-08 13:23:53.320491200 +0900
@@ -181,8 +181,8 @@
 
 echo "Testing uniqid: ";
 $str = "prefix";
-$ui1 = uniqid($str);
-$ui2 = uniqid($str);
+$ui1 = uniqid($str, 0);
+$ui2 = uniqid($str, 0);
 if (strlen($ui1) == strlen($ui2) && strlen($ui1) == 19 && $ui1 != $ui2) {
 	echo("passed\n");
 } else {


Reproduce code:
---------------
<?php
echo uniqid("prefix"),"\n";
echo uniqid("prefix", 1),"\n";
echo uniqid("prefix", 0),"\n";
echo uniqid("prefix", 0),"\n";
echo uniqid("prefix", 0),"\n";
?>

Expected result:
----------------
-- cygwin --
prefix4025c46680d100.85790027
prefix4025c466810f81.04902838
prefix4025c466814e0
prefix4025c466818c8
prefix4025c46681cb0
-- linux --
prefix4025c4a472847
prefix4025c4a47289a3.07476264
prefix4025c4a47766a
prefix4025c4a47c487
prefix4025c4a4812a8


Actual result:
--------------
-- cygwin(NG) --
PHP Fatal error:  uniqid(): You must use 'more entropy' under CYGWIN. in /home/sagawa/uniqid_test.php on line 4
prefix4025c46680d100.85790027
prefix4025c466810f81.04902838
-- linux(OK) --
prefix4025c4a472847
prefix4025c4a47289a3.07476264
prefix4025c4a47766a
prefix4025c4a47c487
prefix4025c4a4812a8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-31 01:39 UTC] yohgaki@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2013-07-31 01:39 UTC] yohgaki@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2013-09-05 13:22 UTC] cmbecker69 at gmx dot de
I made the following test:

  $ uname -a
  CYGWIN_NT-5.1 RELIANT 1.7.18(0.263/5/3) 2013-04-19 10:39 i686 Cygwin
  $ php -v
  PHP 5.4.19 (cli) (built: Aug 23 2013 19:12:30)
  Copyright (c) 1997-2013 The PHP Group
  Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
  $ php -r 'var_dump(uniqid(null,false));'
  PHP Warning:  uniqid(): You must use 'more entropy' under CYGWIN
  in Command line code on line 1

  Warning: uniqid(): You must use 'more entropy' under CYGWIN 
  in Command line code on line 1
  bool(false)

From looking at the sources[1], the result is not surprising.

[1] <http://lxr.php.net/xref/PHP_5_4/ext/standard/uniqid.c#63>
    <http://lxr.php.net/xref/PHP_5_5/ext/standard/uniqid.c#63>
 [2013-09-05 17:27 UTC] cmbecker69 at gmx dot de
I have now recompiled PHP 5.4.19 with the patch given above:

  $ php -r 'var_dump(uniqid(null, false));'
  string(13) "5228be262625a"
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC