mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-20 05:11:46 +03:00
Get it working
This commit is contained in:
parent
8ef34bea65
commit
f1b44b42a9
32
ent.c
32
ent.c
@ -1,28 +1,14 @@
|
||||
#include <ent.h>
|
||||
#include <ent/ent.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined(USE_GETENTROPY)
|
||||
# include <unistd.h>
|
||||
# if defined(__APPLE__) || defined(__linux__)
|
||||
# include <sys/random.h>
|
||||
# endif
|
||||
# define getentropy_impl getentropy
|
||||
#elif defined(USE_URANDOM)
|
||||
#if defined(ENT_USE_URANDOM)
|
||||
# include <assert.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/types.h>
|
||||
# include <unistd.h>
|
||||
#else
|
||||
# error "port: getentropy"
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(USE_URANDOM)
|
||||
|
||||
static int
|
||||
getentropy_impl(void* buf, size_t buflen)
|
||||
int
|
||||
ent_getentropy(void* buf, size_t buflen)
|
||||
{
|
||||
int fd;
|
||||
|
||||
@ -38,10 +24,4 @@ getentropy_impl(void* buf, size_t buflen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
ent_getentropy(void *buf, size_t buflen)
|
||||
{
|
||||
return getentropy_impl(buf, buflen);
|
||||
}
|
||||
#endif /* ENT_USE_URANDOM */
|
||||
|
@ -1,10 +1,21 @@
|
||||
#ifndef _ENT_H
|
||||
#define _ENT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <ent/config.h>
|
||||
|
||||
#if defined(ENT_GETENTROPY)
|
||||
# if defined(ENT_GE_SYSRANDOM)
|
||||
# include <stddef.h>
|
||||
# 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
|
||||
#elif defined(ENT_URANDOM)
|
||||
|
||||
/*
|
||||
* Fills buf with high-quality entropy.
|
||||
*
|
||||
@ -16,4 +27,8 @@
|
||||
int
|
||||
ent_getentropy(void* buf, size_t buflen);
|
||||
|
||||
#else
|
||||
# error "libent: platform not supported"
|
||||
#endif
|
||||
|
||||
#endif /* _ENT_H */
|
||||
|
@ -1,19 +1,29 @@
|
||||
conf_data = configuration_data()
|
||||
compiler = meson.get_compiler('c')
|
||||
|
||||
code = '''#include <unistd.h>
|
||||
code = '''#include <stddef.h>
|
||||
#include <inttypes.h> /* OSX sys/random.h needs Availability.h from this */
|
||||
#include <sys/random.h>
|
||||
int main() { return getentropy((void*)0, 0); }
|
||||
'''
|
||||
have_getentropy = compiler.links(code, name : 'system getentropy')
|
||||
conf_data.set('ENT_USE_GETENTROPY', have_getentropy)
|
||||
sysrandom = compiler.links(code, name : 'getentropy in sys/random.h')
|
||||
conf_data.set('ENT_GE_SYSRANDOM', sysrandom)
|
||||
|
||||
code = '''#include <unistd.h>
|
||||
int main() { return getentropy((void*)0, 0); }
|
||||
'''
|
||||
unistd = compiler.links(code, name : 'getentropy is in unistd.h')
|
||||
conf_data.set('ENT_GE_UNISTD', unistd)
|
||||
|
||||
have_getentropy = sysrandom or unistd
|
||||
conf_data.set('ENT_GETENTROPY', have_getentropy)
|
||||
|
||||
if not have_getentropy
|
||||
code = '''#include <fcntl.h>
|
||||
int main() { return -1 != open("/dev/urandom", O_RDONLY) ? 0 : 1; }
|
||||
'''
|
||||
use_urandom = compiler.run(code, name : 'open /dev/urandom')
|
||||
conf_data.set('ENT_USE_URANDOM', use_urandom.returncode() == 0)
|
||||
use_urandom = compiler.run(code, name : 'can open /dev/urandom')
|
||||
conf_data.set('ENT_URANDOM', use_urandom.returncode() == 0)
|
||||
endif
|
||||
|
||||
configure_file(output : 'config.h',
|
||||
|
@ -9,10 +9,13 @@ inc = include_directories('include')
|
||||
|
||||
ent_sources = ['ent.c']
|
||||
|
||||
ent_dep = declare_dependency(sources : ent_sources,
|
||||
compile_args : ['-Wall', '-pedantic'],
|
||||
include_directories : inc)
|
||||
|
||||
libent = both_libraries('ent',
|
||||
ent_sources,
|
||||
include_directories : inc,
|
||||
install : true)
|
||||
dependencies : [ent_dep],
|
||||
install : false)
|
||||
|
||||
pkg_mod = import('pkgconfig')
|
||||
pkg_mod.generate(libraries : libent,
|
||||
|
Loading…
Reference in New Issue
Block a user