[PATCH 1/3] scripts: common: fix pread_full() for windows

Maud Spierings maudspierings at gocontroll.com
Fri Nov 28 07:00:10 PST 2025


On 11/28/25 15:56, Ahmad Fatoum wrote:
> Hi,
> 
> On 11/28/25 3:08 PM, Maud Spierings via B4 Relay wrote:
>> From: Maud Spierings <maudspierings at gocontroll.com>
>>
>> pread() is not available for windows, convert to lseek() + read()
>>
>> Signed-off-by: Maud Spierings <maudspierings at gocontroll.com>
>>
>> ---
>>
>> I think this modifies the state of fd, I am not sure if pread() did this
>> too. May be necessary to point the file pointer where it was before? On
>> the other hand this reads the whole file so why.
> 
> I would prefer to ship a pread implementation for windows instead that
> takes care to lseek to wherever we need to read from and then lseek back
> to the original offset as not to induce subtle breakage into other host
> tools.
> 

just read the manpage a little better:
pread() reads up to count bytes from file descriptor fd at offset
offset (from the start of the file) into the buffer starting at
buf.  The file offset is not changed.

So yeah it should indeed seek back, I'll get on that.

> 
>> ---
>>   scripts/common.c | 6 +++++-
>>   1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/scripts/common.c b/scripts/common.c
>> index a6eee968b7..544d295b7f 100644
>> --- a/scripts/common.c
>> +++ b/scripts/common.c
>> @@ -202,8 +202,12 @@ int pread_full(int fd, void *buf, size_t size, loff_t offset)
>>   	size_t insize = size;
>>   	int now;
>>   
>> +	now = lseek(fd, offset, SEEK_SET);
>> +	if (now < 0)
>> +		return now;
>> +
>>   	while (size) {
>> -		now = pread(fd, buf, size, offset);
>> +		now = read(fd, buf, size);
>>   		if (now == 0)
>>   			break;
>>   		if (now < 0)
>>
> 




More information about the barebox mailing list