blob: 139ded253c53b0bbe98635652afb4663f8b361f7 [file] [log] [blame]
Avi Drissman837d106b2023-09-12 14:51:201// 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 Sonzognie5fff99c2024-02-21 15:58:249#include <optional>
Avi Drissman837d106b2023-09-12 14:51:2010#include <string>
11
12#include "base/base_export.h"
13#include "build/build_config.h"
Avi Drissman837d106b2023-09-12 14:51:2014
15// NB: While a BSD utility file, this lives in /base/posix/ for simplicity as
16// there is no /base/bsd/.
17
18namespace base {
19
20// Returns the value returned by `sysctl` as a std::string, or nullopt on error.
Arthur Sonzognie5fff99c2024-02-21 15:58:2421BASE_EXPORT std::optional<std::string> StringSysctl(
Avi Drissman837d106b2023-09-12 14:51:2022 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 Sonzognie5fff99c2024-02-21 15:58:2427BASE_EXPORT std::optional<std::string> StringSysctlByName(const char* name);
Avi Drissman837d106b2023-09-12 14:51:2028#endif
29
30} // namespace base
31
32#endif // BASE_POSIX_SYSCTL_H_