php_random.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. | https://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. #ifndef PHP_RANDOM_H
  17. #define PHP_RANDOM_H
  18. BEGIN_EXTERN_C()
  19. PHP_MINIT_FUNCTION(random);
  20. PHP_MSHUTDOWN_FUNCTION(random);
  21. typedef struct {
  22. int fd;
  23. } php_random_globals;
  24. #define php_random_bytes_throw(b, s) php_random_bytes((b), (s), 1)
  25. #define php_random_bytes_silent(b, s) php_random_bytes((b), (s), 0)
  26. #define php_random_int_throw(min, max, result) \
  27. php_random_int((min), (max), (result), 1)
  28. #define php_random_int_silent(min, max, result) \
  29. php_random_int((min), (max), (result), 0)
  30. PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw);
  31. PHPAPI int php_random_int(zend_long min, zend_long max, zend_long *result, bool should_throw);
  32. #ifdef ZTS
  33. # define RANDOM_G(v) ZEND_TSRMG(random_globals_id, php_random_globals *, v)
  34. extern PHPAPI int random_globals_id;
  35. #else
  36. # define RANDOM_G(v) random_globals.v
  37. extern PHPAPI php_random_globals random_globals;
  38. #endif
  39. END_EXTERN_C()
  40. #endif