Files
bluelib/core/sys/linux/random.c

36 lines
543 B
C

#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
uint64_t z__b_platform_random_seed()
{
int fd = open("/dev/urandom", O_RDONLY);
if (fd == -1) {
return (uint64_t)-1;
}
uint64_t v = 0;
if (read(fd, &v, sizeof v) != sizeof v) {
close(fd);
return (uint64_t)-1;
}
return v;
}
uint64_t z__b_platform_random_seed_secure()
{
int fd = open("/dev/random", O_RDONLY);
if (fd == -1) {
return (uint64_t)-1;
}
uint64_t v = 0;
if (read(fd, &v, sizeof v) != sizeof v) {
close(fd);
return (uint64_t)-1;
}
return v;
}