2011-07-17 19:11:40 -05:00
|
|
|
import str::sbuf;
|
2011-05-12 10:24:54 -05:00
|
|
|
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2011-07-17 19:11:40 -05:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "macos")]
|
2011-08-10 11:27:11 -05:00
|
|
|
fn getenv(n: str) -> option::t<str> {
|
2011-07-27 07:19:39 -05:00
|
|
|
let s = os::libc::getenv(str::buf(n));
|
|
|
|
ret if s as int == 0 {
|
2011-08-12 12:56:57 -05:00
|
|
|
option::none::<str>
|
|
|
|
} else { option::some::<str>(str::str_from_cstr(s)) };
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "macos")]
|
2011-07-27 07:19:39 -05:00
|
|
|
fn setenv(n: str, v: str) {
|
|
|
|
let nbuf = str::buf(n);
|
|
|
|
let vbuf = str::buf(v);
|
2011-07-17 19:11:40 -05:00
|
|
|
os::libc::setenv(nbuf, vbuf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "win32")]
|
2011-08-10 11:27:11 -05:00
|
|
|
fn getenv(n: str) -> option::t<str> {
|
2011-07-27 07:19:39 -05:00
|
|
|
let nbuf = str::buf(n);
|
|
|
|
let nsize = 256u;
|
|
|
|
while true {
|
|
|
|
let vstr = str::alloc(nsize - 1u);
|
|
|
|
let vbuf = str::buf(vstr);
|
|
|
|
let res = os::kernel32::GetEnvironmentVariableA(nbuf, vbuf, nsize);
|
|
|
|
if res == 0u {
|
2011-07-17 19:11:40 -05:00
|
|
|
ret option::none;
|
|
|
|
} else if (res < nsize) {
|
|
|
|
ret option::some(str::str_from_cstr(vbuf));
|
2011-07-27 07:19:39 -05:00
|
|
|
} else { nsize = res; }
|
2011-07-17 19:11:40 -05:00
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "win32")]
|
2011-07-27 07:19:39 -05:00
|
|
|
fn setenv(n: str, v: str) {
|
|
|
|
let nbuf = str::buf(n);
|
|
|
|
let vbuf = str::buf(v);
|
2011-07-17 19:11:40 -05:00
|
|
|
os::kernel32::SetEnvironmentVariableA(nbuf, vbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|