[PATCH 1/2] libfile: advance offset in pread_full() on short reads

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Aug 26 02:55:37 PDT 2026


pread_full() loops until the requested size was read, but reads from
the same offset on every iteration, so a short read is followed by
re-reading the same data instead of the remainder.

Advance the offset along with the buffer pointer.

Fixes: 59d6b83f1d4b ("libfile: implement new pread_full")
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
While a fix, I would keep it in next, just to watch if this leads to
adverse effects.
---
 lib/libfile.c    | 1 +
 scripts/common.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/libfile.c b/lib/libfile.c
index cf78c70354d9..bd0118a7e5be 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -93,6 +93,7 @@ int pread_full(int fd, void *buf, size_t size, loff_t offset)
 			return now;
 		size -= now;
 		buf += now;
+		offset += now;
 	}
 
 	return insize - size;
diff --git a/scripts/common.c b/scripts/common.c
index a6eee968b79d..6615cfb38b55 100644
--- a/scripts/common.c
+++ b/scripts/common.c
@@ -210,6 +210,7 @@ int pread_full(int fd, void *buf, size_t size, loff_t offset)
 			return now;
 		size -= now;
 		buf += now;
+		offset += now;
 	}
 
 	return insize - size;
-- 
2.47.3




More information about the barebox mailing list