mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 18:34:57 +02:00
lbutils: new function, mkrbuf (random malloc)
Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -384,6 +384,7 @@ 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 rset(void *buf, size_t n);
|
void rset(void *buf, size_t n);
|
||||||
|
|
||||||
/* Helper functions for command: dump
|
/* Helper functions for command: dump
|
||||||
|
|||||||
@@ -67,6 +67,21 @@
|
|||||||
* or your program dies.
|
* or your program dies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void *
|
||||||
|
mkrbuf(size_t n)
|
||||||
|
{
|
||||||
|
void *buf;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
|
||||||
|
|
||||||
|
if ((buf = malloc(n)) == NULL)
|
||||||
|
err_no_cleanup(0, ENOMEM, "mkrbuf: malloc");
|
||||||
|
|
||||||
|
rset(buf, n);
|
||||||
|
return buf; /* basically malloc() but with rand */
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rset(void *buf, size_t n)
|
rset(void *buf, size_t n)
|
||||||
{
|
{
|
||||||
@@ -76,8 +91,7 @@ rset(void *buf, size_t n)
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
err_no_cleanup(0, EPERM,
|
err_no_cleanup(0, EPERM, "rset: zero-byte request");
|
||||||
"rset: zero-byte length request");
|
|
||||||
|
|
||||||
#if (defined(__OpenBSD__) || defined(__FreeBSD__) || \
|
#if (defined(__OpenBSD__) || defined(__FreeBSD__) || \
|
||||||
defined(__NetBSD__) || defined(__APPLE__) || \
|
defined(__NetBSD__) || defined(__APPLE__) || \
|
||||||
|
|||||||
Reference in New Issue
Block a user