summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2026-03-25 21:23:52 +0000
committerLeah Rowe <leah@libreboot.org>2026-03-26 06:59:42 +0000
commitc66f381e9062f0e75e2731e6b6774c2090933e75 (patch)
treec9c5cac20862fa615c9660637355c186129a8e4f /util
parent1e79219bea878b092b6a833b30f2f3a86aebbc33 (diff)
mkrstr
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/libreboot-utils/include/common.h2
-rw-r--r--util/libreboot-utils/lib/rand.c25
2 files changed, 27 insertions, 0 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h
index c4ee75e0..6d6d8d09 100644
--- a/util/libreboot-utils/include/common.h
+++ b/util/libreboot-utils/include/common.h
@@ -386,6 +386,8 @@ int dcat(const char *s, size_t n,
unsigned short hextonum(char ch_s);
void *mkrbuf(size_t n);
void rset(void *buf, size_t n);
+void *mkrbuf(size_t n);
+char *mkrstr(size_t n);
/* Helper functions for command: dump
*/
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 <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#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)
{