llvm.org GIT mirror llvm / bb14672
Add llvm::sys::{osName,osVersion} for retrieving operating system name & version as strings. - Win32 code is untested. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56942 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 12 years ago
4 changed file(s) with 110 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
1212
1313 #ifndef LLVM_SYSTEM_HOST_H
1414 #define LLVM_SYSTEM_HOST_H
15
16 #include
1517
1618 namespace llvm {
1719 namespace sys {
2931 return !littleEndianHost();
3032 }
3133
34 /// osName() - Return the name of the host operating system or "" if
35 /// unknown.
36 std::string osName();
37
38 /// osVersion() - Return the operating system version as a string or
39 /// "" if unknown.
40 std::string osVersion();
3241 }
3342 }
3443
0 //===-- Host.cpp - Implement OS Host Concept --------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header file implements the operating system Host concept.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "llvm/System/Host.h"
14 #include "llvm/Config/config.h"
15
16 // Include the platform-specific parts of this class.
17 #ifdef LLVM_ON_UNIX
18 #include "Unix/Host.inc"
19 #endif
20 #ifdef LLVM_ON_WIN32
21 #include "Win32/Host.inc"
22 #endif
23
0 //===- llvm/System/Unix/Host.inc --------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the UNIX Host support.
10 //
11 //===----------------------------------------------------------------------===//
12
13 //===----------------------------------------------------------------------===//
14 //=== WARNING: Implementation here must contain only generic UNIX code that
15 //=== is guaranteed to work on *all* UNIX variants.
16 //===----------------------------------------------------------------------===//
17
18 #include
19 #include "Unix.h"
20 #include
21 #include
22
23 using namespace llvm;
24
25 std::string llvm::sys::osName() {
26 struct utsname info;
27
28 if (uname(&info))
29 return "";
30
31 return info.sysname;
32 }
33
34 std::string llvm::sys::osVersion() {
35 struct utsname info;
36
37 if (uname(&info))
38 return "";
39
40 return info.release;
41 }
0 //===- llvm/System/Win32/Host.inc -------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Win32 Host support.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "Win32.h"
14 #include
15 #include
16
17 using namespace llvm;
18
19 std::string sys::osName() {
20 return "Windows";
21 }
22
23 std::string sys::osVersion() {
24 OSVERSIONINFO osvi = { 0 };
25 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
26
27 if (!GetVersionEx(&osvi))
28 return "";
29
30 char buf[64];
31 sprintf(buf, "%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
32
33 return buf;
34 }