Skip to content

Commit efdf16b

Browse files
committed
Rollup merge of #21964 - semarie:openbsd-env, r=alexcrichton
- add `_SC_GETPW_R_SIZE_MAX` constant - declare `struct passwd` - convert `load_self` to `current_exe` Note: OpenBSD don't provide system function to return a valuable Path for `env::current_exe`. The implementation is currently based on the value of `argv[0]`, which couldn't be used when executable is called via PATH.
2 parents 5c172ad + cb4965e commit efdf16b

File tree

5 files changed

+49
-15
lines changed

5 files changed

+49
-15
lines changed

src/libstd/env.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,38 @@ pub mod consts {
562562
pub const EXE_EXTENSION: &'static str = "";
563563
}
564564

565+
/// Constants associated with the current target
566+
#[cfg(target_os = "openbsd")]
567+
pub mod consts {
568+
pub use super::arch_consts::ARCH;
569+
570+
pub const FAMILY: &'static str = "unix";
571+
572+
/// A string describing the specific operating system in use: in this
573+
/// case, `dragonfly`.
574+
pub const OS: &'static str = "openbsd";
575+
576+
/// Specifies the filename prefix used for shared libraries on this
577+
/// platform: in this case, `lib`.
578+
pub const DLL_PREFIX: &'static str = "lib";
579+
580+
/// Specifies the filename suffix used for shared libraries on this
581+
/// platform: in this case, `.so`.
582+
pub const DLL_SUFFIX: &'static str = ".so";
583+
584+
/// Specifies the file extension used for shared libraries on this
585+
/// platform that goes after the dot: in this case, `so`.
586+
pub const DLL_EXTENSION: &'static str = "so";
587+
588+
/// Specifies the filename suffix used for executable binaries on this
589+
/// platform: in this case, the empty string.
590+
pub const EXE_SUFFIX: &'static str = "";
591+
592+
/// Specifies the file extension, if any, used for executable binaries
593+
/// on this platform: in this case, the empty string.
594+
pub const EXE_EXTENSION: &'static str = "";
595+
}
596+
565597
/// Constants associated with the current target
566598
#[cfg(target_os = "android")]
567599
pub mod consts {

src/libstd/os.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,8 @@ pub mod consts {
12891289
}
12901290

12911291
#[cfg(target_os = "openbsd")]
1292+
#[deprecated(since = "1.0.0", reason = "renamed to env::consts")]
1293+
#[unstable(feature = "os")]
12921294
pub mod consts {
12931295
pub use os::arch_consts::ARCH;
12941296

src/libstd/sys/unix/c.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70;
7474
#[cfg(any(target_os = "macos",
7575
target_os = "freebsd"))]
7676
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71;
77+
#[cfg(target_os = "openbsd")]
78+
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101;
7779
#[cfg(target_os = "android")]
7880
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048;
7981

@@ -91,7 +93,8 @@ pub struct passwd {
9193

9294
#[repr(C)]
9395
#[cfg(any(target_os = "macos",
94-
target_os = "freebsd"))]
96+
target_os = "freebsd",
97+
target_os = "openbsd"))]
9598
pub struct passwd {
9699
pub pw_name: *mut libc::c_char,
97100
pub pw_passwd: *mut libc::c_char,

src/libstd/sys/unix/os.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ pub fn errno() -> i32 {
4747
}
4848

4949
#[cfg(target_os = "openbsd")]
50-
fn errno_location() -> *const c_int {
51-
extern {
52-
fn __errno() -> *const c_int;
53-
}
54-
unsafe {
55-
__errno()
56-
}
50+
unsafe fn errno_location() -> *const c_int {
51+
extern { fn __errno() -> *const c_int; }
52+
__errno()
5753
}
5854

5955
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -197,23 +193,23 @@ pub fn current_exe() -> IoResult<Path> {
197193
}
198194

199195
#[cfg(target_os = "openbsd")]
200-
pub fn load_self() -> Option<Vec<u8>> {
196+
pub fn current_exe() -> IoResult<Path> {
201197
use sync::{StaticMutex, MUTEX_INIT};
202198

203199
static LOCK: StaticMutex = MUTEX_INIT;
204200

205201
extern {
206-
fn rust_load_self() -> *const c_char;
202+
fn rust_current_exe() -> *const c_char;
207203
}
208204

209205
let _guard = LOCK.lock();
210206

211207
unsafe {
212-
let v = rust_load_self();
208+
let v = rust_current_exe();
213209
if v.is_null() {
214-
None
210+
Err(IoError::last_error())
215211
} else {
216-
Some(ffi::c_str_to_bytes(&v).to_vec())
212+
Ok(Path::new(ffi::c_str_to_bytes(&v).to_vec()))
217213
}
218214
}
219215
}
@@ -333,7 +329,8 @@ pub fn args() -> Args {
333329
#[cfg(any(target_os = "linux",
334330
target_os = "android",
335331
target_os = "freebsd",
336-
target_os = "dragonfly"))]
332+
target_os = "dragonfly",
333+
target_os = "openbsd"))]
337334
pub fn args() -> Args {
338335
use rt;
339336
let bytes = rt::args::clone().unwrap_or(Vec::new());

src/rt/rust_builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int *__dfly_error(void) { return __error(); }
205205
#include <sys/sysctl.h>
206206
#include <limits.h>
207207

208-
const char * rust_load_self() {
208+
const char * rust_current_exe() {
209209
static char *self = NULL;
210210

211211
if (self == NULL) {

0 commit comments

Comments
 (0)