Chromium Code Reviews| Index: webrtc/base/macutils.cc |
| diff --git a/webrtc/base/macutils.cc b/webrtc/base/macutils.cc |
| index c05526affb73fb36d0f8f28113ebc951849b7f98..cd1d1c99c381278ca92375892061cec1bab09abc 100644 |
| --- a/webrtc/base/macutils.cc |
| +++ b/webrtc/base/macutils.cc |
| @@ -8,10 +8,11 @@ |
| * be found in the AUTHORS file in the root of the source tree. |
| */ |
| +#include <cstring> |
| #include <memory> |
| #include <sstream> |
| -#include <CoreServices/CoreServices.h> |
| +#include <sys/utsname.h> |
| #include "webrtc/base/common.h" |
| #include "webrtc/base/logging.h" |
| @@ -70,34 +71,27 @@ void DecodeFourChar(UInt32 fc, std::string* out) { |
| out->append(ss.str()); |
| } |
| -static bool GetGestalt(OSType ostype, int* value) { |
| - ASSERT(NULL != value); |
| - SInt32 native_value; |
| - OSStatus result = Gestalt(ostype, &native_value); |
| - if (noErr == result) { |
| - *value = native_value; |
| - return true; |
| - } |
| - std::string str; |
| - DecodeFourChar(ostype, &str); |
| - LOG_E(LS_ERROR, OS, result) << "Gestalt(" << str << ")"; |
| - return false; |
| -} |
| - |
| static bool GetOSVersion(int* major, int* minor, int* bugfix) { |
| ASSERT(major && minor && bugfix); |
| - if (!GetGestalt(gestaltSystemVersion, major)) { |
| + struct utsname uname_info; |
| + if (uname(&uname_info) != 0) |
| return false; |
| - } |
| - if (*major < 0x1040) { |
| - *bugfix = *major & 0xF; |
| - *minor = (*major >> 4) & 0xF; |
| - *major = (*major >> 8); |
| - return true; |
| - } |
| - return GetGestalt(gestaltSystemVersionMajor, major) && |
| - GetGestalt(gestaltSystemVersionMinor, minor) && |
| - GetGestalt(gestaltSystemVersionBugFix, bugfix); |
| + |
| + if (strcmp(uname_info.sysname, "Darwin") != 0) |
| + return false; |
| + *major = 10; |
| + |
| + // The market version of macOS is always 4 lower than the internal version. |
| + int minor_version = atoi(uname_info.release); |
| + assert(minor_version >= 6); |
|
Sergey Ulanov
2016/10/07 00:08:46
please use RTC_CHECK()
erikchen
2016/10/07 00:31:02
Done.
|
| + *minor = minor_version - 4; |
| + |
| + char delimiter = '.'; |
| + const char* dot = strchr(uname_info.release, &delimiter); |
| + if (!dot) |
| + return false; |
| + *bugfix = atoi(dot + 1); |
| + return true; |
| } |
| MacOSVersionName GetOSVersionName() { |