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