File 0004-fsck_hfs-Port-byteswap-code-to-Linux.patch of Package hfsplus-tools

From e6c69646bbd39765ff74a6b4c46069811bcdad66 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Tue, 20 Jun 2023 16:58:13 +0200
Subject: [PATCH 4/7] fsck_hfs: Port byteswap code to Linux

---
 fsck_hfs/dfalib/fsck_journal.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/fsck_hfs/dfalib/fsck_journal.c b/fsck_hfs/dfalib/fsck_journal.c
index 10d8033..4ea2e53 100644
--- a/fsck_hfs/dfalib/fsck_journal.c
+++ b/fsck_hfs/dfalib/fsck_journal.c
@@ -51,27 +51,43 @@
 extern char debug;
 
 #include <hfs/hfs_format.h>
+
+#if !LINUX
 #include <libkern/OSByteOrder.h>
+#else
+#include <byteswap.h>
+#define OSSwapInt16(x) bswap_16(x)
+#define OSSwapInt32(x) bswap_32(x)
+#define OSSwapInt64(x) bswap_64(x)
+#endif
+
+uint16_t nativeEndian16 (uint16_t x) { return x; }
+uint32_t nativeEndian32 (uint32_t x) { return x; }
+uint64_t nativeEndian64 (uint64_t x) { return x; }
+
+uint16_t swappedEndian16 (uint16_t x) { return OSSwapInt16(x); }
+uint32_t swappedEndian32 (uint32_t x) { return OSSwapInt32(x); }
+uint64_t swappedEndian64 (uint64_t x) { return OSSwapInt64(x); }
 
 typedef struct SwapType {
 	const char *name;
-	uint16_t (^swap16)(uint16_t);
-	uint32_t (^swap32)(uint32_t);
-	uint64_t (^swap64)(uint64_t);
+	uint16_t (* swap16)(uint16_t);
+	uint32_t (* swap32)(uint32_t);
+	uint64_t (* swap64)(uint64_t);
 } swapper_t;
 
 static swapper_t nativeEndian = {
 	"native endian",
-	^(uint16_t x) { return x; },
-	^(uint32_t x) { return x; },
-	^(uint64_t x) { return x; }
+	&nativeEndian16,
+	&nativeEndian32,
+	&nativeEndian64
 };
 
 static swapper_t swappedEndian = {
 	"swapped endian",
-	^(uint16_t x) { return OSSwapInt16(x); },
-	^(uint32_t x) { return OSSwapInt32(x); },
-	^(uint64_t x) { return OSSwapInt64(x); }
+	&swappedEndian16,
+	&swappedEndian32,
+	&swappedEndian64
 };
 
 //
-- 
2.41.0

openSUSE Build Service is sponsored by