Skip to content

Commit c1f0498

Browse files
committedApr 13, 2025·
Hermit: Unify std::env::args with Unix
The only differences between these implementations are that Unix uses relaxed ordering, but Hermit uses acquire/release, and Unix truncates `argv` at the first null pointer, but Hermit doesn't. Since Hermit aims for Unix compatibility, unify it with Unix.
1 parent 092a284 commit c1f0498

File tree

3 files changed

+9
-40
lines changed

3 files changed

+9
-40
lines changed
 

‎library/std/src/sys/args/hermit.rs

-35
This file was deleted.

‎library/std/src/sys/args/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#![forbid(unsafe_op_in_unsafe_fn)]
44

55
cfg_if::cfg_if! {
6-
if #[cfg(all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))))] {
6+
if #[cfg(any(
7+
all(target_family = "unix", not(any(target_os = "espidf", target_os = "vita"))),
8+
target_os = "hermit",
9+
))] {
710
mod unix;
811
pub use unix::*;
912
} else if #[cfg(target_family = "windows")] {
1013
mod windows;
1114
pub use windows::*;
12-
} else if #[cfg(target_os = "hermit")] {
13-
mod hermit;
14-
pub use hermit::*;
1515
} else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] {
1616
mod sgx;
1717
pub use sgx::*;

‎library/std/src/sys/args/unix.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#![allow(dead_code)] // runtime init functions not used during testing
77

88
use crate::ffi::CStr;
9+
#[cfg(target_os = "hermit")]
10+
use crate::os::hermit::ffi::OsStringExt;
11+
#[cfg(not(target_os = "hermit"))]
912
use crate::os::unix::ffi::OsStringExt;
1013

1114
#[path = "common.rs"]
@@ -73,6 +76,7 @@ pub fn args() -> Args {
7376
target_os = "illumos",
7477
target_os = "emscripten",
7578
target_os = "haiku",
79+
target_os = "hermit",
7680
target_os = "l4re",
7781
target_os = "fuchsia",
7882
target_os = "redox",
@@ -100,7 +104,7 @@ mod imp {
100104

101105
unsafe fn really_init(argc: isize, argv: *const *const u8) {
102106
// These don't need to be ordered with each other or other stores,
103-
// because they only hold the unmodified system-provide argv/argc.
107+
// because they only hold the unmodified system-provided argv/argc.
104108
ARGC.store(argc, Ordering::Relaxed);
105109
ARGV.store(argv as *mut _, Ordering::Relaxed);
106110
}

0 commit comments

Comments
 (0)
Please sign in to comment.