summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-26 01:33:01 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:42 +0000
commitf4f3fe3e0a21ea53427242f053e73e16aca04576 (patch)
tree9a9ca7978a79ab1898ba67088da06f7949bb95b2
parent58ce1d74c0915f9a5acf6336f5707663d2bbb2da (diff)
libreboot-utils: tidy up rand.c
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/libreboot-utils/lib/rand.c57
-rw-r--r--util/libreboot-utils/lottery.c11
2 files changed, 22 insertions, 46 deletions
diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c
index 6fb25d9d..4ac50a9c 100644
--- a/util/libreboot-utils/lib/rand.c
+++ b/util/libreboot-utils/lib/rand.c
@@ -71,52 +71,35 @@
#define ELOTTERY ECANCELED
-void *
-rmalloc(size_t *rval)
-{
- if (if_err(rval == NULL, EFAULT))
- return NULL;
-
- rset(rval, sizeof(*rval));
- return mkrstr(*rval %= BUFSIZ);
-}
-
int
-win_lottery(void)
+win_lottery(void) /* are u lucky? */
{
- int saved_errno = errno;
- size_t size1;
- char *s1 = NULL;
- size_t size2;
- char *s2 = NULL;
- size_t pool = BUFSIZ;
+ size_t size = 0;
int rval;
- rset(&size1, sizeof(size1));
- rset(&size2, sizeof(size2));
+ char *s1 = rmalloc(&size);
+ char *s2 = rmalloc(&size);
- size1 %= pool, size2 %= pool;
- s1 = mkrstr(size1), s2 = mkrstr(size2);
+ if (scmp(s1, s2, BUFSIZ + 2, &rval) >= 0 &&
+ rval == 0)
+ rval = 1; /* winner */
+ else
+ rval = 0;
- if (scmp(s1, s2, BUFSIZ + 2, &rval) < 0)
- goto err;
- if (rval == 0)
- goto win;
+ free_if_null(&s1);
+ free_if_null(&s2);
- free_if_null(&s1), free_if_null(&s2);
+ return rval;
+}
- fprintf(stderr, "Sorry, you lose! Try again.\n");
- return 0;
-win:
- free_if_null(&s1), free_if_null(&s2);
+void *
+rmalloc(size_t *rval)
+{
+ if (if_err(rval == NULL, EFAULT))
+ return NULL;
- printf("Congratulations! you won the errno lottery!\n");
- return 1;
-err:
- /* the lottery won you */
- free_if_null(&s1), free_if_null(&s2);
- err_no_cleanup(0, EFAULT, "lottery won you");
- return 0;
+ rset(rval, sizeof(*rval));
+ return mkrstr(*rval %= BUFSIZ);
}
char *
diff --git a/util/libreboot-utils/lottery.c b/util/libreboot-utils/lottery.c
index 6c151add..711a2449 100644
--- a/util/libreboot-utils/lottery.c
+++ b/util/libreboot-utils/lottery.c
@@ -38,18 +38,11 @@ main(int argc, char *argv[])
}
return 1;
-}/*
-
+}/*
( >:3 )
/| |\
- / \
-
-
-
-
-
- */
+ / \ */