From c064f12df209043cbc47b99c5ccb1aef41d2627b Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Tue, 6 Aug 2024 03:52:56 +0800
Subject: [PATCH 17/21] Fix compatibility with 10.4

---
 src/common/processing_linux.c                   | 8 ++++++--
 src/detection/host/host_apple.c                 | 4 +++-
 src/detection/memory/memory_apple.c             | 2 ++
 src/detection/temps/temps_apple.c               | 3 +++
 src/detection/terminalfont/terminalfont_apple.m | 5 ++++-
 src/util/platform/FFPlatform_unix.c             | 5 ++++-
 6 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c
index af3f4ebf..b2b1d6fa 100644
--- a/src/common/processing_linux.c
+++ b/src/common/processing_linux.c
@@ -19,7 +19,10 @@
     #include <sys/sysctl.h>
 #endif
 #if defined(__APPLE__)
-    #include <libproc.h>
+  #include <AvailabilityMacros.h>
+  #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
+      #include <libproc.h>
+  #endif
 #elif defined(__sun)
     #include <procfs.h>
 #endif
@@ -185,6 +188,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
             ffStrbufSetS(exe, arg0);
         }
     }
+    #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // No proc_pidpath on 10.4
     else
     {
         ffStrbufEnsureFixedLengthFree(exe, PATH_MAX);
@@ -196,7 +200,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
                 ffStrbufSet(exePath, exe);
         }
     }
-
+    #endif
     #elif defined(__FreeBSD__)
 
     size_t size = ARG_MAX;
diff --git a/src/detection/host/host_apple.c b/src/detection/host/host_apple.c
index efc15ab5..10fd867c 100644
--- a/src/detection/host/host_apple.c
+++ b/src/detection/host/host_apple.c
@@ -4,6 +4,7 @@
 #include "util/stringUtils.h"
 
 #include <IOKit/IOKitLib.h>
+#include <AvailabilityMacros.h>
 
 static const char* getProductNameWithHwModel(const FFstrbuf* hwModel)
 {
@@ -238,6 +239,7 @@ const char* getProductNameWithIokit(FFstrbuf* result)
 
 const char* getOthersByIokit(FFHostResult* host)
 {
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice"));
     if (!registryEntry)
         return "IOServiceGetMatchingService() failed";
@@ -253,7 +255,7 @@ const char* getOthersByIokit(FFHostResult* host)
     FF_CFTYPE_AUTO_RELEASE CFStringRef manufacturer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
     if (manufacturer)
         ffCfStrGetString(manufacturer, &host->vendor);
-
+#endif
     return NULL;
 }
 
diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c
index cdfdee12..23ce20dc 100644
--- a/src/detection/memory/memory_apple.c
+++ b/src/detection/memory/memory_apple.c
@@ -28,7 +28,9 @@ const char* ffDetectMemory(FFMemoryResult* ram)
     ram->bytesUsed = ((uint64_t)
         + vmstat.active_count
         + vmstat.inactive_count
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
         + vmstat.speculative_count
+#endif
         + vmstat.wire_count
 #if (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) && !defined(__ppc__)
         + vmstat.compressor_page_count
diff --git a/src/detection/temps/temps_apple.c b/src/detection/temps/temps_apple.c
index c4cef782..0fea5a84 100644
--- a/src/detection/temps/temps_apple.c
+++ b/src/detection/temps/temps_apple.c
@@ -5,6 +5,7 @@
 #include <stdint.h>
 #include <math.h>
 #include <IOKit/IOKitLib.h>
+#include <AvailabilityMacros.h>
 
 static const char kSmcCmdReadBytes = 5;
 static const char kSmcCmdReadKeyInfo = 9;
@@ -87,7 +88,9 @@ static const char *smcCall(io_connect_t conn, uint32_t selector, SmcKeyData_t *i
 {
     size_t size = sizeof(SmcKeyData_t);
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     if (IOConnectCallStructMethod(conn, selector, inputStructure, size, outputStructure, &size) != kIOReturnSuccess)
+#endif
         return "IOConnectCallStructMethod(conn) failed";
     return NULL;
 }
diff --git a/src/detection/terminalfont/terminalfont_apple.m b/src/detection/terminalfont/terminalfont_apple.m
index 96917199..b3f50ffa 100644
--- a/src/detection/terminalfont/terminalfont_apple.m
+++ b/src/detection/terminalfont/terminalfont_apple.m
@@ -5,7 +5,8 @@
 
 #include <stdlib.h>
 #include <string.h>
-#import <Foundation/Foundation.h>
+#include <Foundation/Foundation.h>
+#include <AvailabilityMacros.h>
 
 static void detectIterm2(FFTerminalFontResult* terminalFont)
 {
@@ -18,6 +19,7 @@ static void detectIterm2(FFTerminalFontResult* terminalFont)
 
     NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.googlecode.iterm2.plist"]];
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 // This chunk of code breaks linkage on 10.4
     for(NSDictionary* bookmark in [dict valueForKey:@"New Bookmarks"])
     {
         if(![[bookmark valueForKey:@"Name"] isEqualToString:[NSString stringWithUTF8String:profile]])
@@ -40,6 +42,7 @@ static void detectIterm2(FFTerminalFontResult* terminalFont)
         }
         return;
     }
+#endif
 
     ffStrbufAppendF(&terminalFont->error, "find profile `%s` bookmark failed", profile);
 }
diff --git a/src/util/platform/FFPlatform_unix.c b/src/util/platform/FFPlatform_unix.c
index b442eed5..8cac81f2 100644
--- a/src/util/platform/FFPlatform_unix.c
+++ b/src/util/platform/FFPlatform_unix.c
@@ -10,7 +10,10 @@
 #include <paths.h>
 
 #ifdef __APPLE__
+  #include <AvailabilityMacros.h>
+  #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
     #include <libproc.h>
+  #endif
     #include <sys/sysctl.h>
 #elif defined(__FreeBSD__)
     #include <sys/sysctl.h>
@@ -22,7 +25,7 @@ static void getExePath(FFPlatform* platform)
     #ifdef __linux__
         ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
         exePath[exePathLen] = '\0';
-    #elif defined(__APPLE__)
+    #elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
         int exePathLen = proc_pidpath((int) getpid(), exePath, sizeof(exePath));
     #elif defined(__FreeBSD__)
         size_t exePathLen = sizeof(exePath);
-- 
2.46.0

