From 60e044199e773df4863405dba0f7abe16a43282d Mon Sep 17 00:00:00 2001
From: Mark Mentovai <mark@mentovai.com>
Date: Fri, 29 May 2026 12:48:31 -0400
Subject: [PATCH] gen_init_cpio: fix build on macOS hosts

ae18b94099b0 (2025-08-20, in 6.18) introduced a dependency on the
Linux-specific O_LARGEFILE, and 97169cd6d95b (2025-08-20, in 6.18)
introduced a dependency on the Linux-specific copy_file_range. Both of
these commits were a part of the
https://lore.kernel.org/all/20250819032607.28727-1-ddiss@suse.de/
series. These new dependencies may not be available on non-Linux
systems, although it is possible to cross-build Linux on non-Linux build
hosts, and it is appropriate to run tools like gen_init_cpio on such
build hosts. It is straightforward to avoid these Linux-specific
features when not building on Linux.

Signed-off-by: Mark Mentovai <mark@mentovai.com>
---
 usr/gen_init_cpio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

--- a/usr/gen_init_cpio.c
+++ b/usr/gen_init_cpio.c
@@ -456,6 +456,7 @@ static int cpio_mkfile(const char *name,
 		    push_pad(namepadlen ? namepadlen : padlen(offset, 4)) < 0)
 			goto error;
 
+#ifdef __linux__
 		if (size) {
 			this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
 			if (this_read > 0) {
@@ -466,6 +467,7 @@ static int cpio_mkfile(const char *name,
 			}
 			/* short or failed copy falls back to read/write... */
 		}
+#endif
 
 		while (size) {
 			unsigned char filebuf[65536];
@@ -674,7 +676,11 @@ int main (int argc, char *argv[])
 			break;
 		case 'o':
 			outfd = open(optarg,
-				     O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC,
+				     O_WRONLY | O_CREAT | O_TRUNC
+#ifdef O_LARGEFILE
+					     | O_LARGEFILE
+#endif
+				     ,
 				     0600);
 			if (outfd < 0) {
 				fprintf(stderr, "failed to open %s\n", optarg);
