Skip to content

Commit

Permalink
Try fix compile on Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsdz committed Aug 10, 2024
1 parent acf8bfb commit 8b58800
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
15 changes: 6 additions & 9 deletions compat_arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/* $OpenBSD$ */

#include <stddef.h>
#include <stdint.h>

#define KEYSTREAM_ONLY
Expand Down Expand Up @@ -253,10 +254,6 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
* Made fully portable and thread-safe by Sudhi Herle.
*/

#if defined(__linux__) || defined(__wasi__)
# define _DEFAULT_SOURCE /* new glibc for getentropy() */
#endif

#include <fcntl.h>
#include <limits.h>
#include <signal.h>
Expand Down Expand Up @@ -422,7 +419,7 @@ static volatile uint32_t Rforked = 0;
* Fork handler to reset my context
*/
static void
atfork()
atfork(void)
{
// the pthread_atfork() callbacks called once per process.
// We set it to be called by the child process.
Expand All @@ -434,7 +431,7 @@ atfork()
* create the thread-specific key.
*/
static void
screate()
screate(void)
{
pthread_key_create(&Rkey, 0);
pthread_atfork(0, 0, atfork);
Expand All @@ -445,7 +442,7 @@ screate()
* Get the per-thread rand state. Initialize if needed.
*/
static rand_state*
sget()
sget(void)
{
pthread_once(&Ronce, screate);

Expand Down Expand Up @@ -479,7 +476,7 @@ sget()
*/
static __thread rand_state st = { .rs_count = 0, .rs_pid = -1, .rs_have = 0 };
static inline rand_state*
sget()
sget(void)
{
rand_state* s = &st;

Expand All @@ -505,7 +502,7 @@ __rand32(rand_state *z)
}

uint32_t
arc4random()
arc4random(void)
{
rand_state* z = sget();
return __rand32(z);
Expand Down
15 changes: 6 additions & 9 deletions compats.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* $OpenBSD$ */

#include <stddef.h>
#include <stdint.h>

#define KEYSTREAM_ONLY
Expand Down Expand Up @@ -255,10 +256,6 @@ chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
* Made fully portable and thread-safe by Sudhi Herle.
*/

#if defined(__linux__) || defined(__wasi__)
# define _DEFAULT_SOURCE /* new glibc for getentropy() */
#endif

#include <fcntl.h>
#include <limits.h>
#include <signal.h>
Expand Down Expand Up @@ -424,7 +421,7 @@ static volatile uint32_t Rforked = 0;
* Fork handler to reset my context
*/
static void
atfork()
atfork(void)
{
// the pthread_atfork() callbacks called once per process.
// We set it to be called by the child process.
Expand All @@ -436,7 +433,7 @@ atfork()
* create the thread-specific key.
*/
static void
screate()
screate(void)
{
pthread_key_create(&Rkey, 0);
pthread_atfork(0, 0, atfork);
Expand All @@ -447,7 +444,7 @@ screate()
* Get the per-thread rand state. Initialize if needed.
*/
static rand_state*
sget()
sget(void)
{
pthread_once(&Ronce, screate);

Expand Down Expand Up @@ -481,7 +478,7 @@ sget()
*/
static __thread rand_state st = { .rs_count = 0, .rs_pid = -1, .rs_have = 0 };
static inline rand_state*
sget()
sget(void)
{
rand_state* s = &st;

Expand All @@ -507,7 +504,7 @@ __rand32(rand_state *z)
}

uint32_t
arc4random()
arc4random(void)
{
rand_state* z = sget();
return __rand32(z);
Expand Down
3 changes: 2 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ __HEREDOC__
# someting that pulls in support for size_t.
# Our function declarations are standalone, so specify them here.

if [ ${HAVE_BLOWFISH} -eq 0 -o \
if [ ${HAVE_ARC4RANDOM} -eq 0 -o \
${HAVE_BLOWFISH} -eq 0 -o \
${HAVE_FTS} -eq 0 -o \
${HAVE_MD5} -eq 0 -o \
${HAVE_MEMMEM} -eq 0 -o \
Expand Down
3 changes: 2 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ __HEREDOC__
# someting that pulls in support for size_t.
# Our function declarations are standalone, so specify them here.

if [ ${HAVE_BLOWFISH} -eq 0 -o \
if [ ${HAVE_ARC4RANDOM} -eq 0 -o \
${HAVE_BLOWFISH} -eq 0 -o \
${HAVE_FTS} -eq 0 -o \
${HAVE_MD5} -eq 0 -o \
${HAVE_MEMMEM} -eq 0 -o \
Expand Down
1 change: 1 addition & 0 deletions configure.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HAVE_ARC4RANDOM=0

0 comments on commit 8b58800

Please sign in to comment.