1 //===-- HostInfoOpenBSD.cpp -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/Host/openbsd/HostInfoOpenBSD.h"
11 
12 #include <stdio.h>
13 #include <string.h>
14 #include <sys/sysctl.h>
15 #include <sys/types.h>
16 #include <sys/utsname.h>
17 
18 using namespace lldb_private;
19 
20 bool HostInfoOpenBSD::GetOSVersion(uint32_t &major, uint32_t &minor,
21                                    uint32_t &update) {
22   struct utsname un;
23 
24   ::memset(&un, 0, sizeof(utsname));
25   if (uname(&un) < 0)
26     return false;
27 
28   int status = sscanf(un.release, "%u.%u", &major, &minor);
29   return status == 2;
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