[PATCH 4/5] libfile: drop TFTP-specific hack in open_fdt()
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Mar 12 07:44:24 PDT 2026
Now that TFTP internally does the equivalent of closing and reopening
a file when seeking back, switch to using that in open_fdt() instead
of open-coding it.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
lib/libfile.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/libfile.c b/lib/libfile.c
index f5cea7b94998..0670ef0584cb 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -976,7 +976,7 @@ int open_fdt(const char *filename, size_t *size)
if (ret)
goto err;
- ret = pread_full(fd, &fdt_hdr, sizeof(fdt_hdr), 0);
+ ret = read_full(fd, &fdt_hdr, sizeof(fdt_hdr));
if (ret >= 0 && ret < sizeof(fdt_hdr))
ret = -EILSEQ;
if (ret < 0)
@@ -988,13 +988,12 @@ int open_fdt(const char *filename, size_t *size)
goto err;
}
- close(fd);
-
- /* HACK: TFTP doesn't support backwards seeking, so reopen afresh */
- fd = open(filename, O_RDONLY);
- if (fd >= 0)
- *size = fdt_size;
+ if (lseek(fd, 0, SEEK_SET) != 0) {
+ ret = -errno;
+ goto err;
+ }
+ *size = fdt_size;
return fd;
err:
close(fd);
--
2.47.3
More information about the barebox
mailing list