]> git.bzium.org - embe/choinka.git/blobdiff - choinka.c
meson.build: instalujemy program
[embe/choinka.git] / choinka.c
index b117972281f325bb341ccf914f85202cf741fbce..4865cff3f5468322c92f4f1eb9e9e71b2cdca553 100644 (file)
--- a/choinka.c
+++ b/choinka.c
@@ -1,7 +1,10 @@
+#include <fcntl.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <term.h>
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <term.h>
 #include <time.h>
+#include <unistd.h>
 
 #define A_POGRUBIONY (1 << 0)
 
 
 #define A_POGRUBIONY (1 << 0)
 
@@ -38,16 +41,16 @@ static atrybut const gwiazdka = {A_POGRUBIONY, KOLOR_BRAZOWY};
 
 static void inicjuj_rng()
 {
 
 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);
     ziarno = time(NULL);
   }
   srand(ziarno);
@@ -80,6 +83,7 @@ static void ustaw(atrybut const* attr)
 
 int main()
 {
 
 int main()
 {
+  setvbuf(stdout, NULL, _IOFBF, BUFSIZ);
   inicjuj_rng();
   setupterm(NULL, 1, NULL);
   atrybut const* kolor = &choinka;
   inicjuj_rng();
   setupterm(NULL, 1, NULL);
   atrybut const* kolor = &choinka;