mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 18:34:57 +02:00
util/nvmutil: tidy up write_gbe
by handling close() in main, we can reduce the indendation in write_gbe and generally make it much easier to read. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+13
-7
@@ -122,6 +122,8 @@ main(int argc, char *argv[])
|
|||||||
(*cmd)();
|
(*cmd)();
|
||||||
write_gbe();
|
write_gbe();
|
||||||
|
|
||||||
|
err_if(close(fd) == -1);
|
||||||
|
|
||||||
err_if((errno != 0) && (cmd != cmd_dump));
|
err_if((errno != 0) && (cmd != cmd_dump));
|
||||||
return errno ? EXIT_FAILURE : EXIT_SUCCESS;
|
return errno ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -520,21 +522,25 @@ write_gbe(void)
|
|||||||
{
|
{
|
||||||
int p;
|
int p;
|
||||||
|
|
||||||
if (flags != O_RDONLY)
|
if (flags == O_RDONLY)
|
||||||
for (p = 0; p < 2; p++)
|
return;
|
||||||
if (part_modified[p])
|
|
||||||
write_gbe_part(p);
|
for (p = 0; p < 2; p++) {
|
||||||
err_if(close(fd) == -1);
|
if (part_modified[p])
|
||||||
|
write_gbe_part(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
write_gbe_part(int p)
|
write_gbe_part(int p)
|
||||||
{
|
{
|
||||||
swap(p); /* swap bytes on big-endian host CPUs */
|
swap(p); /* swap bytes on big-endian host CPUs */
|
||||||
if(pwrite(fd, buf + (SIZE_4KB * p), SIZE_4KB, p * partsize)
|
|
||||||
!= SIZE_4KB)
|
if (pwrite(fd, buf + (SIZE_4KB * p),
|
||||||
|
SIZE_4KB, p * partsize) != SIZE_4KB) {
|
||||||
err(set_err(ECANCELED),
|
err(set_err(ECANCELED),
|
||||||
"Can't write %d b to '%s' p%d", SIZE_4KB, fname, p);
|
"Can't write %d b to '%s' p%d", SIZE_4KB, fname, p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user