qrcode demo: use arc4rand() on freebsd #601

This commit is contained in:
nick black 2020-05-13 01:42:09 -04:00
parent 45db9c2ac7
commit 18ba212709
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

View File

@ -1,5 +1,9 @@
#include "demo.h"
#ifdef __linux__
#include <sys/random.h>
#else
#include <sys/libkern.h>
#endif
int qrcode_demo(struct notcurses* nc){
#ifdef USE_QRCODEGEN
@ -9,10 +13,14 @@ int qrcode_demo(struct notcurses* nc){
for(int i = 0 ; i < 1024 ; ++i){
ncplane_erase(n);
size_t len = random() % sizeof(data) + 1;
#ifdef __linux__
ssize_t got = getrandom(data, len, 0);
if(got < 0 || (size_t)got != len){
return -1;
}
#else
arc4rand(data, len, 0);
#endif
if(ncplane_cursor_move_yx(n, 0, 0)){
return -1;
}