X-Git-Url: https://git.bzium.org/embe/choinka.git/blobdiff_plain/ce2e37059c21803606557e44fe872174fed3772c..HEAD:/choinka.c diff --git a/choinka.c b/choinka.c index b117972..4865cff 100644 --- a/choinka.c +++ b/choinka.c @@ -1,7 +1,10 @@ +#include +#include #include #include #include #include +#include #define A_POGRUBIONY (1 << 0) @@ -38,16 +41,16 @@ static atrybut const gwiazdka = {A_POGRUBIONY, KOLOR_BRAZOWY}; static void inicjuj_rng() { - unsigned ziarno = 0; - FILE* f = fopen("/dev/urandom", "rb"); - if (f != NULL) { - unsigned nowe_ziarno; - if (fread(&nowe_ziarno, sizeof nowe_ziarno, 1, f) == 1) { - ziarno = nowe_ziarno; + bool ok = false; + unsigned ziarno; + int f = open("/dev/urandom", O_RDONLY); + if (f != -1) { + if (read(f, &ziarno, sizeof ziarno) == sizeof ziarno) { + ok = true; } - fclose(f); + close(f); } - if (ziarno == 0) { + if (!ok) { ziarno = time(NULL); } srand(ziarno); @@ -80,6 +83,7 @@ static void ustaw(atrybut const* attr) int main() { + setvbuf(stdout, NULL, _IOFBF, BUFSIZ); inicjuj_rng(); setupterm(NULL, 1, NULL); atrybut const* kolor = &choinka;