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

Commit

Permalink
unbreak tree for openbsd after rust-lang#21787
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
semarie committed Feb 5, 2015
1 parent 2bd8ec2 commit 5ad3488
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/libstd/sys/unix/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 70;
#[cfg(any(target_os = "macos",
target_os = "freebsd"))]
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 71;
#[cfg(target_os = "openbsd")]
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 101;
#[cfg(target_os = "android")]
pub const _SC_GETPW_R_SIZE_MAX: libc::c_int = 0x0048;

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

#[repr(C)]
#[cfg(any(target_os = "macos",
target_os = "freebsd"))]
target_os = "freebsd",
target_os = "openbsd"))]
pub struct passwd {
pub pw_name: *mut libc::c_char,
pub pw_passwd: *mut libc::c_char,
Expand Down
13 changes: 7 additions & 6 deletions src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,23 @@ pub fn current_exe() -> IoResult<Path> {
}

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

static LOCK: StaticMutex = MUTEX_INIT;

extern {
fn rust_load_self() -> *const c_char;
fn rust_current_exe() -> *const c_char;
}

let _guard = LOCK.lock();

unsafe {
let v = rust_load_self();
let v = rust_current_exe();
if v.is_null() {
None
Err(IoError::last_error())
} else {
Some(ffi::c_str_to_bytes(&v).to_vec())
Ok(Path::new(ffi::c_str_to_bytes(&v).to_vec()))
}
}
}
Expand Down Expand Up @@ -333,7 +333,8 @@ pub fn args() -> Args {
#[cfg(any(target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly"))]
target_os = "dragonfly",
target_os = "openbsd"))]
pub fn args() -> Args {
use rt;
let bytes = rt::args::clone().unwrap_or(Vec::new());
Expand Down
2 changes: 1 addition & 1 deletion src/rt/rust_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int *__dfly_error(void) { return __error(); }
#include <sys/sysctl.h>
#include <limits.h>

const char * rust_load_self() {
const char * rust_current_exe() {
static char *self = NULL;

if (self == NULL) {
Expand Down

0 comments on commit 5ad3488

Please sign in to comment.