PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LTP GCOV extension - code coverage report
Current view: directory - standard - uniqid.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 15
Code covered: 100.0 % Executed lines: 15
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 The PHP Group                                |
       6                 :    +----------------------------------------------------------------------+
       7                 :    | This source file is subject to version 3.01 of the PHP license,      |
       8                 :    | that is bundled with this package in the file LICENSE, and is        |
       9                 :    | available through the world-wide-web at the following url:           |
      10                 :    | http://www.php.net/license/3_01.txt                                  |
      11                 :    | If you did not receive a copy of the PHP license and are unable to   |
      12                 :    | obtain it through the world-wide-web, please send a note to          |
      13                 :    | license@php.net so we can mail you a copy immediately.               |
      14                 :    +----------------------------------------------------------------------+
      15                 :    | Author: Stig Sæther Bakken <ssb@php.net>                             |
      16                 :    +----------------------------------------------------------------------+
      17                 :  */
      18                 : 
      19                 : /* $Id: uniqid.c 272374 2008-12-31 11:17:49Z sebastian $ */
      20                 : 
      21                 : #include "php.h"
      22                 : 
      23                 : #include <stdlib.h>
      24                 : #if HAVE_UNISTD_H
      25                 : #include <unistd.h>
      26                 : #endif
      27                 : 
      28                 : #include <string.h>
      29                 : #include <errno.h>
      30                 : 
      31                 : #include <stdio.h>
      32                 : #ifdef PHP_WIN32
      33                 : #include "win32/time.h"
      34                 : #else
      35                 : #include <sys/time.h>
      36                 : #endif
      37                 : 
      38                 : #include "php_lcg.h"
      39                 : #include "uniqid.h"
      40                 : 
      41                 : /* {{{ proto string uniqid([string prefix [, bool more_entropy]])
      42                 :    Generates a unique ID */
      43                 : #ifdef HAVE_GETTIMEOFDAY
      44                 : PHP_FUNCTION(uniqid)
      45            8925 : {
      46            8925 :         char *prefix = "";
      47                 : #if defined(__CYGWIN__)
      48                 :         zend_bool more_entropy = 1;
      49                 : #else
      50            8925 :         zend_bool more_entropy = 0;
      51                 : #endif
      52                 :         char *uniqid;
      53            8925 :         int sec, usec, prefix_len = 0;
      54                 :         struct timeval tv;
      55                 : 
      56            8925 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sb", &prefix, &prefix_len,
      57                 :                                                           &more_entropy)) {
      58               4 :                 return;
      59                 :         }
      60                 : 
      61                 : #if HAVE_USLEEP && !defined(PHP_WIN32)
      62            8921 :         if (!more_entropy) {
      63                 : #if defined(__CYGWIN__)
      64                 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must use 'more entropy' under CYGWIN");
      65                 :                 RETURN_FALSE;
      66                 : #else
      67            8914 :                 usleep(1);
      68                 : #endif
      69                 :         }
      70                 : #endif
      71            8921 :         gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
      72            8921 :         sec = (int) tv.tv_sec;
      73            8921 :         usec = (int) (tv.tv_usec % 0x100000);
      74                 : 
      75                 :         /* The max value usec can have is 0xF423F, so we use only five hex
      76                 :          * digits for usecs.
      77                 :          */
      78            8921 :         if (more_entropy) {
      79               7 :                 spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
      80                 :         } else {
      81            8914 :                 spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
      82                 :         }
      83                 : 
      84            8921 :         RETURN_STRING(uniqid, 0);
      85                 : }
      86                 : #endif
      87                 : /* }}} */
      88                 : 
      89                 : /*
      90                 :  * Local variables:
      91                 :  * tab-width: 4
      92                 :  * c-basic-offset: 4
      93                 :  * End:
      94                 :  * vim600: sw=4 ts=4 fdm=marker
      95                 :  * vim<600: sw=4 ts=4
      96                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:23 +0000 (5 days ago)

Copyright © 2005-2009 The PHP Group
All rights reserved.