Skip to content

Commit 9d64652

Browse files
committed
Add wrappers for sysconf(3), pathconf(3), and fpathconf(3)
1 parent 274b09e commit 9d64652

File tree

2 files changed

+355
-1
lines changed

2 files changed

+355
-1
lines changed

src/unistd.rs

Lines changed: 324 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Safe wrappers around functions found in libc "unistd.h" header
22
3+
use errno;
34
use {Errno, Error, Result, NixPath};
45
use fcntl::{fcntl, OFlag, O_CLOEXEC, FD_CLOEXEC};
56
use fcntl::FcntlArg::F_SETFD;
6-
use libc::{self, c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t};
7+
use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t,
8+
uid_t, gid_t, mode_t};
79
use std::mem;
810
use std::ffi::{CString, CStr, OsString, OsStr};
911
use std::os::unix::ffi::{OsStringExt, OsStrExt};
@@ -819,6 +821,327 @@ pub fn mkstemp<P: ?Sized + NixPath>(template: &P) -> Result<(RawFd, PathBuf)> {
819821
Ok((fd, PathBuf::from(pathname)))
820822
}
821823

824+
/// 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
828+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
829+
#[repr(i32)]
830+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
831+
pub enum PathconfVar {
832+
// As of 2017-06-24, libc does not define this option on any platform
833+
//FILESIZEBITS = libc::_PC_FILESIZEBITS,
834+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
835+
LINK_MAX = libc::_PC_LINK_MAX,
836+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
837+
MAX_CANON = libc::_PC_MAX_CANON,
838+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
839+
MAX_INPUT = libc::_PC_MAX_INPUT,
840+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
841+
NAME_MAX = libc::_PC_NAME_MAX,
842+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
843+
PATH_MAX = libc::_PC_PATH_MAX,
844+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
845+
PIPE_BUF = libc::_PC_PIPE_BUF,
846+
// As of 2017-06-24, libc does not define these options on any platform
847+
//POSIX2_SYMLINKS = libc::_PC_2_SYMLINKS,
848+
//POSIX_ALLOC_SIZE_MIN = libc::_PC_ALLOC_SIZE_MIN,
849+
//POSIX_REC_INCR_XFER_SIZE = libc::_PC_REC_INCR_XFER_SIZE,
850+
//POSIX_REC_MAX_XFER_SIZE = libc::_PC_REC_MAX_XFER_SIZE,
851+
//POSIX_REC_MIN_XFER_SIZE = libc::_PC_REC_MIN_XFER_SIZE,
852+
//POSIX_REC_XFER_ALIGN = libc::_PC_REC_XFER_ALIGN,
853+
//SYMLINK_MAX = libc::_PC_SYMLINK_MAX,
854+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
855+
_POSIX_CHOWN_RESTRICTED = libc::_PC_CHOWN_RESTRICTED,
856+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
857+
_POSIX_NO_TRUNC = libc::_PC_NO_TRUNC,
858+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
859+
_POSIX_VDISABLE = libc::_PC_VDISABLE,
860+
// As of 2017-06-24, libc does not define these options on any platform
861+
//_POSIX_ASYNC_IO = libc::_PC_ASYNC_IO,
862+
//_POSIX_PRIO_IO = libc::_PC_PRIO_IO,
863+
//_POSIX_SYNC_IO = libc::_PC_SYNC_IO,
864+
//_POSIX_TIMESTAMP_RESOLUTION = libc::_PC_TIMESTAMP_RESOLUTION
865+
}
866+
867+
/// Like `pathconf`, but for file descriptors instead of paths
868+
/// # Parameters
869+
///
870+
/// - `fd`: Lookup the value of `var` for this file descriptor
871+
/// - `var`: The pathconf variable to lookup
872+
///
873+
/// # Returns
874+
///
875+
/// - `Ok(Some(x))`: the variable's limit (for limit variables) or its
876+
/// implementation level (for option variables). Implementation levels are
877+
/// usually a decimal-coded date, such as 200112 for POSIX 2001.12
878+
/// - `Ok(None)`: the variable has no limit (for limit variables) or is
879+
/// unsupported (for option variables)
880+
/// - `Err(x)`: an error occurred
881+
///
882+
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html
883+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
884+
pub fn fpathconf(fd: RawFd, var: PathconfVar) -> Result<Option<c_long>> {
885+
let raw = unsafe {
886+
Errno::clear();
887+
libc::fpathconf(fd, var as c_int)
888+
};
889+
if raw == -1 {
890+
if errno::errno() == 0 {
891+
Ok(None)
892+
} else {
893+
Err(Error::Sys(Errno::last()))
894+
}
895+
} else {
896+
Ok(Some(raw))
897+
}
898+
}
899+
900+
/// Get path-dependent configurable system variables
901+
///
902+
/// Returns the value of a path-dependent configurable system variable. Most
903+
/// supported variables also have associated compile-time constants, but POSIX
904+
/// allows their values to change at runtime. There are generally two types of
905+
/// pathconf variables: options and limits. See pathconf(3) for more details.
906+
///
907+
/// # Parameters
908+
///
909+
/// - `path`: Lookup the value of `var` for this file or directory
910+
/// - `var`: The pathconf variable to lookup
911+
///
912+
/// # Returns
913+
///
914+
/// - `Ok(Some(x))`: the variable's limit (for limit variables) or its
915+
/// implementation level (for option variables). Implementation levels are
916+
/// usually a decimal-coded date, such as 200112 for POSIX 2001.12
917+
/// - `Ok(None)`: the variable has no limit (for limit variables) or is
918+
/// unsupported (for option variables)
919+
/// - `Err(x)`: an error occurred
920+
///
921+
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/pathconf.html
922+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
923+
pub fn pathconf<P: ?Sized + NixPath>(path: &P, var: PathconfVar) -> Result<Option<c_long>> {
924+
let raw = try!(path.with_nix_path(|cstr| {
925+
unsafe {
926+
Errno::clear();
927+
libc::pathconf(cstr.as_ptr(), var as c_int)
928+
}
929+
}));
930+
if raw == -1 {
931+
if errno::errno() == 0 {
932+
Ok(None)
933+
} else {
934+
Err(Error::Sys(Errno::last()))
935+
}
936+
} else {
937+
Ok(Some(raw))
938+
}
939+
}
940+
941+
/// Variable names for `sysconf`
942+
// Note: POSIX 1003.1-2008 requires all of these symbols to be
943+
// supported, but Rust's libc does not yet define them all for all
944+
// platforms
945+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
946+
#[repr(i32)]
947+
pub enum SysconfVar {
948+
AIO_LISTIO_MAX = libc::_SC_AIO_LISTIO_MAX,
949+
AIO_MAX = libc::_SC_AIO_MAX,
950+
AIO_PRIO_DELTA_MAX = libc::_SC_AIO_PRIO_DELTA_MAX,
951+
ARG_MAX = libc::_SC_ARG_MAX,
952+
ATEXIT_MAX = libc::_SC_ATEXIT_MAX,
953+
BC_BASE_MAX = libc::_SC_BC_BASE_MAX,
954+
BC_DIM_MAX = libc::_SC_BC_DIM_MAX,
955+
BC_SCALE_MAX = libc::_SC_BC_SCALE_MAX,
956+
BC_STRING_MAX = libc::_SC_BC_STRING_MAX,
957+
CHILD_MAX = libc::_SC_CHILD_MAX,
958+
// _SC_CLK_TCK is obsolete
959+
COLL_WEIGHTS_MAX = libc::_SC_COLL_WEIGHTS_MAX,
960+
DELAYTIMER_MAX = libc::_SC_DELAYTIMER_MAX,
961+
EXPR_NEST_MAX = libc::_SC_EXPR_NEST_MAX,
962+
HOST_NAME_MAX = libc::_SC_HOST_NAME_MAX,
963+
IOV_MAX = libc::_SC_IOV_MAX,
964+
LINE_MAX = libc::_SC_LINE_MAX,
965+
LOGIN_NAME_MAX = libc::_SC_LOGIN_NAME_MAX,
966+
NGROUPS_MAX = libc::_SC_NGROUPS_MAX,
967+
GETGR_R_SIZE_MAX = libc::_SC_GETGR_R_SIZE_MAX,
968+
GETPW_R_SIZE_MAX = libc::_SC_GETPW_R_SIZE_MAX,
969+
MQ_OPEN_MAX = libc::_SC_MQ_OPEN_MAX,
970+
MQ_PRIO_MAX = libc::_SC_MQ_PRIO_MAX,
971+
OPEN_MAX = libc::_SC_OPEN_MAX,
972+
#[cfg(any(target_os = "ios", target_os = "macos"))]
973+
_POSIX_ADVISORY_INFO = libc::_SC_ADVISORY_INFO,
974+
#[cfg(any(target_os = "ios", target_os = "macos"))]
975+
_POSIX_BARRIERS = libc::_SC_BARRIERS,
976+
_POSIX_ASYNCHRONOUS_IO = libc::_SC_ASYNCHRONOUS_IO,
977+
#[cfg(any(target_os = "ios", target_os = "macos"))]
978+
_POSIX_CLOCK_SELECTION = libc::_SC_CLOCK_SELECTION,
979+
#[cfg(any(target_os = "ios", target_os = "macos"))]
980+
_POSIX_CPUTIME = libc::_SC_CPUTIME,
981+
_POSIX_FSYNC = libc::_SC_FSYNC,
982+
#[cfg(any(target_os = "ios", target_os = "macos"))]
983+
_POSIX_IPV6 = libc::_SC_IPV6,
984+
_POSIX_JOB_CONTROL = libc::_SC_JOB_CONTROL,
985+
_POSIX_MAPPED_FILES = libc::_SC_MAPPED_FILES,
986+
_POSIX_MEMLOCK = libc::_SC_MEMLOCK,
987+
_POSIX_MEMLOCK_RANGE = libc::_SC_MEMLOCK_RANGE,
988+
_POSIX_MEMORY_PROTECTION = libc::_SC_MEMORY_PROTECTION,
989+
_POSIX_MESSAGE_PASSING = libc::_SC_MESSAGE_PASSING,
990+
#[cfg(any(target_os = "ios", target_os = "macos"))]
991+
_POSIX_MONOTONIC_CLOCK = libc::_SC_MONOTONIC_CLOCK,
992+
_POSIX_PRIORITIZED_IO = libc::_SC_PRIORITIZED_IO,
993+
_POSIX_PRIORITY_SCHEDULING = libc::_SC_PRIORITY_SCHEDULING,
994+
#[cfg(any(target_os = "ios", target_os = "macos"))]
995+
_POSIX_RAW_SOCKETS = libc::_SC_RAW_SOCKETS,
996+
#[cfg(any(target_os = "ios", target_os = "macos"))]
997+
_POSIX_READER_WRITER_LOCKS = libc::_SC_READER_WRITER_LOCKS,
998+
_POSIX_REALTIME_SIGNALS = libc::_SC_REALTIME_SIGNALS,
999+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1000+
_POSIX_REGEXP = libc::_SC_REGEXP,
1001+
_POSIX_SAVED_IDS = libc::_SC_SAVED_IDS,
1002+
_POSIX_SEMAPHORES = libc::_SC_SEMAPHORES,
1003+
_POSIX_SHARED_MEMORY_OBJECTS = libc::_SC_SHARED_MEMORY_OBJECTS,
1004+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1005+
_POSIX_SHELL = libc::_SC_SHELL,
1006+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1007+
_POSIX_SPAWN = libc::_SC_SPAWN,
1008+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1009+
_POSIX_SPIN_LOCKS = libc::_SC_SPIN_LOCKS,
1010+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1011+
_POSIX_SPORADIC_SERVER = libc::_SC_SPORADIC_SERVER,
1012+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1013+
_POSIX_SS_REPL_MAX = libc::_SC_SS_REPL_MAX,
1014+
_POSIX_SYNCHRONIZED_IO = libc::_SC_SYNCHRONIZED_IO,
1015+
_POSIX_THREAD_ATTR_STACKADDR = libc::_SC_THREAD_ATTR_STACKADDR,
1016+
_POSIX_THREAD_ATTR_STACKSIZE = libc::_SC_THREAD_ATTR_STACKSIZE,
1017+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1018+
_POSIX_THREAD_CPUTIME = libc::_SC_THREAD_CPUTIME,
1019+
_POSIX_THREAD_PRIO_INHERIT = libc::_SC_THREAD_PRIO_INHERIT,
1020+
_POSIX_THREAD_PRIO_PROTECT = libc::_SC_THREAD_PRIO_PROTECT,
1021+
_POSIX_THREAD_PRIORITY_SCHEDULING = libc::_SC_THREAD_PRIORITY_SCHEDULING,
1022+
#[cfg(not(target_os = "linux"))]
1023+
_POSIX_THREAD_PROCESS_SHARED = libc::_SC_THREAD_PROCESS_SHARED,
1024+
// As of 2017-06-24, libc does not define these options on any platform
1025+
//_POSIX_THREAD_ROBUST_PRIO_INHERIT = libc::_SC_THREAD_ROBUST_PRIO_INHERIT ,
1026+
//_POSIX_THREAD_ROBUST_PRIO_PROTECT = libc::_SC_THREAD_ROBUST_PRIO_PROTECT ,
1027+
_POSIX_THREAD_SAFE_FUNCTIONS = libc::_SC_THREAD_SAFE_FUNCTIONS,
1028+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1029+
_POSIX_THREAD_SPORADIC_SERVER = libc::_SC_THREAD_SPORADIC_SERVER,
1030+
_POSIX_THREADS = libc::_SC_THREADS,
1031+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1032+
_POSIX_TIMEOUTS = libc::_SC_TIMEOUTS,
1033+
_POSIX_TIMERS = libc::_SC_TIMERS,
1034+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1035+
_POSIX_TRACE = libc::_SC_TRACE,
1036+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1037+
_POSIX_TRACE_EVENT_FILTER = libc::_SC_TRACE_EVENT_FILTER,
1038+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1039+
_POSIX_TRACE_EVENT_NAME_MAX = libc::_SC_TRACE_EVENT_NAME_MAX,
1040+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1041+
_POSIX_TRACE_INHERIT = libc::_SC_TRACE_INHERIT,
1042+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1043+
_POSIX_TRACE_LOG = libc::_SC_TRACE_LOG,
1044+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1045+
_POSIX_TRACE_NAME_MAX = libc::_SC_TRACE_NAME_MAX,
1046+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1047+
_POSIX_TRACE_SYS_MAX = libc::_SC_TRACE_SYS_MAX,
1048+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1049+
_POSIX_TRACE_USER_EVENT_MAX = libc::_SC_TRACE_USER_EVENT_MAX,
1050+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1051+
_POSIX_TYPED_MEMORY_OBJECTS = libc::_SC_TYPED_MEMORY_OBJECTS,
1052+
_POSIX_VERSION = libc::_SC_VERSION,
1053+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1054+
_POSIX_V6_ILP32_OFF32 = libc::_SC_V6_ILP32_OFF32,
1055+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1056+
_POSIX_V6_ILP32_OFFBIG = libc::_SC_V6_ILP32_OFFBIG,
1057+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1058+
_POSIX_V6_LP64_OFF64 = libc::_SC_V6_LP64_OFF64,
1059+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1060+
_POSIX_V6_LPBIG_OFFBIG = libc::_SC_V6_LPBIG_OFFBIG,
1061+
_POSIX2_C_BIND = libc::_SC_2_C_BIND,
1062+
_POSIX2_C_DEV = libc::_SC_2_C_DEV,
1063+
_POSIX2_CHAR_TERM = libc::_SC_2_CHAR_TERM,
1064+
_POSIX2_FORT_DEV = libc::_SC_2_FORT_DEV,
1065+
_POSIX2_FORT_RUN = libc::_SC_2_FORT_RUN,
1066+
_POSIX2_LOCALEDEF = libc::_SC_2_LOCALEDEF,
1067+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1068+
_POSIX2_PBS = libc::_SC_2_PBS,
1069+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1070+
_POSIX2_PBS_ACCOUNTING = libc::_SC_2_PBS_ACCOUNTING,
1071+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1072+
_POSIX2_PBS_CHECKPOINT = libc::_SC_2_PBS_CHECKPOINT,
1073+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1074+
_POSIX2_PBS_LOCATE = libc::_SC_2_PBS_LOCATE,
1075+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1076+
_POSIX2_PBS_MESSAGE = libc::_SC_2_PBS_MESSAGE,
1077+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1078+
_POSIX2_PBS_TRACK = libc::_SC_2_PBS_TRACK,
1079+
_POSIX2_SW_DEV = libc::_SC_2_SW_DEV,
1080+
_POSIX2_UPE = libc::_SC_2_UPE,
1081+
_POSIX2_VERSION = libc::_SC_2_VERSION,
1082+
PAGE_SIZE = libc::_SC_PAGE_SIZE,
1083+
// POSIX requires an alias PAGESIZE == PAGE_SIZE, but Rust doesn't like
1084+
// for two enums to have the same value
1085+
PTHREAD_DESTRUCTOR_ITERATIONS = libc::_SC_THREAD_DESTRUCTOR_ITERATIONS,
1086+
PTHREAD_KEYS_MAX = libc::_SC_THREAD_KEYS_MAX,
1087+
PTHREAD_STACK_MIN = libc::_SC_THREAD_STACK_MIN,
1088+
PTHREAD_THREADS_MAX = libc::_SC_THREAD_THREADS_MAX,
1089+
RE_DUP_MAX = libc::_SC_RE_DUP_MAX,
1090+
RTSIG_MAX = libc::_SC_RTSIG_MAX,
1091+
SEM_NSEMS_MAX = libc::_SC_SEM_NSEMS_MAX,
1092+
SEM_VALUE_MAX = libc::_SC_SEM_VALUE_MAX,
1093+
SIGQUEUE_MAX = libc::_SC_SIGQUEUE_MAX,
1094+
STREAM_MAX = libc::_SC_STREAM_MAX,
1095+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1096+
SYMLOOP_MAX = libc::_SC_SYMLOOP_MAX,
1097+
TIMER_MAX = libc::_SC_TIMER_MAX,
1098+
TTY_NAME_MAX = libc::_SC_TTY_NAME_MAX,
1099+
TZNAME_MAX = libc::_SC_TZNAME_MAX,
1100+
_XOPEN_CRYPT = libc::_SC_XOPEN_CRYPT,
1101+
_XOPEN_ENH_I18N = libc::_SC_XOPEN_ENH_I18N,
1102+
_XOPEN_LEGACY = libc::_SC_XOPEN_LEGACY,
1103+
_XOPEN_REALTIME = libc::_SC_XOPEN_REALTIME,
1104+
_XOPEN_REALTIME_THREADS = libc::_SC_XOPEN_REALTIME_THREADS,
1105+
_XOPEN_SHM = libc::_SC_XOPEN_SHM,
1106+
#[cfg(any(target_os = "ios", target_os = "macos"))]
1107+
_XOPEN_STREAMS = libc::_SC_XOPEN_STREAMS,
1108+
_XOPEN_UNIX = libc::_SC_XOPEN_UNIX,
1109+
_XOPEN_VERSION = libc::_SC_XOPEN_VERSION,
1110+
}
1111+
1112+
/// Get configurable system variables
1113+
///
1114+
/// Returns the value of a configurable system variable. Most supported
1115+
/// variables also have associated compile-time constants, but POSIX
1116+
/// allows their values to change at runtime. There are generally two types of
1117+
/// sysconf variables: options and limits. See sysconf(3) for more details.
1118+
///
1119+
/// # Returns
1120+
///
1121+
/// - Ok(Some(x)): the variable's limit (for limit variables) or its
1122+
/// implementation level (for option variables). Implementation levels are
1123+
/// usually a decimal-coded date, such as 200112 for POSIX 2001.12
1124+
/// - Ok(None): the variable has no limit (for limit variables) or is
1125+
/// unsupported (for option variables)
1126+
/// - Err(x): an error occurred
1127+
///
1128+
/// http://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html
1129+
pub fn sysconf(var: SysconfVar) -> Result<Option<c_long>> {
1130+
let raw = unsafe {
1131+
Errno::clear();
1132+
libc::sysconf(var as c_int)
1133+
};
1134+
if raw == -1 {
1135+
if errno::errno() == 0 {
1136+
Ok(None)
1137+
} else {
1138+
Err(Error::Sys(Errno::last()))
1139+
}
1140+
} else {
1141+
Ok(Some(raw))
1142+
}
1143+
}
1144+
8221145
#[cfg(any(target_os = "linux", target_os = "android"))]
8231146
mod linux {
8241147
use libc::{self, uid_t, gid_t};

test/test_unistd.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,34 @@ execve_test_factory!(test_execve, execve, b"/bin/sh", b"/system/bin/sh");
217217
#[cfg(any(target_os = "linux", target_os = "android"))]
218218
#[cfg(feature = "execvpe")]
219219
execve_test_factory!(test_execvpe, execvpe, b"sh", b"sh");
220+
221+
#[test]
222+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
223+
fn test_fpathconf_limited() {
224+
let f = tempfile().unwrap();
225+
let path_max = fpathconf(f.as_raw_fd(), PathconfVar::PATH_MAX);
226+
assert!(path_max.expect("fpathconf failed").expect("PATH_MAX is unlimited") > 0);
227+
}
228+
229+
#[test]
230+
#[cfg(any(target_os = "android", target_os = "ios", target_os = "linux", target_os = "macos"))]
231+
fn test_pathconf_limited() {
232+
let path_max = pathconf(".", PathconfVar::PATH_MAX);
233+
assert!(path_max.expect("pathconf failed").expect("PATH_MAX is unlimited") > 0);
234+
}
235+
236+
#[test]
237+
fn test_sysconf_limited() {
238+
let open_max = sysconf(SysconfVar::OPEN_MAX);
239+
assert!(open_max.expect("sysconf failed").expect("OPEN_MAX is unlimited") > 0);
240+
}
241+
242+
// Test sysconf with an unsupported varible
243+
// Note: If future versions of FreeBSD add support for this option then the test
244+
// must be modified.
245+
#[cfg(target_os = "freebsd")]
246+
#[test]
247+
fn test_sysconf_unlimited() {
248+
let open_max = sysconf(SysconfVar::_XOPEN_CRYPT);
249+
assert!(open_max.expect("sysconf failed").is_none())
250+
}

0 commit comments

Comments
 (0)