Re: cvs: php-src /ext/standard microtime.c

From: Date: Wed, 17 Dec 2003 22:05:37 +0000
Subject: Re: cvs: php-src /ext/standard microtime.c
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-25262@lists.php.net to get a copy of this message
You didn't fix the proto. And please, try to hold commits for a few hours whilst I roll the beta. Andi At 10:03 PM 12/17/2003 +0000, Andrey Hristov wrote:
andrey          Wed Dec 17 17:03:34 2003 EDT
Modified files:
    /php-src/ext/standard       microtime.c
Log: Added optional parameter to microtime so now it can return float if it the user wants. This prevents from getting string representation exploding it and then creating a float. Index: php-src/ext/standard/microtime.c diff -u php-src/ext/standard/microtime.c:1.41 php-src/ext/standard/microtime.c:1.42
--- php-src/ext/standard/microtime.c:1.41       Tue Jun 10 16:03:38 2003
+++ php-src/ext/standard/microtime.c    Wed Dec 17 17:03:33 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
*/ -/* $Id: microtime.c,v 1.41 2003/06/10 20:03:38 imajes Exp $ */ +/* $Id: microtime.c,v 1.42 2003/12/17 22:03:33 andrey Exp $ */ #include "php.h" @@ -51,29 +51,40 @@ #define MICRO_IN_SEC 1000000.00 #define SEC_IN_MIN 60 -/* {{{ proto string microtime(void) - Returns a string containing the current time in seconds and microseconds */ #ifdef HAVE_GETTIMEOFDAY +/* {{{ proto string microtime([bool get_as_float]) + Returns either a string or a float containing the current time in seconds and microseconds */ PHP_FUNCTION(microtime) {
        struct timeval tp;
        long sec = 0L;
        double msec = 0.0;
-       char ret[100];
-
+       zend_bool get_as_float = 0;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
+               return;
+       }
+
        if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
                msec = (double) (tp.tv_usec / MICRO_IN_SEC);
                sec = tp.tv_sec;
                if (msec >= 1.0) msec -= (long) msec;
-               snprintf(ret, 100, "%.8f %ld", msec, sec);
-               RETVAL_STRING(ret,1);
+               if (get_as_float == 0) {
+                       char ret[100];
+
+                       snprintf(ret, 100, "%.8f %ld", msec, sec);
+                       RETURN_STRING(ret,1);
+               } else {
+                       RETURN_DOUBLE((double) (sec + msec));
+               }
        } else {
                RETURN_FALSE;
        }
+ } -#endif /* }}} */ +#endif /* {{{ proto array gettimeofday(void)
    Returns the current time as array */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.cvs (#25262) next »