sys_random.in.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Substitute for <sys/random.h>.
  2. Copyright (C) 2020-2021 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser 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 */