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 <optional>
14#include <sys/sysctl.h>
15#include <sys/types.h>
16#include <sys/utsname.h>
17
18using namespace lldb_private;
19
20llvm::VersionTuple HostInfoOpenBSD::GetOSVersion() {
21 struct utsname un;
22
23 ::memset(s: &un, c: 0, n: sizeof(un));
24 if (::uname(name: &un) < 0)
25 return llvm::VersionTuple();
26
27 uint32_t major, minor;
28 int status = ::sscanf(s: un.release, format: "%" PRIu32 ".%" PRIu32, &major, &minor);
29 switch (status) {
30 case 1:
31 return llvm::VersionTuple(major);
32 case 2:
33 return llvm::VersionTuple(major, minor);
34 }
35 return llvm::VersionTuple();
36}
37
38std::optional<std::string> HostInfoOpenBSD::GetOSBuildString() {
39 int mib[2] = {CTL_KERN, KERN_OSREV};
40 uint32_t osrev = 0;
41 size_t osrev_len = sizeof(osrev);
42
43 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0)
44 return llvm::formatv(Fmt: "{0,8:8}", Vals&: osrev).str();
45
46 return std::nullopt;
47}
48
49FileSpec HostInfoOpenBSD::GetProgramFileSpec() {
50 static FileSpec g_program_filespec;
51 return g_program_filespec;
52}
53

source code of lldb/source/Host/openbsd/HostInfoOpenBSD.cpp