diff --git a/src/libcore/os.rs b/src/libcore/os.rs index d01f45928302ef08624ae9ed2b78c64aa5c689ba..0045bad07a563903567aca11b9f744c2412fa6fa 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -732,6 +732,30 @@ pub fn set_exit_status(code: int) { rustrt::rust_set_exit_status(code as libc::intptr_t); } +/** + * Returns the command line arguments + * + * Returns a list of the command line arguments. + */ +#[cfg(target_os = "macos")] +pub fn args() -> ~[~str] { + unsafe { + let (argc, argv) = (*_NSGetArgc() as uint, *_NSGetArgv()); + let mut args = ~[]; + for uint::range(0, argc) |i| { + vec::push(&mut args, str::raw::from_c_str(*argv.offset(i))); + } + return args; + } +} + +#[cfg(target_os = "macos")] +extern { + // These functions are in crt_externs.h. + pub fn _NSGetArgc() -> *c_int; + pub fn _NSGetArgv() -> ***c_char; +} + #[cfg(unix)] pub fn family() -> ~str { ~"unix" } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index d0b848adde24adf86288456f0f4021ce6decda9e..9f9d2eea0e67a8d768ce9972c105e6f43f66538d 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -47,7 +47,7 @@ pub mod p2 { /// Calculate the offset from a pointer #[inline(always)] -pub fn offset(ptr: *T, count: uint) -> *T { +pub pure fn offset(ptr: *T, count: uint) -> *T { unsafe { (ptr as uint + count * sys::size_of::()) as *T } @@ -55,7 +55,7 @@ pub fn offset(ptr: *T, count: uint) -> *T { /// Calculate the offset from a const pointer #[inline(always)] -pub fn const_offset(ptr: *const T, count: uint) -> *const T { +pub pure fn const_offset(ptr: *const T, count: uint) -> *const T { unsafe { (ptr as uint + count * sys::size_of::()) as *T } @@ -63,7 +63,7 @@ pub fn const_offset(ptr: *const T, count: uint) -> *const T { /// Calculate the offset from a mut pointer #[inline(always)] -pub fn mut_offset(ptr: *mut T, count: uint) -> *mut T { +pub pure fn mut_offset(ptr: *mut T, count: uint) -> *mut T { (ptr as uint + count * sys::size_of::()) as *mut T } @@ -176,18 +176,25 @@ pub fn ref_eq(thing: &a/T, other: &b/T) -> bool { to_uint(thing) == to_uint(other) } -pub trait Ptr { +pub trait Ptr { pure fn is_null() -> bool; pure fn is_not_null() -> bool; + pure fn offset(count: uint) -> self; } /// Extension methods for pointers -impl *T: Ptr { +impl *T: Ptr { /// Returns true if the pointer is equal to the null pointer. + #[inline(always)] pure fn is_null() -> bool { is_null(self) } /// Returns true if the pointer is not equal to the null pointer. + #[inline(always)] pure fn is_not_null() -> bool { is_not_null(self) } + + /// Calculates the offset from a pointer. + #[inline(always)] + pure fn offset(count: uint) -> *T { offset(self, count) } } // Equality for pointers