1 //===-- HostInfoFreeBSD.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/freebsd/HostInfoFreeBSD.h"
13 #include <sys/sysctl.h>
14 #include <sys/types.h>
15 #include <sys/utsname.h>
18 using namespace lldb_private;
20 llvm::VersionTuple HostInfoFreeBSD::GetOSVersion() {
23 ::memset(&un, 0, sizeof(utsname));
25 return llvm::VersionTuple();
27 unsigned major, minor;
28 if (2 == sscanf(un.release, "%u.%u", &major, &minor))
29 return llvm::VersionTuple(major, minor);
30 return llvm::VersionTuple();
33 bool HostInfoFreeBSD::GetOSBuildString(std::string &s) {
34 int mib[2] = {CTL_KERN, KERN_OSREV};
37 size_t osrev_len = sizeof(osrev);
39 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) {
40 ::snprintf(osrev_str, sizeof(osrev_str), "%-8.8u", osrev);
49 bool HostInfoFreeBSD::GetOSKernelDescription(std::string &s) {
52 ::memset(&un, 0, sizeof(utsname));
63 FileSpec HostInfoFreeBSD::GetProgramFileSpec() {
64 static FileSpec g_program_filespec;
65 if (!g_program_filespec) {
66 int exe_path_mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid()};
68 if (sysctl(exe_path_mib, 4, NULL, &exe_path_size, NULL, 0) == 0) {
69 char *exe_path = new char[exe_path_size];
70 if (sysctl(exe_path_mib, 4, exe_path, &exe_path_size, NULL, 0) == 0)
71 g_program_filespec.SetFile(exe_path, FileSpec::Style::native);
75 return g_program_filespec;