1 /* 2 +----------------------------------------------------------------------+ 3 | Copyright (c) The PHP Group | 4 +----------------------------------------------------------------------+ 5 | This source file is subject to version 3.01 of the PHP license, | 6 | that is bundled with this package in the file LICENSE, and is | 7 | available through the world-wide-web at the following url: | 8 | http://www.php.net/license/3_01.txt | 9 | If you did not receive a copy of the PHP license and are unable to | 10 | obtain it through the world-wide-web, please send a note to | 11 | license@php.net so we can mail you a copy immediately. | 12 +----------------------------------------------------------------------+ 13 | Authors: Sammy Kaye Powers <me@sammyk.me> | 14 +----------------------------------------------------------------------+ 15 */ 16 17 #ifndef PHP_RANDOM_H 18 #define PHP_RANDOM_H 19 20 BEGIN_EXTERN_C() 21 22 PHP_MINIT_FUNCTION(random); 23 PHP_MSHUTDOWN_FUNCTION(random); 24 25 typedef struct { 26 int fd; 27 } php_random_globals; 28 29 #define php_random_bytes_throw(b, s) php_random_bytes((b), (s), 1) 30 #define php_random_bytes_silent(b, s) php_random_bytes((b), (s), 0) 31 32 #define php_random_int_throw(min, max, result) \ 33 php_random_int((min), (max), (result), 1) 34 #define php_random_int_silent(min, max, result) \ 35 php_random_int((min), (max), (result), 0) 36 37 PHPAPI int php_random_bytes(void *bytes, size_t size, zend_bool should_throw); 38 PHPAPI int php_random_int(zend_long min, zend_long max, zend_long *result, zend_bool should_throw); 39 40 #ifdef ZTS 41 # define RANDOM_G(v) ZEND_TSRMG(random_globals_id, php_random_globals *, v) 42 extern PHPAPI int random_globals_id; 43 #else 44 # define RANDOM_G(v) random_globals.v 45 extern PHPAPI php_random_globals random_globals; 46 #endif 47 48 END_EXTERN_C() 49 50 #endif 51