Chromium Code Reviews| 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 |
| 16 #include "webrtc/base/common.h" | 17 #include "webrtc/base/common.h" |
| 17 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/macutils.h" | 19 #include "webrtc/base/macutils.h" |
| 19 #include "webrtc/base/stringutils.h" | 20 #include "webrtc/base/stringutils.h" |
| 20 | 21 |
| 21 namespace rtc { | 22 namespace rtc { |
| 22 | 23 |
| 23 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
| 24 | 25 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 } | 64 } |
| 64 if (printable) { | 65 if (printable) { |
| 65 ss << '\''; | 66 ss << '\''; |
| 66 } else { | 67 } else { |
| 67 ss.str(""); | 68 ss.str(""); |
| 68 ss << "0x" << std::hex << fc; | 69 ss << "0x" << std::hex << fc; |
| 69 } | 70 } |
| 70 out->append(ss.str()); | 71 out->append(ss.str()); |
| 71 } | 72 } |
| 72 | 73 |
| 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) { | 74 static bool GetOSVersion(int* major, int* minor, int* bugfix) { |
| 88 ASSERT(major && minor && bugfix); | 75 ASSERT(major && minor && bugfix); |
| 89 if (!GetGestalt(gestaltSystemVersion, major)) { | 76 struct utsname uname_info; |
| 77 if (uname(&uname_info) != 0) | |
| 90 return false; | 78 return false; |
| 91 } | 79 |
| 92 if (*major < 0x1040) { | 80 if (strcmp(uname_info.sysname, "Darwin") != 0) |
| 93 *bugfix = *major & 0xF; | 81 return false; |
| 94 *minor = (*major >> 4) & 0xF; | 82 *major = 10; |
| 95 *major = (*major >> 8); | 83 |
| 96 return true; | 84 // The market version of macOS is always 4 lower than the internal version. |
|
kthelgason
2016/10/05 18:23:26
This should not be relied upon. Though there has b
erikchen
2016/10/05 20:16:35
-[NSProcessInfo operatingSystemVersion] isn't avai
Sergey Ulanov
2016/10/05 23:04:45
Maybe add CHECK(atoi(uname_info.release) >= 6) her
erikchen
2016/10/05 23:48:43
Done.
| |
| 97 } | 85 *minor = atoi(uname_info.release) - 4; |
| 98 return GetGestalt(gestaltSystemVersionMajor, major) && | 86 |
| 99 GetGestalt(gestaltSystemVersionMinor, minor) && | 87 char delimiter = '.'; |
| 100 GetGestalt(gestaltSystemVersionBugFix, bugfix); | 88 const char* dot = strchr(uname_info.release, &delimiter); |
|
Sergey Ulanov
2016/10/05 23:04:45
strchr() takes char as the second argument, but yo
erikchen
2016/10/05 23:48:43
webrtc uses an inlined strchr that has a different
Sergey Ulanov
2016/10/07 00:08:46
This is a wchar_t version, which I don't think is
erikchen
2016/10/07 00:31:02
ah, yup, switched to ::strchr().
| |
| 89 if (!dot) | |
| 90 return false; | |
| 91 *bugfix = atoi(dot + 1); | |
| 92 return true; | |
| 101 } | 93 } |
| 102 | 94 |
| 103 MacOSVersionName GetOSVersionName() { | 95 MacOSVersionName GetOSVersionName() { |
| 104 int major = 0, minor = 0, bugfix = 0; | 96 int major = 0, minor = 0, bugfix = 0; |
| 105 if (!GetOSVersion(&major, &minor, &bugfix)) { | 97 if (!GetOSVersion(&major, &minor, &bugfix)) { |
| 106 return kMacOSUnknown; | 98 return kMacOSUnknown; |
| 107 } | 99 } |
| 108 if (major > 10) { | 100 if (major > 10) { |
| 109 return kMacOSNewer; | 101 return kMacOSNewer; |
| 110 } | 102 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 123 case 7: | 115 case 7: |
| 124 return kMacOSLion; | 116 return kMacOSLion; |
| 125 case 8: | 117 case 8: |
| 126 return kMacOSMountainLion; | 118 return kMacOSMountainLion; |
| 127 case 9: | 119 case 9: |
| 128 return kMacOSMavericks; | 120 return kMacOSMavericks; |
| 129 } | 121 } |
| 130 return kMacOSNewer; | 122 return kMacOSNewer; |
| 131 } | 123 } |
| 132 } // namespace rtc | 124 } // namespace rtc |
| OLD | NEW |