Avi Drissman | 837d106b | 2023-09-12 14:51:20 | [diff] [blame] | 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> |
Arthur Sonzogni | e5fff99c | 2024-02-21 15:58:24 | [diff] [blame] | 9 | #include <optional> |
Avi Drissman | 837d106b | 2023-09-12 14:51:20 | [diff] [blame] | 10 | #include <string> |
| 11 | |
| 12 | #include "base/base_export.h" |
| 13 | #include "build/build_config.h" |
Avi Drissman | 837d106b | 2023-09-12 14:51:20 | [diff] [blame] | 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. |
Arthur Sonzogni | e5fff99c | 2024-02-21 15:58:24 | [diff] [blame] | 21 | BASE_EXPORT std::optional<std::string> StringSysctl( |
Avi Drissman | 837d106b | 2023-09-12 14:51:20 | [diff] [blame] | 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. |
Arthur Sonzogni | e5fff99c | 2024-02-21 15:58:24 | [diff] [blame] | 27 | BASE_EXPORT std::optional<std::string> StringSysctlByName(const char* name); |
Avi Drissman | 837d106b | 2023-09-12 14:51:20 | [diff] [blame] | 28 | #endif |
| 29 | |
| 30 | } // namespace base |
| 31 | |
| 32 | #endif // BASE_POSIX_SYSCTL_H_ |