diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-06 05:36:48 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-06 16:21:05 +0530 |
| commit | efdf16b72f20ef4d3703ce018864611358d0023e (patch) | |
| tree | 0ad3be936b2c591ae0f4fabc0cdc80489b42e533 /src/libstd/sys | |
| parent | 5c172ad03cee9274028ae8333338845002eeec9a (diff) | |
| parent | cb4965ef3a826af8150ef863e98709b4ffa83767 (diff) | |
| download | rust-efdf16b72f20ef4d3703ce018864611358d0023e.tar.gz rust-efdf16b72f20ef4d3703ce018864611358d0023e.zip | |
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.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/c.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 23 |
2 files changed, 14 insertions, 14 deletions
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs index 50a8e6b73e3..22194145252 100644 --- a/src/libstd/sys/unix/c.rs +++ b/src/libstd/sys/unix/c.rs @@ -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; @@ -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, diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5004ff713c4..b191eda583c 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -47,13 +47,9 @@ pub fn errno() -> i32 { } #[cfg(target_os = "openbsd")] - fn errno_location() -> *const c_int { - extern { - fn __errno() -> *const c_int; - } - unsafe { - __errno() - } + unsafe fn errno_location() -> *const c_int { + extern { fn __errno() -> *const c_int; } + __errno() } #[cfg(any(target_os = "linux", target_os = "android"))] @@ -197,23 +193,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())) } } } @@ -333,7 +329,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()); |
