1 //===-- HostInfoOpenBSD.cpp -------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Host/openbsd/HostInfoOpenBSD.h" 10 #include "lldb/Host/FileSystem.h" 11 12 #include <stdio.h> 13 #include <string.h> 14 #include <unistd.h> 15 #include <sys/sysctl.h> 16 #include <sys/types.h> 17 #include <sys/utsname.h> 18 19 using namespace lldb_private; 20 21 llvm::VersionTuple HostInfoOpenBSD::GetOSVersion() { 22 struct utsname un; 23 24 ::memset(&un, 0, sizeof(un)); 25 if (::uname(&un) < 0) 26 return llvm::VersionTuple(); 27 28 uint32_t major, minor; 29 int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32, &major, &minor); 30 switch (status) { 31 case 1: 32 return llvm::VersionTuple(major); 33 case 2: 34 return llvm::VersionTuple(major, minor); 35 } 36 return llvm::VersionTuple(); 37 } 38 39 bool HostInfoOpenBSD::GetOSBuildString(std::string &s) { 40 int mib[2] = {CTL_KERN, KERN_OSREV}; 41 char osrev_str[12]; 42 uint32_t osrev = 0; 43 size_t osrev_len = sizeof(osrev); 44 45 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { 46 ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev); 47 s.assign(osrev_str); 48 return true; 49 } 50 51 s.clear(); 52 return false; 53 } 54 55 bool HostInfoOpenBSD::GetOSKernelDescription(std::string &s) { 56 struct utsname un; 57 58 ::memset(&un, 0, sizeof(utsname)); 59 s.clear(); 60 61 if (uname(&un) < 0) 62 return false; 63 64 s.assign(un.version); 65 66 return true; 67 } 68 69 FileSpec HostInfoOpenBSD::GetProgramFileSpec() { 70 static FileSpec g_program_filespec; 71 return g_program_filespec; 72 } 73 74 bool HostInfoOpenBSD::ComputeSupportExeDirectory(FileSpec &file_spec) { 75 if (HostInfoPosix::ComputeSupportExeDirectory(file_spec) && 76 file_spec.IsAbsolute() && FileSystem::Instance().Exists(file_spec)) 77 return true; 78 79 file_spec.GetDirectory().SetCString("/usr/bin"); 80 return true; 81 } 82