shrub/include/ent/ent.h

60 lines
1.9 KiB
C
Raw Normal View History

2018-12-28 03:32:15 +03:00
/* Copyright 2018 Steven Dee. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
2018-12-28 03:42:28 +03:00
#pragma once
2018-12-27 09:03:44 +03:00
2018-12-27 22:13:51 +03:00
#include <stddef.h>
2018-12-27 22:43:48 +03:00
#include <ent/config.h>
2018-12-27 21:56:10 +03:00
#if defined(ENT_GETENTROPY)
# if defined(ENT_GE_SYSRANDOM)
# include <inttypes.h> /* OSX sys/random.h needs Availability.h from this */
# include <sys/random.h>
# elif defined(ENT_GE_UNISTD)
# include <unistd.h>
# else
# error "libent: this shouldn't happen"
# endif
# define ent_getentropy getentropy
2018-12-31 20:19:28 +03:00
#elif defined(ENT_GETRANDOM) || defined(ENT_URANDOM)
2018-12-27 21:56:10 +03:00
2018-12-28 03:32:15 +03:00
/* Fills buf with high-quality entropy.
2018-12-27 09:03:44 +03:00
*
* buflen is the number of bytes, no greater than 256.
*
* Returns 0 on success. On failure, returns -1 and sets errno to
* indicate the error.
*/
int
ent_getentropy(void* buf, size_t buflen);
2018-12-27 21:56:10 +03:00
#else
# error "libent: platform not supported"
#endif
2018-12-27 22:43:48 +03:00
#undef ENT_GETENTROPY
#undef ENT_GE_SYSRANDOM
#undef ENT_GE_UNISTD
2018-12-31 20:19:28 +03:00
#undef ENT_GETRANDOM
#undef ENT_URANDOM