Skip to content

Commit f6eb496

Browse files
committed
Auto merge of #2883 - thomcc:confstr, r=JohnTitor
Add `confstr` and guaranteed `_CS_*` constants on apple I actually just want `_CS_DARWIN_USER_TEMP_DIR`, and the `confstr` function, but I also have added the other "guaranteed" `_CS_*` values (e.g. present in the [output of `man confstr`](https://gist.github.com/thomcc/12a27c7998019b6da9fa4b539bdbca44)). This is apparently a [POSIX API](https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html) but I have no idea which other platforms support it, nor what values should be provided. It's somewhat important on Darwin (the only way to access the user temp dir), but I'm not sure what other use it has, so I've only provided it on Darwin. There are a few other constants in Darwin `unistd.h`, but they're omitted since they're only conditionally present, and they provide values that... don't actually work[^1]. As a result, I've only provided the ones documented by `confstr` documentation. [^1]: For example, `_CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS` nominally provides values that can be passed to a c compiler, but it gives `-W 64` for me, which does not seem to work with `clang`.
2 parents b252b2f + 52199a6 commit f6eb496

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

libc-test/semver/apple.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,10 @@ XATTR_SHOWCOMPRESSION
15111511
XUCRED_VERSION
15121512
YESEXPR
15131513
YESSTR
1514+
_CS_PATH
1515+
_CS_DARWIN_USER_DIR
1516+
_CS_DARWIN_USER_TEMP_DIR
1517+
_CS_DARWIN_USER_CACHE_DIR
15141518
_IOFBF
15151519
_IOLBF
15161520
_IONBF
@@ -1685,6 +1689,7 @@ clock_getres
16851689
clonefile
16861690
clonefileat
16871691
cmsghdr
1692+
confstr
16881693
connectx
16891694
copyfile
16901695
copyfile_flags_t

src/unix/bsd/apple/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,6 +3800,11 @@ pub const _SC_TRACE_NAME_MAX: ::c_int = 128;
38003800
pub const _SC_TRACE_SYS_MAX: ::c_int = 129;
38013801
pub const _SC_TRACE_USER_EVENT_MAX: ::c_int = 130;
38023802
pub const _SC_PASS_MAX: ::c_int = 131;
3803+
// `confstr` keys (only the values guaranteed by `man confstr`).
3804+
pub const _CS_PATH: ::c_int = 1;
3805+
pub const _CS_DARWIN_USER_DIR: ::c_int = 65536;
3806+
pub const _CS_DARWIN_USER_TEMP_DIR: ::c_int = 65537;
3807+
pub const _CS_DARWIN_USER_CACHE_DIR: ::c_int = 65538;
38033808

38043809
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
38053810
pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1;
@@ -4850,6 +4855,11 @@ extern "C" {
48504855
pub fn fchflags(fd: ::c_int, flags: ::c_uint) -> ::c_int;
48514856
pub fn clock_getres(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
48524857
pub fn clock_gettime(clk_id: ::clockid_t, tp: *mut ::timespec) -> ::c_int;
4858+
#[cfg_attr(
4859+
all(target_os = "macos", target_arch = "x86"),
4860+
link_name = "confstr$UNIX2003"
4861+
)]
4862+
pub fn confstr(name: ::c_int, buf: *mut ::c_char, len: ::size_t) -> ::size_t;
48534863
pub fn lio_listio(
48544864
mode: ::c_int,
48554865
aiocb_list: *const *mut aiocb,

0 commit comments

Comments
 (0)