lbutils/file: rename rw_file_exact

call it rw_exact, so that it's closer to
the name rw. it matches naming more closely;
the alternative was to call rw rw_file

but read/write can handle more than just files!

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-04-01 16:20:12 +01:00
parent f68cedf202
commit fb81b7b736
4 changed files with 15 additions and 15 deletions
+1 -1
View File
@@ -457,7 +457,7 @@ ssize_t rw_gbe_file_exact(int fd, unsigned char *mem, size_t nrw,
*/
int fsync_dir(const char *path);
ssize_t rw_file_exact(int fd, unsigned char *mem, size_t len,
ssize_t rw_exact(int fd, unsigned char *mem, size_t len,
off_t off, int rw_type);
ssize_t rw(int fd, void *mem, size_t nrw,
off_t off, int rw_type);
+1 -1
View File
@@ -492,7 +492,7 @@ cat_buf(unsigned char *b)
if (b == NULL)
exitf("null pointer in cat command");
if (rw_file_exact(STDOUT_FILENO, b,
if (rw_exact(STDOUT_FILENO, b,
GBE_PART_SIZE, 0, IO_WRITE) < 0)
exitf("stdout: cat");
}
+9 -9
View File
@@ -127,7 +127,7 @@ err_fsync_dir:
return with_fallback_errno(EIO);
}
/* rw_file_exact() - Read perfectly or die
/* rw_exact() - Read perfectly or die
*
* Read/write, and absolutely insist on an
* absolute read; e.g. if 100 bytes are
@@ -145,7 +145,7 @@ err_fsync_dir:
*/
ssize_t
rw_file_exact(int fd, unsigned char *mem, size_t nrw,
rw_exact(int fd, unsigned char *mem, size_t nrw,
off_t off, int rw_type)
{
int saved_errno = errno;
@@ -157,13 +157,13 @@ rw_file_exact(int fd, unsigned char *mem, size_t nrw,
errno = 0;
if (io_args(fd, mem, nrw, off, rw_type) == -1)
goto err_rw_file_exact;
goto err_rw_exact;
while (1) {
/* Prevent theoretical overflow */
if (if_err(rval >= 0 && (size_t)rval > (nrw - rc), EOVERFLOW))
goto err_rw_file_exact;
goto err_rw_exact;
rc += rval;
if ((size_t)rc >= nrw)
@@ -173,22 +173,22 @@ rw_file_exact(int fd, unsigned char *mem, size_t nrw,
nrw_cur = (size_t)(nrw - (size_t)rc);
if (if_err(off < 0, EOVERFLOW))
goto err_rw_file_exact;
goto err_rw_exact;
off_cur = off + (off_t)rc;
if ((rval = rw(fd, mem_cur, nrw_cur, off_cur, rw_type)) <= 0)
goto err_rw_file_exact;
goto err_rw_exact;
}
if (if_err((size_t)rc != nrw, EIO) ||
(rval = rw_over_nrw(rc, nrw)) < 0)
goto err_rw_file_exact;
goto err_rw_exact;
reset_caller_errno(rval);
return rval;
err_rw_file_exact:
err_rw_exact:
return with_fallback_errno(EIO);
}
@@ -202,7 +202,7 @@ err_rw_file_exact:
*
* WARNING: this function allows zero-byte returns.
* this is intentional, to mimic libc behaviour.
* use rw_file_exact if you need to avoid this.
* use rw_exact if you need to avoid this.
* (ditto partial writes/reads)
*
*/
+4 -4
View File
@@ -108,7 +108,7 @@ read_file(void)
/* read main file
*/
_r = rw_file_exact(f->gbe_fd, f->buf, f->gbe_file_size,
_r = rw_exact(f->gbe_fd, f->buf, f->gbe_file_size,
0, IO_PREAD);
if (_r < 0)
@@ -116,7 +116,7 @@ read_file(void)
/* copy to tmpfile
*/
_r = rw_file_exact(f->tmp_fd, f->buf, f->gbe_file_size,
_r = rw_exact(f->tmp_fd, f->buf, f->gbe_file_size,
0, IO_PWRITE);
if (_r < 0)
@@ -139,7 +139,7 @@ read_file(void)
if (fsync_on_eintr(f->tmp_fd) == -1)
exitf("%s: fsync (tmpfile copy)", f->tname);
_r = rw_file_exact(f->tmp_fd, f->bufcmp, f->gbe_file_size,
_r = rw_exact(f->tmp_fd, f->bufcmp, f->gbe_file_size,
0, IO_PREAD);
if (_r < 0)
@@ -556,7 +556,7 @@ rw_gbe_file_exact(int fd, unsigned char *mem, size_t nrw,
if (nrw > (size_t)GBE_PART_SIZE)
goto err_rw_gbe_file_exact;
r = rw_file_exact(fd, mem, nrw, off, rw_type);
r = rw_exact(fd, mem, nrw, off, rw_type);
return rw_over_nrw(r, nrw);