1 //===-- HostInfoOpenBSD.cpp -----------------------------------------------===// 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 11 #include <cstdio> 12 #include <cstring> 13 #include <sys/sysctl.h> 14 #include <sys/types.h> 15 #include <sys/utsname.h> 16 17 using namespace lldb_private; 18 19 llvm::VersionTuple HostInfoOpenBSD::GetOSVersion() { 20 struct utsname un; 21 22 ::memset(&un, 0, sizeof(utsname)); 23 if (uname(&un) < 0) 24 return llvm::VersionTuple(); 25 26 unsigned major, minor; 27 if (2 == sscanf(un.release, "%u.%u", &major, &minor)) 28 return llvm::VersionTuple(major, minor); 29 return llvm::VersionTuple(); 30 } 31 32 bool HostInfoOpenBSD::GetOSBuildString(std::string &s) { 33 int mib[2] = {CTL_KERN, KERN_OSREV}; 34 char osrev_str[12]; 35 uint32_t osrev = 0; 36 size_t osrev_len = sizeof(osrev); 37 38 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { 39 ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev); 40 s.assign(osrev_str); 41 return true; 42 } 43 44 s.clear(); 45 return false; 46 } 47 48 bool HostInfoOpenBSD::GetOSKernelDescription(std::string &s) { 49 struct utsname un; 50 51 ::memset(&un, 0, sizeof(utsname)); 52 s.clear(); 53 54 if (uname(&un) < 0) 55 return false; 56 57 s.assign(un.version); 58 59 return true; 60 } 61 62 FileSpec HostInfoOpenBSD::GetProgramFileSpec() { 63 static FileSpec g_program_filespec; 64 return g_program_filespec; 65 } 66