From 50d028a504a4091a350ea2fbcc447a4b2f8e6d87 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 28 Jun 2016 17:58:34 -0400 Subject: GTMServiceManagement.c: Don't use Gestalt() when targeting 10.8+ Gestalt() is deprecated with a 10.8 deployment target. Use the recommended replacement when deploying to 10.8 and 10.9, and just use a constant function when deploying to 10.10. --- Foundation/GTMServiceManagement.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'Foundation') diff --git a/Foundation/GTMServiceManagement.c b/Foundation/GTMServiceManagement.c index d19fd86..5e41ba0 100644 --- a/Foundation/GTMServiceManagement.c +++ b/Foundation/GTMServiceManagement.c @@ -43,6 +43,12 @@ #include #include +#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10 && \ + MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 +#include +#include +#endif + typedef struct { CFMutableDictionaryRef dict; bool convert_non_standard_objects; @@ -55,6 +61,31 @@ typedef struct { } GTMCFToLDictContext; static bool IsOsYosemiteOrGreater() { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10 + // In 10.10, [[NSProcessInfo processInfo] operatingSystemVersion] exists, + // but if we can assume 10.10 we already know the answer. + return true; +#elif MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_8 + // Gestalt() is deprected in 10.8, and the recommended replacement is sysctl. + // https://developer.apple.com/library/mac/releasenotes/General/CarbonCoreDeprecations/index.html#//apple_ref/doc/uid/TP40012224-CH1-SW16 + const size_t N = 128; + char buffer[N]; + size_t buffer_size = N; + int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; + if (sysctl(ctl_name, 2, buffer, &buffer_size, NULL, 0) != 0) { + return false; + } + // The buffer now contains a string of the form XX.YY.ZZ, where + // XX is the major kernel version component. + char* period_pos = strchr(buffer, '.'); + if (!period_pos) { + return false; + } + *period_pos = '\0'; + long kernel_version_major = strtol(buffer, NULL, 10); + // Kernel version 14 corresponds to OS X 10.10 Yosemite. + return kernel_version_major >= 14; +#else SInt32 version_major; SInt32 version_minor; require_noerr(Gestalt(gestaltSystemVersionMajor, &version_major), @@ -64,6 +95,7 @@ static bool IsOsYosemiteOrGreater() { return version_major > 10 || (version_major == 10 && version_minor >= 10); failedGestalt: return false; +#endif } static CFErrorRef GTMCFLaunchCreateUnlocalizedError(CFIndex code, -- cgit v1.2.3