aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-28 17:58:34 -0400
committerGravatar Thomas Van Lenten <thomasvl@google.com>2016-06-28 17:58:34 -0400
commit50d028a504a4091a350ea2fbcc447a4b2f8e6d87 (patch)
tree80c92cd7994e2daf229e5e6b66b82ed1d1efa9e1 /Foundation
parent6fd164a3c5b8734f682b8028f6ec719fb8c3fe07 (diff)
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.
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMServiceManagement.c32
1 files changed, 32 insertions, 0 deletions
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 <sys/stat.h>
#include <vproc.h>
+#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 <sys/types.h>
+#include <sys/sysctl.h>
+#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,