1 //===-- HostInfoNetBSD.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/netbsd/HostInfoNetBSD.h" 11 12 #include <inttypes.h> 13 #include <limits.h> 14 #include <pthread.h> 15 #include <stdio.h> 16 #include <string.h> 17 #include <sys/sysctl.h> 18 #include <sys/types.h> 19 #include <sys/utsname.h> 20 #include <unistd.h> 21 22 using namespace lldb_private; 23 24 bool HostInfoNetBSD::GetOSVersion(uint32_t &major, uint32_t &minor, 25 uint32_t &update) { 26 struct utsname un; 27 28 ::memset(&un, 0, sizeof(un)); 29 if (::uname(&un) < 0) 30 return false; 31 32 /* Accept versions like 7.99.21 and 6.1_STABLE */ 33 int status = ::sscanf(un.release, "%" PRIu32 ".%" PRIu32 ".%" PRIu32, &major, 34 &minor, &update); 35 switch (status) { 36 case 0: 37 return false; 38 case 1: 39 minor = 0; 40 /* FALLTHROUGH */ 41 case 2: 42 update = 0; 43 /* FALLTHROUGH */ 44 case 3: 45 default: 46 return true; 47 } 48 } 49 50 bool HostInfoNetBSD::GetOSBuildString(std::string &s) { 51 int mib[2] = {CTL_KERN, KERN_OSREV}; 52 char osrev_str[12]; 53 int osrev = 0; 54 size_t osrev_len = sizeof(osrev); 55 56 if (::sysctl(mib, 2, &osrev, &osrev_len, NULL, 0) == 0) { 57 ::snprintf(osrev_str, sizeof(osrev_str), "%-10.10d", osrev); 58 s.assign(osrev_str); 59 return true; 60 } 61 62 s.clear(); 63 return false; 64 } 65 66 bool HostInfoNetBSD::GetOSKernelDescription(std::string &s) { 67 struct utsname un; 68 69 ::memset(&un, 0, sizeof(un)); 70 s.clear(); 71 72 if (::uname(&un) < 0) 73 return false; 74 75 s.assign(un.version); 76 77 return true; 78 } 79 80 FileSpec HostInfoNetBSD::GetProgramFileSpec() { 81 static FileSpec g_program_filespec; 82 83 if (!g_program_filespec) { 84 static const int name[] = { 85 CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME, 86 }; 87 char path[MAXPATHLEN]; 88 size_t len; 89 90 len = sizeof(path); 91 if (sysctl(name, __arraycount(name), path, &len, NULL, 0) != -1) { 92 g_program_filespec.SetFile(path, false); 93 } 94 } 95 return g_program_filespec; 96 } 97