Skip to content
/ rust Public
forked from rust-lang/rust

Commit 5ad3488

Browse files
committed
unbreak tree for openbsd after rust-lang#21787
- 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.
1 parent 2bd8ec2 commit 5ad3488

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/libstd/sys/unix/c.rs

+4-1
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

+7-6
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,23 @@ pub fn current_exe() -> IoResult<Path> {
197197
}
198198

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

203203
static LOCK: StaticMutex = MUTEX_INIT;
204204

205205
extern {
206-
fn rust_load_self() -> *const c_char;
206+
fn rust_current_exe() -> *const c_char;
207207
}
208208

209209
let _guard = LOCK.lock();
210210

211211
unsafe {
212-
let v = rust_load_self();
212+
let v = rust_current_exe();
213213
if v.is_null() {
214-
None
214+
Err(IoError::last_error())
215215
} else {
216-
Some(ffi::c_str_to_bytes(&v).to_vec())
216+
Ok(Path::new(ffi::c_str_to_bytes(&v).to_vec()))
217217
}
218218
}
219219
}
@@ -333,7 +333,8 @@ pub fn args() -> Args {
333333
#[cfg(any(target_os = "linux",
334334
target_os = "android",
335335
target_os = "freebsd",
336-
target_os = "dragonfly"))]
336+
target_os = "dragonfly",
337+
target_os = "openbsd"))]
337338
pub fn args() -> Args {
338339
use rt;
339340
let bytes = rt::args::clone().unwrap_or(Vec::new());

src/rt/rust_builtin.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int *__dfly_error(void) { return __error(); }
204204
#include <sys/sysctl.h>
205205
#include <limits.h>
206206

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

210210
if (self == NULL) {

0 commit comments

Comments
 (0)