Created
May 19, 2014 10:06
-
-
Save jjgod/16489e6810af9c2b284a to your computer and use it in GitHub Desktop.
Test whether a system is running 10.7 or later
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define MAC_OS_X_VERSION_10_7_HEX 0x00001070 | |
static int sOnLionOrLater = -1; | |
static bool OnLionOrLater() | |
{ | |
if (sOnLionOrLater < 0) { | |
SInt32 major = 0, minor = 0; | |
CFURLRef url = | |
CFURLCreateWithString(kCFAllocatorDefault, | |
CFSTR("file:///System/Library/CoreServices/SystemVersion.plist"), | |
NULL); | |
CFReadStreamRef stream = | |
CFReadStreamCreateWithFile(kCFAllocatorDefault, url); | |
CFReadStreamOpen(stream); | |
CFDictionaryRef sysVersionPlist = (CFDictionaryRef) | |
CFPropertyListCreateWithStream(kCFAllocatorDefault, | |
stream, 0, kCFPropertyListImmutable, | |
NULL, NULL); | |
CFReadStreamClose(stream); | |
CFRelease(stream); | |
CFRelease(url); | |
CFStringRef versionString = (CFStringRef) | |
CFDictionaryGetValue(sysVersionPlist, CFSTR("ProductVersion")); | |
CFArrayRef versions = | |
CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault, | |
versionString, CFSTR(".")); | |
CFIndex count = CFArrayGetCount(versions); | |
if (count > 0) { | |
CFStringRef component = (CFStringRef) CFArrayGetValueAtIndex(versions, 0); | |
major = CFStringGetIntValue(component); | |
if (count > 1) { | |
component = (CFStringRef) CFArrayGetValueAtIndex(versions, 1); | |
minor = CFStringGetIntValue(component); | |
} | |
} | |
CFRelease(sysVersionPlist); | |
CFRelease(versions); | |
if (major < 10) { | |
sOnLionOrLater = 0; | |
} else { | |
int version = 0x1000 + (minor << 4); | |
sOnLionOrLater = version >= MAC_OS_X_VERSION_10_7_HEX ? 1 : 0; | |
} | |
} | |
return sOnLionOrLater > 0 ? true : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment