Add a sample program

This commit is contained in:
Jōshin 2018-12-27 19:19:59 +00:00
parent 16451c769c
commit 4d89cad020
3 changed files with 27 additions and 1 deletions

2
ent.c
View File

@ -14,7 +14,7 @@ ent_getentropy(void* buf, size_t len)
{
int fd;
ssize_t ret;
char* cuf;
char* cuf = buf;
assert(len <= 256);
if (-1 == (fd = open("/dev/urandom", O_RDONLY))) {

View File

@ -23,3 +23,7 @@ pkg_mod.generate(libraries : libent,
name : 'libent',
filebase : 'ent',
description : 'A library to get entropy.')
ent_sample = executable('sample',
['sample.c'],
dependencies : [ent_dep])

22
sample.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <string.h>
#include <ent/ent.h>
int
main()
{
char buf[256];
int i;
memset(buf, 0, sizeof(buf));
if (0 != ent_getentropy(buf, sizeof(buf))) {
perror("getentropy");
}
for (i = 0; i < sizeof buf; ++i) {
printf("%02hhx", buf[i]);
}
puts("");
return 0;
}