sys_random.in.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Substitute for <sys/random.h>.
  2. Copyright (C) 2020-2021 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <https://www.gnu.org/licenses/>. */
  13. # if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. # endif
  16. @PRAGMA_COLUMNS@
  17. #ifndef _@GUARD_PREFIX@_SYS_RANDOM_H
  18. #if @HAVE_SYS_RANDOM_H@
  19. /* On uClibc, <sys/random.h> assumes prior inclusion of <stddef.h>. */
  20. # if defined __UCLIBC__
  21. # include <stddef.h>
  22. # endif
  23. /* On Mac OS X 10.5, <sys/random.h> assumes prior inclusion of <sys/types.h>.
  24. On Max OS X 10.13, <sys/random.h> assumes prior inclusion of a file that
  25. includes <Availability.h>, such as <stdlib.h> or <unistd.h>. */
  26. # if defined __APPLE__ && defined __MACH__ /* Mac OS X */
  27. # include <sys/types.h>
  28. # include <stdlib.h>
  29. # endif
  30. /* The include_next requires a split double-inclusion guard. */
  31. # @INCLUDE_NEXT@ @NEXT_SYS_RANDOM_H@
  32. #endif
  33. #ifndef _@GUARD_PREFIX@_SYS_RANDOM_H
  34. #define _@GUARD_PREFIX@_SYS_RANDOM_H
  35. #include <sys/types.h>
  36. /* Define the GRND_* constants. */
  37. #ifndef GRND_NONBLOCK
  38. # define GRND_NONBLOCK 1
  39. # define GRND_RANDOM 2
  40. #endif
  41. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  42. /* The definition of _GL_ARG_NONNULL is copied here. */
  43. /* The definition of _GL_WARN_ON_USE is copied here. */
  44. /* Declare overridden functions. */
  45. #if @GNULIB_GETRANDOM@
  46. /* Fill a buffer with random bytes. */
  47. # if @REPLACE_GETRANDOM@
  48. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  49. # undef getrandom
  50. # define getrandom rpl_getrandom
  51. # endif
  52. _GL_FUNCDECL_RPL (getrandom, ssize_t,
  53. (void *buffer, size_t length, unsigned int flags)
  54. _GL_ARG_NONNULL ((1)));
  55. _GL_CXXALIAS_RPL (getrandom, ssize_t,
  56. (void *buffer, size_t length, unsigned int flags));
  57. # else
  58. # if !@HAVE_GETRANDOM@
  59. _GL_FUNCDECL_SYS (getrandom, ssize_t,
  60. (void *buffer, size_t length, unsigned int flags)
  61. _GL_ARG_NONNULL ((1)));
  62. # endif
  63. _GL_CXXALIAS_SYS (getrandom, ssize_t,
  64. (void *buffer, size_t length, unsigned int flags));
  65. # endif
  66. _GL_CXXALIASWARN (getrandom);
  67. #elif defined GNULIB_POSIXCHECK
  68. # undef getrandom
  69. # if HAVE_RAW_DECL_GETRANDOM
  70. _GL_WARN_ON_USE (getrandom, "getrandom is unportable - "
  71. "use gnulib module getrandom for portability");
  72. # endif
  73. #endif
  74. #endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */
  75. #endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */