entropy.c 494 B

12345678910111213141516171819202122232425262728
  1. /* See LICENSE file for copyright and license details. */
  2. #if defined(__linux__)
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include "../util.h"
  6. const char *
  7. entropy(void)
  8. {
  9. uintmax_t num;
  10. if (pscanf("/proc/sys/kernel/random/entropy_avail", "%ju", &num)
  11. != 1) {
  12. return NULL;
  13. }
  14. return bprintf("%ju", num);
  15. }
  16. #elif defined(__OpenBSD__) | defined(__FreeBSD__)
  17. const char *
  18. entropy(void)
  19. {
  20. /* Unicode Character 'INFINITY' (U+221E) */
  21. return "\xe2\x88\x9e";
  22. }
  23. #endif