From 8522b5c391db034f29adcedab000adf21c79d67a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 26 Mar 2026 02:14:09 +0000 Subject: more cleanup on rand.c Signed-off-by: Leah Rowe --- util/libreboot-utils/include/common.h | 2 +- util/libreboot-utils/lib/rand.c | 7 ++++++- util/libreboot-utils/lottery.c | 30 +++++++----------------------- 3 files changed, 14 insertions(+), 25 deletions(-) (limited to 'util') diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index dac87fac..c74da0a3 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -391,7 +391,7 @@ void *rmalloc(size_t *size); /* don't ever use this */ void rset(void *buf, size_t n); void *mkrbuf(size_t n); char *mkrstr(size_t n); -int win_lottery(void); +int win_lottery(char **buf); /* Helper functions for command: dump */ diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index ac94a482..3a0a94bf 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -20,6 +20,9 @@ #if defined(USE_URANDOM) && \ ((USE_URANDOM) > 0) #include /* if not arc4random: /dev/urandom */ +#elif defined(__linux__) +#include +#include #endif #include @@ -70,7 +73,7 @@ */ int -win_lottery(void) /* are u lucky? */ +win_lottery(char **buf) /* are u lucky? */ { size_t size = 0; int rval; @@ -84,6 +87,8 @@ win_lottery(void) /* are u lucky? */ else rval = 0; + (void) scat(s1, s2, BUFSIZ << 1, buf); + free_if_null(&s1); free_if_null(&s2); diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c index 711a2449..8157d7a9 100644 --- a/util/libreboot-utils/lottery.c +++ b/util/libreboot-utils/lottery.c @@ -13,8 +13,8 @@ int main(int argc, char *argv[]) { - size_t s; - char *s1; + char *s1 = NULL; + int rval = 0; #if defined(__OpenBSD__) && defined(OpenBSD) #if (OpenBSD) >= 509 @@ -22,36 +22,20 @@ main(int argc, char *argv[]) err_no_cleanup(0, errno, "openbsd won it"); #endif #endif - setvbuf(stdout, NULL, _IONBF, 0); - if (win_lottery()) { - printf("You won!"); - return 0; - } - - s1 = rmalloc(&s); + if (win_lottery(&s1)) + rval = 1; if (s1 != NULL) { - printf("%s\n\nYou lose. Sorry!\n", s1); + printf("%s\n\n", s1); free(s1); } - return 1; + printf("%s\n", rval ? "You won!" : "You lose! Sorry!"); + return rval? EXIT_SUCCESS : EXIT_FAILURE; }/* ( >:3 ) /| |\ / \ */ - - - - - - - - - - - - -- cgit v1.2.1