Skip to content

Commit

Permalink
Don't try to use confstr in Miri
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 22, 2024
1 parent 14aef3d commit 6ce7e79
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions std/src/sys/pal/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,9 @@ pub fn page_size() -> usize {
//
// [posix_confstr]:
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html
#[cfg(target_vendor = "apple")]
//
// FIXME: Support `confstr` in Miri.
#[cfg(all(target_vendor = "apple", not(miri)))]
fn confstr(key: c_int, size_hint: Option<usize>) -> io::Result<OsString> {
let mut buf: Vec<u8> = Vec::with_capacity(0);
let mut bytes_needed_including_nul = size_hint
Expand Down Expand Up @@ -753,7 +755,7 @@ fn confstr(key: c_int, size_hint: Option<usize>) -> io::Result<OsString> {
Ok(OsString::from_vec(buf))
}

#[cfg(target_vendor = "apple")]
#[cfg(all(target_vendor = "apple", not(miri)))]
fn darwin_temp_dir() -> PathBuf {
confstr(libc::_CS_DARWIN_USER_TEMP_DIR, Some(64)).map(PathBuf::from).unwrap_or_else(|_| {
// It failed for whatever reason (there are several possible reasons),
Expand All @@ -765,7 +767,7 @@ fn darwin_temp_dir() -> PathBuf {
pub fn temp_dir() -> PathBuf {
crate::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(|| {
cfg_if::cfg_if! {
if #[cfg(target_vendor = "apple")] {
if #[cfg(all(target_vendor = "apple", not(miri)))] {
darwin_temp_dir()
} else if #[cfg(target_os = "android")] {
PathBuf::from("/data/local/tmp")
Expand Down
2 changes: 1 addition & 1 deletion std/src/sys/pal/unix/os/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn test_parse_glibc_version() {
// Smoke check `confstr`, do it for several hint values, to ensure our resizing
// logic is correct.
#[test]
#[cfg(target_vendor = "apple")]
#[cfg(all(target_vendor = "apple", not(miri)))]
fn test_confstr() {
for key in [libc::_CS_DARWIN_USER_TEMP_DIR, libc::_CS_PATH] {
let value_nohint = super::confstr(key, None).unwrap_or_else(|e| {
Expand Down

0 comments on commit 6ce7e79

Please sign in to comment.