util/nvmutil: code cleanup

fsdg20230625
Leah Rowe 2023-01-27 19:52:11 +00:00
parent 7a98649764
commit b1186968e8
1 changed files with 9 additions and 19 deletions

View File

@ -62,7 +62,7 @@ size_t gbe[2];
uint8_t skipread[2] = {0, 0}; uint8_t skipread[2] = {0, 0};
int part, gbeFileModified = 0; int part, gbeFileModified = 0;
uint8_t nvmPartModified[2]; uint8_t nvmPartModified[2] = {0, 0};
uint16_t test; uint16_t test;
uint8_t little_endian; uint8_t little_endian;
@ -70,11 +70,9 @@ uint8_t little_endian;
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int fd;
size_t nr = 128; size_t nr = 128;
int flags = O_RDWR; int fd, flags = O_RDWR;
char *strMac = NULL; char *strMac = NULL, *strRMac = "??:??:??:??:??:??";
char *strRMac = "??:??:??:??:??:??";
void (*cmd)(void) = NULL; void (*cmd)(void) = NULL;
#ifdef HAVE_PLEDGE #ifdef HAVE_PLEDGE
@ -84,11 +82,7 @@ main(int argc, char *argv[])
if ((buf = (uint8_t *) malloc(SIZE_8KB)) == NULL) if ((buf = (uint8_t *) malloc(SIZE_8KB)) == NULL)
err(errno, NULL); err(errno, NULL);
gbe[0] = gbe[1] = (size_t) buf; gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB;
gbe[1] += SIZE_4KB;
nvmPartModified[0] = 0;
nvmPartModified[1] = 0;
test = 1; test = 1;
little_endian = ((uint8_t *) &test)[0]; little_endian = ((uint8_t *) &test)[0];
@ -141,19 +135,17 @@ main(int argc, char *argv[])
writeGbeFile(&fd, FILENAME); writeGbeFile(&fd, FILENAME);
nvmutil_exit: nvmutil_exit:
if (!((errno == ECANCELED) && (flags == O_RDONLY))) if ((errno != 0) && (cmd != &cmd_dump))
if (errno != 0) err(errno, NULL);
err(errno, NULL); else
return errno;
return errno;
} }
void void
readGbeFile(int *fd, const char *path, int flags, size_t nr) readGbeFile(int *fd, const char *path, int flags, size_t nr)
{ {
struct stat st; struct stat st;
int r, tr = 0; int p, r, tr = 0;
int p;
if (opendir(path) != NULL) if (opendir(path) != NULL)
err(errno = EISDIR, path); err(errno = EISDIR, path);
@ -463,8 +455,6 @@ writeGbeFile(int *fd, const char *filename)
} }
if (close((*fd))) if (close((*fd)))
err(errno, "%s", filename); err(errno, "%s", filename);
if (errno != 0)
err(errno, "%s", filename);
printf("%d bytes written to file: `%s`\n", tw, filename); printf("%d bytes written to file: `%s`\n", tw, filename);
} }