[llvm-commits] [llvm] r56942 - in /llvm/trunk: include/llvm/System/Host.h lib/System/Host.cpp lib/System/Unix/Host.inc lib/System/Win32/Host.inc
Daniel Dunbar
daniel at zuster.org
Wed Oct 1 18:17:28 PDT 2008
Author: ddunbar
Date: Wed Oct 1 20:17:28 2008
New Revision: 56942
URL: http://llvm.org/viewvc/llvm-project?rev=56942&view=rev
Log:
Add llvm::sys::{osName,osVersion} for retrieving operating system name
& version as strings.
- Win32 code is untested.
Added:
llvm/trunk/lib/System/Host.cpp
llvm/trunk/lib/System/Unix/Host.inc
llvm/trunk/lib/System/Win32/Host.inc
Modified:
llvm/trunk/include/llvm/System/Host.h
Modified: llvm/trunk/include/llvm/System/Host.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Host.h?rev=56942&r1=56941&r2=56942&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Host.h (original)
+++ llvm/trunk/include/llvm/System/Host.h Wed Oct 1 20:17:28 2008
@@ -14,6 +14,8 @@
#ifndef LLVM_SYSTEM_HOST_H
#define LLVM_SYSTEM_HOST_H
+#include <string>
+
namespace llvm {
namespace sys {
@@ -30,6 +32,13 @@
return !littleEndianHost();
}
+ /// osName() - Return the name of the host operating system or "" if
+ /// unknown.
+ std::string osName();
+
+ /// osVersion() - Return the operating system version as a string or
+ /// "" if unknown.
+ std::string osVersion();
}
}
Added: llvm/trunk/lib/System/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Host.cpp?rev=56942&view=auto
==============================================================================
--- llvm/trunk/lib/System/Host.cpp (added)
+++ llvm/trunk/lib/System/Host.cpp Wed Oct 1 20:17:28 2008
@@ -0,0 +1,24 @@
+//===-- Host.cpp - Implement OS Host Concept --------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file implements the operating system Host concept.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/System/Host.h"
+#include "llvm/Config/config.h"
+
+// Include the platform-specific parts of this class.
+#ifdef LLVM_ON_UNIX
+#include "Unix/Host.inc"
+#endif
+#ifdef LLVM_ON_WIN32
+#include "Win32/Host.inc"
+#endif
+
Added: llvm/trunk/lib/System/Unix/Host.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Host.inc?rev=56942&view=auto
==============================================================================
--- llvm/trunk/lib/System/Unix/Host.inc (added)
+++ llvm/trunk/lib/System/Unix/Host.inc Wed Oct 1 20:17:28 2008
@@ -0,0 +1,42 @@
+ //===- llvm/System/Unix/Host.inc --------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the UNIX Host support.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only generic UNIX code that
+//=== is guaranteed to work on *all* UNIX variants.
+//===----------------------------------------------------------------------===//
+
+#include <llvm/Config/config.h>
+#include "Unix.h"
+#include <sys/utsname.h>
+#include <string>
+
+using namespace llvm;
+
+std::string llvm::sys::osName() {
+ struct utsname info;
+
+ if (uname(&info))
+ return "";
+
+ return info.sysname;
+}
+
+std::string llvm::sys::osVersion() {
+ struct utsname info;
+
+ if (uname(&info))
+ return "";
+
+ return info.release;
+}
Added: llvm/trunk/lib/System/Win32/Host.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Win32/Host.inc?rev=56942&view=auto
==============================================================================
--- llvm/trunk/lib/System/Win32/Host.inc (added)
+++ llvm/trunk/lib/System/Win32/Host.inc Wed Oct 1 20:17:28 2008
@@ -0,0 +1,35 @@
+//===- llvm/System/Win32/Host.inc -------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the Win32 Host support.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Win32.h"
+#include <cstdio>
+#include <string>
+
+using namespace llvm;
+
+std::string sys::osName() {
+ return "Windows";
+}
+
+std::string sys::osVersion() {
+ OSVERSIONINFO osvi = { 0 };
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (!GetVersionEx(&osvi))
+ return "";
+
+ char buf[64];
+ sprintf(buf, "%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
+
+ return buf;
+}
More information about the llvm-commits
mailing list