From 886b1aabbdedcd69961ac519f64cb6d8c3afe21e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 25 Mar 2026 21:23:52 +0000 Subject: mkrstr Signed-off-by: Leah Rowe --- util/libreboot-utils/lib/rand.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'util/libreboot-utils/lib/rand.c') diff --git a/util/libreboot-utils/lib/rand.c b/util/libreboot-utils/lib/rand.c index e67b7058..d54d4adc 100644 --- a/util/libreboot-utils/lib/rand.c +++ b/util/libreboot-utils/lib/rand.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../include/common.h" @@ -67,6 +68,30 @@ * or your program dies. */ +char * +mkrstr(size_t n) /* emulates spkmodem-decode */ +{ + char *s; + size_t i; + + if (n == 0) + err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request"); + + if (n == SIZE_MAX) + err_no_cleanup(0, EOVERFLOW, "mkrbuf: overflow"); + + if (if_err((s = mkrbuf(n + 1)) == NULL, EFAULT)) + err_no_cleanup(0, EFAULT, "mkrstr: null"); + + for (i = 0; i < n; i++) + while(*(s + i) == '\0') + rset(s + i, 1); + + *(s + n) = '\0'; + + return s; +} + void * mkrbuf(size_t n) { -- cgit v1.2.1