1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_POSIX_SYSCTL_H_ 6 #define BASE_POSIX_SYSCTL_H_ 7 8 #include <initializer_list> 9 #include <optional> 10 #include <string> 11 12 #include "base/base_export.h" 13 #include "build/build_config.h" 14 15 // NB: While a BSD utility file, this lives in /base/posix/ for simplicity as 16 // there is no /base/bsd/. 17 18 namespace base { 19 20 // Returns the value returned by `sysctl` as a std::string, or nullopt on error. 21 BASE_EXPORT std::optional<std::string> StringSysctl( 22 const std::initializer_list<int>& mib); 23 24 #if !BUILDFLAG(IS_OPENBSD) 25 // Returns the value returned by `sysctlbyname` as a std::string, or nullopt 26 // on error. 27 BASE_EXPORT std::optional<std::string> StringSysctlByName(const char* name); 28 #endif 29 30 } // namespace base 31 32 #endif // BASE_POSIX_SYSCTL_H_ 33