From: Maud Spierings <[email protected]> Add a simple pread implementation for the mingw target so imx-usb-loader can be compiled for windows.
This function is actually only called by bareboxtlv, which I don't think targets being compiled for windows, so it is a bit of a dead weight. Signed-off-by: Maud Spierings <[email protected]> Reviewed-by: Ahmad Fatoum <[email protected]> Link: https://lore.barebox.org/[email protected] Signed-off-by: Sascha Hauer <[email protected]> (cherry picked from commit 969c9b94b58de50ab0db2eeef0a4dcfad4f5da5c) Signed-off-by: Ahmad Fatoum <[email protected]> --- scripts/imx/Makefile.mingw64 | 2 +- scripts/imx/pread.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 scripts/imx/pread.c diff --git a/scripts/imx/Makefile.mingw64 b/scripts/imx/Makefile.mingw64 index 101b39e9178d..a7be48ae5333 100644 --- a/scripts/imx/Makefile.mingw64 +++ b/scripts/imx/Makefile.mingw64 @@ -33,7 +33,7 @@ obj := $(realpath $(obj)) CPPFLAGS := -I $(LIBUSB_MINGW)/include/libusb-1.0 -I $(src)/../include/ -I $(src)/../../include/mach/ -include $(src)/../include/defines.h LDFLAGS := -L $(LIBUSB_MINGW)/lib -lusb-1.0 -static -OBJECTS := $(addprefix $(obj)/, imx.o imx-usb-loader.o) +OBJECTS := $(addprefix $(obj)/, imx.o imx-usb-loader.o pread.o) $(obj)/%.o: $(src)/%.c @$(CC) -c -o $@ $< $(CPPFLAGS) diff --git a/scripts/imx/pread.c b/scripts/imx/pread.c new file mode 100644 index 000000000000..febb6f32432c --- /dev/null +++ b/scripts/imx/pread.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// SPDX-FileCopyrightText: 2025 Maud Spierings, GOcontroll B.V. + +#include <stdint.h> +#include <sys/types.h> +#include <unistd.h> + +ssize_t pread(int fd, void *buf, size_t count, off_t offset) +{ + int offset_start, now; + + offset_start = lseek(fd, 0, SEEK_CUR); + if (offset_start < 0) + return offset_start; + + now = lseek(fd, offset, SEEK_SET); + if (now < 0) + return now; + + now = read(fd, buf, count); + + lseek(fd, offset_start, SEEK_SET); + + return now; +} -- 2.47.3
