Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 53 lines (44 sloc) 1.566 kb
3660578 @firecore think for yourself, question authority
authored
1
2 @implementation NSApplication (SystemVersion)
3
4 - (void)getSystemVersionMajor:(unsigned *)major
5 minor:(unsigned *)minor
6 bugFix:(unsigned *)bugFix;
7 {
8 OSErr err;
9 SInt32 systemVersion, versionMajor, versionMinor, versionBugFix;
10 if ((err = Gestalt(gestaltSystemVersion, &systemVersion)) != noErr) goto fail;
11 if (systemVersion < 0x1040)
12 {
13 if (major) *major = ((systemVersion & 0xF000) >> 12) * 10 +
14 ((systemVersion & 0x0F00) >> 8);
15 if (minor) *minor = (systemVersion & 0x00F0) >> 4;
16 if (bugFix) *bugFix = (systemVersion & 0x000F);
17 }
18 else
19 {
20 if ((err = Gestalt(gestaltSystemVersionMajor, &versionMajor)) != noErr) goto fail;
21 if ((err = Gestalt(gestaltSystemVersionMinor, &versionMinor)) != noErr) goto fail;
22 if ((err = Gestalt(gestaltSystemVersionBugFix, &versionBugFix)) != noErr) goto fail;
23 if (major) *major = versionMajor;
24 if (minor) *minor = versionMinor;
25 if (bugFix) *bugFix = versionBugFix;
26 }
27
28 return;
29
30 fail:
31 NSLog(@"Unable to obtain system version: %ld", (long)err);
32 if (major) *major = 10;
33 if (minor) *minor = 0;
34 if (bugFix) *bugFix = 0;
35 }
36
37 @end
38
39 /*
40 int main(void)
41 {
42 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
43
44 unsigned major, minor, bugFix;
45 [[NSApplication sharedApplication]
46 getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
47 NSLog(@"%u.%u.%u", major, minor, bugFix);
48
49 [pool release];
50 return EXIT_SUCCESS;
51 }
52
53 */
Something went wrong with that request. Please try again.