Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-25 21:23:52 +00:00
parent 1e79219bea
commit c66f381e90
2 changed files with 27 additions and 0 deletions
+2
View File
@@ -386,6 +386,8 @@ int dcat(const char *s, size_t n,
unsigned short hextonum(char ch_s); unsigned short hextonum(char ch_s);
void *mkrbuf(size_t n); void *mkrbuf(size_t n);
void rset(void *buf, 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 /* Helper functions for command: dump
*/ */
+25
View File
@@ -29,6 +29,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include "../include/common.h" #include "../include/common.h"
@@ -67,6 +68,30 @@
* or your program dies. * 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 * void *
mkrbuf(size_t n) mkrbuf(size_t n)
{ {