sys_random.in.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Substitute for <sys/random.h>.
  2. Copyright (C) 2020-2023 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 < 1.0.35, <sys/random.h> assumes prior inclusion of <stddef.h>.
  20. Do not use __UCLIBC__ here, as it might not be defined yet.
  21. But avoid namespace pollution on glibc systems. */
  22. # ifndef __GLIBC__
  23. # include <stddef.h>
  24. # endif
  25. /* On Mac OS X 10.5, <sys/random.h> assumes prior inclusion of <sys/types.h>.
  26. On Max OS X 10.13, <sys/random.h> assumes prior inclusion of a file that
  27. includes <Availability.h>, such as <stdlib.h> or <unistd.h>. */
  28. # if defined __APPLE__ && defined __MACH__ /* Mac OS X */
  29. # include <sys/types.h>
  30. # include <stdlib.h>
  31. # endif
  32. /* The include_next requires a split double-inclusion guard. */
  33. # @INCLUDE_NEXT@ @NEXT_SYS_RANDOM_H@
  34. #endif
  35. #ifndef _@GUARD_PREFIX@_SYS_RANDOM_H
  36. #define _@GUARD_PREFIX@_SYS_RANDOM_H
  37. #include <sys/types.h>
  38. /* Define the GRND_* constants. */
  39. #ifndef GRND_NONBLOCK
  40. # define GRND_NONBLOCK 1
  41. # define GRND_RANDOM 2
  42. #endif
  43. /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
  44. /* The definition of _GL_ARG_NONNULL is copied here. */
  45. /* The definition of _GL_WARN_ON_USE is copied here. */
  46. /* Declare overridden functions. */
  47. #if @GNULIB_GETRANDOM@
  48. /* Fill a buffer with random bytes. */
  49. # if @REPLACE_GETRANDOM@
  50. # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
  51. # undef getrandom
  52. # define getrandom rpl_getrandom
  53. # endif
  54. _GL_FUNCDECL_RPL (getrandom, ssize_t,
  55. (void *buffer, size_t length, unsigned int flags)
  56. _GL_ARG_NONNULL ((1)));
  57. _GL_CXXALIAS_RPL (getrandom, ssize_t,
  58. (void *buffer, size_t length, unsigned int flags));
  59. # else
  60. # if !@HAVE_GETRANDOM@
  61. _GL_FUNCDECL_SYS (getrandom, ssize_t,
  62. (void *buffer, size_t length, unsigned int flags)
  63. _GL_ARG_NONNULL ((1)));
  64. # endif
  65. _GL_CXXALIAS_SYS (getrandom, ssize_t,
  66. (void *buffer, size_t length, unsigned int flags));
  67. # endif
  68. # if __GLIBC__ + (__GLIBC_MINOR__ >= 25) > 2
  69. _GL_CXXALIASWARN (getrandom);
  70. # endif
  71. #elif defined GNULIB_POSIXCHECK
  72. # undef getrandom
  73. # if HAVE_RAW_DECL_GETRANDOM
  74. _GL_WARN_ON_USE (getrandom, "getrandom is unportable - "
  75. "use gnulib module getrandom for portability");
  76. # endif
  77. #endif
  78. #endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */
  79. #endif /* _@GUARD_PREFIX@_SYS_RANDOM_H */