| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <cstring> |
| 11 #include <memory> | 12 #include <memory> |
| 12 #include <sstream> | 13 #include <sstream> |
| 13 | 14 |
| 14 #include <CoreServices/CoreServices.h> | 15 #include <sys/utsname.h> |
| 15 | 16 |
| 17 #include "webrtc/base/checks.h" |
| 16 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 17 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/macutils.h" | 20 #include "webrtc/base/macutils.h" |
| 19 #include "webrtc/base/stringutils.h" | 21 #include "webrtc/base/stringutils.h" |
| 20 | 22 |
| 21 namespace rtc { | 23 namespace rtc { |
| 22 | 24 |
| 23 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
| 24 | 26 |
| 25 bool ToUtf8(const CFStringRef str16, std::string* str8) { | 27 bool ToUtf8(const CFStringRef str16, std::string* str8) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 65 } |
| 64 if (printable) { | 66 if (printable) { |
| 65 ss << '\''; | 67 ss << '\''; |
| 66 } else { | 68 } else { |
| 67 ss.str(""); | 69 ss.str(""); |
| 68 ss << "0x" << std::hex << fc; | 70 ss << "0x" << std::hex << fc; |
| 69 } | 71 } |
| 70 out->append(ss.str()); | 72 out->append(ss.str()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 static bool GetGestalt(OSType ostype, int* value) { | |
| 74 ASSERT(NULL != value); | |
| 75 SInt32 native_value; | |
| 76 OSStatus result = Gestalt(ostype, &native_value); | |
| 77 if (noErr == result) { | |
| 78 *value = native_value; | |
| 79 return true; | |
| 80 } | |
| 81 std::string str; | |
| 82 DecodeFourChar(ostype, &str); | |
| 83 LOG_E(LS_ERROR, OS, result) << "Gestalt(" << str << ")"; | |
| 84 return false; | |
| 85 } | |
| 86 | |
| 87 static bool GetOSVersion(int* major, int* minor, int* bugfix) { | 75 static bool GetOSVersion(int* major, int* minor, int* bugfix) { |
| 88 ASSERT(major && minor && bugfix); | 76 ASSERT(major && minor && bugfix); |
| 89 if (!GetGestalt(gestaltSystemVersion, major)) { | 77 struct utsname uname_info; |
| 78 if (uname(&uname_info) != 0) |
| 90 return false; | 79 return false; |
| 91 } | 80 |
| 92 if (*major < 0x1040) { | 81 if (strcmp(uname_info.sysname, "Darwin") != 0) |
| 93 *bugfix = *major & 0xF; | 82 return false; |
| 94 *minor = (*major >> 4) & 0xF; | 83 *major = 10; |
| 95 *major = (*major >> 8); | 84 |
| 96 return true; | 85 // The market version of macOS is always 4 lower than the internal version. |
| 97 } | 86 int minor_version = atoi(uname_info.release); |
| 98 return GetGestalt(gestaltSystemVersionMajor, major) && | 87 RTC_CHECK(minor_version >= 6); |
| 99 GetGestalt(gestaltSystemVersionMinor, minor) && | 88 *minor = minor_version - 4; |
| 100 GetGestalt(gestaltSystemVersionBugFix, bugfix); | 89 |
| 90 const char* dot = ::strchr(uname_info.release, '.'); |
| 91 if (!dot) |
| 92 return false; |
| 93 *bugfix = atoi(dot + 1); |
| 94 return true; |
| 101 } | 95 } |
| 102 | 96 |
| 103 MacOSVersionName GetOSVersionName() { | 97 MacOSVersionName GetOSVersionName() { |
| 104 int major = 0, minor = 0, bugfix = 0; | 98 int major = 0, minor = 0, bugfix = 0; |
| 105 if (!GetOSVersion(&major, &minor, &bugfix)) { | 99 if (!GetOSVersion(&major, &minor, &bugfix)) { |
| 106 return kMacOSUnknown; | 100 return kMacOSUnknown; |
| 107 } | 101 } |
| 108 if (major > 10) { | 102 if (major > 10) { |
| 109 return kMacOSNewer; | 103 return kMacOSNewer; |
| 110 } | 104 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 case 7: | 117 case 7: |
| 124 return kMacOSLion; | 118 return kMacOSLion; |
| 125 case 8: | 119 case 8: |
| 126 return kMacOSMountainLion; | 120 return kMacOSMountainLion; |
| 127 case 9: | 121 case 9: |
| 128 return kMacOSMavericks; | 122 return kMacOSMavericks; |
| 129 } | 123 } |
| 130 return kMacOSNewer; | 124 return kMacOSNewer; |
| 131 } | 125 } |
| 132 } // namespace rtc | 126 } // namespace rtc |
| OLD | NEW |