diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2004-10-21 21:20:52 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2004-10-21 21:20:52 +0000 |
commit | 4b947b0525750993dbd54ac006daff128f96804b (patch) | |
tree | b6f96d18db096b55ffd3abe419cd25300bcab13d /ext/standard/microtime.c | |
parent | 54aa88107572f86a29c5f631dc22dbea3ea1ccce (diff) | |
download | php-git-4b947b0525750993dbd54ac006daff128f96804b.tar.gz |
Allow gettimeofday() return a float if optional argument is specified.
Diffstat (limited to 'ext/standard/microtime.c')
-rw-r--r-- | ext/standard/microtime.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c index 3ff8255069..3e4debe433 100644 --- a/ext/standard/microtime.c +++ b/ext/standard/microtime.c @@ -88,12 +88,22 @@ PHP_FUNCTION(microtime) #ifdef HAVE_GETTIMEOFDAY PHP_FUNCTION(gettimeofday) { + zend_bool get_as_float = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) { + return; + } + struct timeval tp; struct timezone tz; memset(&tp, 0, sizeof(tp)); memset(&tz, 0, sizeof(tz)); if(gettimeofday(&tp, &tz) == 0) { + if (get_as_float) { + RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC)); + } + array_init(return_value); add_assoc_long(return_value, "sec", tp.tv_sec); add_assoc_long(return_value, "usec", tp.tv_usec); |