(OSX) Implement OSX version number detection

This commit is contained in:
Twinaphex 2016-01-13 20:48:56 +01:00
parent f1923f9a84
commit aac630a021
1 changed files with 21 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#ifdef __OBJC__
#include <Foundation/NSPathUtilities.h>
#include <objc/message.h>
#endif
#if defined(OSX)
@ -310,6 +311,26 @@ static void frontend_darwin_get_os(char *s, size_t len, int *major, int *minor)
get_ios_version(major, minor);
strlcpy(s, "iOS", len);
#elif defined(OSX)
typedef struct
{
NSInteger majorVersion;
NSInteger minorVersion;
NSInteger patchVersion;
} NSMyOSVersion;
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)])
{
NSMyOSVersion version = ((NSMyOSVersion(*)(id, SEL))objc_msgSend_stret)([NSProcessInfo processInfo], @selector(operatingSystemVersion));
*major = version.majorVersion;
*minor = version.minorVersion;
}
else
{
UInt32 version = 0;
OSStatus err = Gestalt(gestaltSystemVersion, (SInt32*)&version);
(void)err;
sscanf(version, "%d.%d", major, minor);
}
strlcpy(s, "OSX", len);
#endif
}