summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-01 11:56:01 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-01 12:02:16 +0100
commit18f39ab6fafde132af48350d7c976afa5716038f (patch)
tree326e4626e92bbf3dbbb51df9f56de6a73913fa3d /util/nvmutil
parent4d91bcc2d75ba9874ed352ef0fde5cfa128c4ebd (diff)
util/nvmutil: clean up rhex()
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c5
-rw-r--r--util/nvmutil/nvmutil.h6
2 files changed, 6 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index d047e2aa..fcdab9e8 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -140,10 +140,9 @@ rhex(void)
{
static int rfd = -1, n = 0;
static uint8_t rnum[16];
- if (!n) {
- xopen(rfd, "/dev/urandom", O_RDONLY);
+ xopen(rfd, "/dev/urandom", O_RDONLY);
+ if (!n)
xpread(rfd, (uint8_t *) &rnum, (n = 15) + 1, 0, "/dev/urandom");
- }
return rnum[n--] & 0xf;
}
diff --git a/util/nvmutil/nvmutil.h b/util/nvmutil/nvmutil.h
index c951148f..1b928a34 100644
--- a/util/nvmutil/nvmutil.h
+++ b/util/nvmutil/nvmutil.h
@@ -51,8 +51,10 @@ int big_endian;
#define ERR() errno = errno ? errno : ECANCELED
#define err_if(x) if (x) err(ERR(), NULL)
-#define xopen(f,l,p) if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \
- if (f == -1) if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
+#define xopen(f,l,p) \
+ if (f == -1) \
+ if (opendir(l) != NULL) err(errno = EISDIR, "%s", l); \
+ if ((f = open(l, p)) == -1) err(ERR(), "%s", l); \
struct stat st; if (fstat(f, &st) == -1) err(ERR(), "%s", l)
#define xpread(f, b, n, o, l) if (pread(f, b, n, o) == -1) err(ERR(), "%s", l)
#define handle_endianness() if (big_endian) xorswap_buf(p)