Simplify memory management with std::unique_ptr.
[oota-llvm.git] / lib / Support / Unix / Host.inc
1 //===- llvm/Support/Unix/Host.inc -------------------------------*- 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 // This file implements the UNIX Host support.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 //=== WARNING: Implementation here must contain only generic UNIX code that
16 //===          is guaranteed to work on *all* UNIX variants.
17 //===----------------------------------------------------------------------===//
18
19 #include "Unix.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Config/config.h"
22 #include <cctype>
23 #include <string>
24 #include <sys/utsname.h>
25
26 using namespace llvm;
27
28 static std::string getOSVersion() {
29   struct utsname info;
30
31   if (uname(&info))
32     return "";
33
34   return info.release;
35 }
36
37 std::string sys::getDefaultTargetTriple() {
38   std::string TargetTripleString(LLVM_DEFAULT_TARGET_TRIPLE);
39
40   // On darwin, we want to update the version to match that of the
41   // target.
42   std::string::size_type DarwinDashIdx = TargetTripleString.find("-darwin");
43   if (DarwinDashIdx != std::string::npos) {
44     TargetTripleString.resize(DarwinDashIdx + strlen("-darwin"));
45     TargetTripleString += getOSVersion();
46   }
47
48   return Triple::normalize(TargetTripleString);
49 }