yash_env/system/
sysconf.rs

1// This file is part of yash, an extended POSIX shell.
2// Copyright (C) 2025 WATANABE Yuki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17//! Items for obtaining system configuration information
18
19use super::Result;
20use crate::str::UnixString;
21use std::ffi::CString;
22
23/// Trait for getting system configuration information
24pub trait Sysconf {
25    /// Returns the standard `$PATH` value where all standard utilities are
26    /// expected to be found.
27    ///
28    /// This is a thin wrapper around `confstr(_CS_PATH, …)`.
29    fn confstr_path(&self) -> Result<UnixString>;
30}
31
32pub trait ShellPath {
33    // TODO: Should return `Cow<CStr>` instead
34    /// Returns the path to the shell executable.
35    ///
36    /// If possible, this function should return the path to the current shell
37    /// executable. Otherwise, it should return the path to the default POSIX
38    /// shell.
39    fn shell_path(&self) -> CString;
40}