Path: blob/main/contrib/llvm-project/lldb/source/Host/openbsd/HostInfoOpenBSD.cpp
39607 views
//===-- HostInfoOpenBSD.cpp -----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/openbsd/HostInfoOpenBSD.h"910#include <cstdio>11#include <cstring>12#include <optional>13#include <sys/sysctl.h>14#include <sys/types.h>15#include <sys/utsname.h>1617using namespace lldb_private;1819llvm::VersionTuple HostInfoOpenBSD::GetOSVersion() {20struct utsname un;2122::memset(&un, 0, sizeof(un));23if (::uname(&un) < 0)24return llvm::VersionTuple();2526uint32_t major, minor;27int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32, &major, &minor);28switch (status) {29case 1:30return llvm::VersionTuple(major);31case 2:32return llvm::VersionTuple(major, minor);33}34return llvm::VersionTuple();35}3637std::optional<std::string> HostInfoOpenBSD::GetOSBuildString() {38int mib[2] = {CTL_KERN, KERN_OSREV};39uint32_t osrev = 0;40size_t osrev_len = sizeof(osrev);4142if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)43return llvm::formatv("{0,8:8}", osrev).str();4445return std::nullopt;46}4748FileSpec HostInfoOpenBSD::GetProgramFileSpec() {49static FileSpec g_program_filespec;50return g_program_filespec;51}525354