mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: maudspierings@gocontroll.com,
	Sascha Hauer <s.hauer@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>
Subject: Re: [PATCH 1/3] scripts: common: fix pread_full() for windows
Date: Fri, 28 Nov 2025 15:56:34 +0100	[thread overview]
Message-ID: <7e285378-cff8-4387-bb6e-02bb7d868faf@pengutronix.de> (raw)
In-Reply-To: <20251128-imx_usb-v1-1-bb6a5180b38e@gocontroll.com>

Hi,

On 11/28/25 3:08 PM, Maud Spierings via B4 Relay wrote:
> From: Maud Spierings <maudspierings@gocontroll.com>
> 
> pread() is not available for windows, convert to lseek() + read()
> 
> Signed-off-by: Maud Spierings <maudspierings@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.

Cheers,
Ahmad

> ---
>  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)
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2025-11-28 14:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28 14:08 [PATCH 0/3] scripts: imx: imx-usb-loader: fix mingw compilation Maud Spierings via B4 Relay
2025-11-28 14:08 ` [PATCH 1/3] scripts: common: fix pread_full() for windows Maud Spierings via B4 Relay
2025-11-28 14:56   ` Ahmad Fatoum [this message]
2025-11-28 15:00     ` Maud Spierings
2025-11-28 15:11       ` Ahmad Fatoum
2025-11-28 14:08 ` [PATCH 2/3] scripts: imx: Makefile.mingw64: add _GNU_SOURCE Maud Spierings via B4 Relay
2025-11-28 14:08 ` [PATCH 3/3] gitignore: ignore *.exe Maud Spierings via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7e285378-cff8-4387-bb6e-02bb7d868faf@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=maudspierings@gocontroll.com \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox