PageRenderTime 31ms CodeModel.GetById 13ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/.attic/sshfs-gui/GoogleShared_SystemVersion.m

http://macfuse.googlecode.com/
Objective C | 92 lines | 66 code | 13 blank | 13 comment | 25 complexity | 7fad196743960e199eba6d61dab425d7 MD5 | raw file
 1//
 2//  GoogleShared_SystemVersion.m
 3//
 4//  Created by Dave MacLachlan on 04/18/07.
 5//  Copyright 2007 Google, Inc. All rights reserved.
 6//
 7
 8#import "GoogleShared_SystemVersion.h"
 9#import <Carbon/Carbon.h>
10#import <stdlib.h>
11
12@implementation GoogleShared_SystemVersion
13
14+ (BOOL)isPanther {
15  long major, minor;
16  [self getMajor:&major minor:&minor bugFix:nil];
17  return major == 10 && minor == 3;
18}
19
20+ (BOOL)isTiger {
21  long major, minor;
22  [self getMajor:&major minor:&minor bugFix:nil];
23  return major == 10 && minor == 4;
24}
25
26+ (BOOL)isLeopard {
27  long major, minor;
28  [self getMajor:&major minor:&minor bugFix:nil];
29  return major == 10 && minor == 5;
30}
31
32+ (BOOL)isPantherOrGreater {
33  long major, minor;
34  [self getMajor:&major minor:&minor bugFix:nil];
35  return (major > 10) || (major == 10 && minor >= 3);
36}
37
38+ (BOOL)isTigerOrGreater {
39  long major, minor;
40  [self getMajor:&major minor:&minor bugFix:nil];
41  return (major > 10) || (major == 10 && minor >= 4);
42}
43
44+ (BOOL)isLeopardOrGreater {
45  long major, minor;
46  [self getMajor:&major minor:&minor bugFix:nil];
47  return (major > 10) || (major == 10 && minor >= 5);
48}
49
50+ (void)getMajor:(long*)major minor:(long*)minor bugFix:(long*)bugFix {
51  OSStatus err = noErr;
52  long binaryCodedDec;
53  
54  if (major) {
55    require_noerr(Gestalt(gestaltSystemVersionMajor, major), failedGestalt);
56  }
57  if (minor) {
58    require_noerr(Gestalt(gestaltSystemVersionMinor, minor), failedGestalt);
59  }
60  if (bugFix) {
61    require_noerr(Gestalt(gestaltSystemVersionBugFix, bugFix), failedGestalt);
62  }
63  return;
64
65failedGestalt:
66  // gestaltSystemVersionMajor et al are only on 10.4 and above, so they
67  // could fail if we have this code on 10.3.
68  err = Gestalt(gestaltSystemVersion, &binaryCodedDec);
69  if (err) {
70    // Theory being if gestalt can't handle this basic selector, something
71    // serious is wrong.
72    abort();
73  }
74  
75  // Note that this code will return x.9.9 for any system rev parts that are
76  // greater than 9 (ie 10.10.10 will be 10.9.9. This shouldn't ever be a
77  // problem  as the code above takes care of this for any system above 10.4.
78  if (major) {
79    int msb = (binaryCodedDec & 0x0000F000L) >> 12;
80    msb *= 10;
81    int lsb = (binaryCodedDec & 0x00000F00L) >> 8;
82    *major = msb + lsb;
83  }
84  if (minor) {
85    *minor = (binaryCodedDec & 0x000000F0L) >> 4;
86  }
87  if (bugFix) {
88    *bugFix = (binaryCodedDec & 0x0000000FL);
89  }
90}
91
92@end