blob: dfaff795437531c49467a4552140fa256c345700 [file] [log] [blame]
Zachary Turner97a14e62014-08-19 17:18:29 +00001//===-- HostInfoWindows.cpp -------------------------------------*- 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/windows/windows.h"
11
12#include "lldb/Host/windows/HostInfoWindows.h"
13#include "llvm/ADT/SmallString.h"
14#include "llvm/Support/raw_ostream.h"
15
16using namespace lldb_private;
17
18size_t
19HostInfoWindows::GetPageSize()
20{
21 SYSTEM_INFO systemInfo;
22 GetNativeSystemInfo(&systemInfo);
23 return systemInfo.dwPageSize;
24}
25
26bool
27HostInfoWindows::GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update)
28{
29 OSVERSIONINFOEX info;
30
31 ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
32 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
33#pragma warning(push)
34#pragma warning(disable : 4996)
35 // Starting with Microsoft SDK for Windows 8.1, this function is deprecated in favor of the
36 // new Windows Version Helper APIs. Since we don't specify a minimum SDK version, it's easier
37 // to simply disable the warning rather than try to support both APIs.
38 if (GetVersionEx((LPOSVERSIONINFO)&info) == 0)
39 {
40 return false;
41 }
42#pragma warning(pop)
43
44 major = info.dwMajorVersion;
45 minor = info.dwMinorVersion;
46 update = info.wServicePackMajor;
47
48 return true;
49}
50
51bool
52HostInfoWindows::GetOSBuildString(std::string &s)
53{
54 s.clear();
55 uint32_t major, minor, update;
56 if (!GetOSVersion(major, minor, update))
57 return false;
58
59 llvm::raw_string_ostream stream(s);
60 stream << "Windows NT " << major << "." << minor << "." << update;
61 return true;
62}
63
64bool
65HostInfoWindows::GetOSKernelDescription(std::string &s)
66{
67 return GetOSBuildString(s);
68}
69
70bool
71HostInfoWindows::GetHostname(std::string &s)
72{
73 char buffer[MAX_COMPUTERNAME_LENGTH + 1];
74 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
75 if (!::GetComputerName(buffer, &dwSize))
76 return false;
77
78 s.assign(buffer, buffer + dwSize);
79 return true;
80}