Skip to content

Commit 8abdeb7

Browse files
committed
Better comments and a CHANGELOG entry
1 parent 0f0825e commit 8abdeb7

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
## [Unreleased]
77

88
### Added
9+
- Added `sysconf`, `pathconf`, and `fpathconf`
10+
([#630](https://github.com/nix-rust/nix/pull/630)
911
- Added `sys::signal::SigAction::{ flags, mask, handler}`
1012
([#611](https://github.com/nix-rust/nix/pull/609)
1113
- Added `nix::sys::pthread::pthread_self`

src/unistd.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,9 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
822822
}
823823

824824
/// Variable names for `pathconf`
825-
// Note: POSIX 1003.1-2008 requires all of these symbols to be
826-
// supported, but Rust's libc does not yet define them all for all
827-
// platforms
825+
///
826+
/// Note: POSIX 1003.1-2008 standardizes all of these variables, but some OSes
827+
/// choose not to implement variables that cannot change at runtime.
828828
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
829829
#[repr(i32)]
830830
pub enum PathconfVar {
@@ -889,6 +889,8 @@ pub enum PathconfVar {
889889
/// unsupported (for option variables)
890890
/// - `Err(x)`: an error occurred
891891
///
892+
/// # Referencces
893+
///
892894
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html
893895
pub fn fpathconf(fd: RawFd, var: PathconfVar) -> Result<Option<c_long>> {
894896
let raw = unsafe {
@@ -911,12 +913,12 @@ pub fn fpathconf(fd: RawFd, var: PathconfVar) -> Result<Option<c_long>> {
911913
/// Returns the value of a path-dependent configurable system variable. Most
912914
/// supported variables also have associated compile-time constants, but POSIX
913915
/// allows their values to change at runtime. There are generally two types of
914-
/// pathconf variables: options and limits. See pathconf(3) for more details.
916+
/// `pathconf` variables: options and limits. See pathconf(3) for more details.
915917
///
916918
/// # Parameters
917919
///
918920
/// - `path`: Lookup the value of `var` for this file or directory
919-
/// - `var`: The pathconf variable to lookup
921+
/// - `var`: The `pathconf` variable to lookup
920922
///
921923
/// # Returns
922924
///
@@ -927,6 +929,8 @@ pub fn fpathconf(fd: RawFd, var: PathconfVar) -> Result<Option<c_long>> {
927929
/// unsupported (for option variables)
928930
/// - `Err(x)`: an error occurred
929931
///
932+
/// # Referencces
933+
///
930934
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html
931935
pub fn pathconf<P: ?Sized + NixPath>(path: &P, var: PathconfVar) -> Result<Option<c_long>> {
932936
let raw = try!(path.with_nix_path(|cstr| {
@@ -947,8 +951,9 @@ pub fn pathconf<P: ?Sized + NixPath>(path: &P, var: PathconfVar) -> Result<Optio
947951
}
948952

949953
/// Variable names for `sysconf`
950-
// Note: All of these symbols are standardized by POSIX 1003.1-2008, but haven't
951-
// been implemented by all platforms.
954+
///
955+
/// Note: All of these symbols are standardized by POSIX 1003.1-2008, but haven't
956+
/// been implemented by all platforms.
952957
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
953958
#[repr(i32)]
954959
pub enum SysconfVar {
@@ -1229,6 +1234,8 @@ _XOPEN_VERSION = libc::_SC_XOPEN_VERSION,
12291234
/// unsupported (for option variables)
12301235
/// - Err(x): an error occurred
12311236
///
1237+
/// # Referencces
1238+
///
12321239
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html
12331240
pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
12341241
let raw = unsafe {

test/test_unistd.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,31 @@ execve_test_factory!(test_execvpe, execvpe, b"sh", b"sh");
221221
#[test]
222222
fn test_fpathconf_limited() {
223223
let f = tempfile().unwrap();
224+
// AFAIK, PATH_MAX is limited on all platforms, so it makes a good test
224225
let path_max = fpathconf(f.as_raw_fd(), PathconfVar::PATH_MAX);
225226
assert!(path_max.expect("fpathconf failed").expect("PATH_MAX is unlimited") > 0);
226227
}
227228

228229
#[test]
229230
fn test_pathconf_limited() {
231+
// AFAIK, PATH_MAX is limited on all platforms, so it makes a good test
230232
let path_max = pathconf(".", PathconfVar::PATH_MAX);
231233
assert!(path_max.expect("pathconf failed").expect("PATH_MAX is unlimited") > 0);
232234
}
233235

234236
#[test]
235237
fn test_sysconf_limited() {
238+
// AFAIK, OPEN_MAX is limited on all platforms, so it makes a good test
236239
let open_max = sysconf(SysconfVar::OPEN_MAX);
237240
assert!(open_max.expect("sysconf failed").expect("OPEN_MAX is unlimited") > 0);
238241
}
239242

240-
// Test sysconf with an unsupported varible
241-
// Note: If future versions of FreeBSD add support for this option then the test
242-
// must be modified.
243243
#[cfg(target_os = "freebsd")]
244244
#[test]
245-
fn test_sysconf_unlimited() {
245+
fn test_sysconf_unsupported() {
246+
// I know of no sysconf variables that are unsupported everywhere, but
247+
// _XOPEN_CRYPT is unsupported on FreeBSD 11.0, which is one of the platforms
248+
// we test.
246249
let open_max = sysconf(SysconfVar::_XOPEN_CRYPT);
247250
assert!(open_max.expect("sysconf failed").is_none())
248251
}

0 commit comments

Comments
 (0)