blob: 5f15402930216b62c04d41d381edbaa294650c48 [file] [log] [blame]
Zachary Turner97a14e62014-08-19 17:18:29 +00001//===-- HostInfoMacOSX.mm ---------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Host/macosx/HostInfoMacOSX.h"
11#include "lldb/Interpreter/Args.h"
12
13// C++ Includes
14#include <string>
15
16// C inclues
17#include <sys/sysctl.h>
18#include <sys/types.h>
19
20// Objective C/C++ includes
21#include <CoreFoundation/CoreFoundation.h>
22#include <Foundation/Foundation.h>
23#include <objc/objc-auto.h>
24
25using namespace lldb_private;
26
27bool
28HostInfoMacOSX::GetOSBuildString(std::string &s)
29{
30 int mib[2] = {CTL_KERN, KERN_OSVERSION};
31 char cstr[PATH_MAX];
32 size_t cstr_len = sizeof(cstr);
33 if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
34 {
35 s.assign(cstr, cstr_len);
36 return true;
37 }
38
39 s.clear();
40 return false;
41}
42
43bool
44HostInfoMacOSX::GetOSKernelDescription(std::string &s)
45{
46 int mib[2] = {CTL_KERN, KERN_VERSION};
47 char cstr[PATH_MAX];
48 size_t cstr_len = sizeof(cstr);
49 if (::sysctl(mib, 2, cstr, &cstr_len, NULL, 0) == 0)
50 {
51 s.assign(cstr, cstr_len);
52 return true;
53 }
54 s.clear();
55 return false;
56}
57
58bool
59HostInfoMacOSX::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update)
60{
61 static uint32_t g_major = 0;
62 static uint32_t g_minor = 0;
63 static uint32_t g_update = 0;
64
65 if (g_major == 0)
66 {
67 @autoreleasepool
68 {
69 NSDictionary *version_info = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
70 NSString *version_value = [version_info objectForKey:@"ProductVersion"];
71 const char *version_str = [version_value UTF8String];
72 if (version_str)
73 Args::StringToVersion(version_str, g_major, g_minor, g_update);
74 }
75 }
76
77 if (g_major != 0)
78 {
79 major = g_major;
80 minor = g_minor;
81 update = g_update;
82 return true;
83 }
84 return false;
85}