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