aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-05-06 16:30:39 -0700
committerGraydon Hoare <[email protected]>2011-05-06 16:30:39 -0700
commit0f23bbac0104fe4c51923eb09b7a98c3e6239571 (patch)
tree0eab6391a37b71c753b5515358285163e93f76f2
parentPut out burning linux tinderbox. (diff)
downloadrust-0f23bbac0104fe4c51923eb09b7a98c3e6239571.tar.xz
rust-0f23bbac0104fe4c51923eb09b7a98c3e6239571.zip
Fix GenericOS.getenv returning a raw str, return an Option.t[str] instead.
-rw-r--r--src/comp/front/extenv.rs13
-rw-r--r--src/lib/GenericOS.rs9
-rw-r--r--src/lib/Term.rs2
3 files changed, 19 insertions, 5 deletions
diff --git a/src/comp/front/extenv.rs b/src/comp/front/extenv.rs
index a3fdde95..15483cec 100644
--- a/src/comp/front/extenv.rs
+++ b/src/comp/front/extenv.rs
@@ -23,9 +23,18 @@ fn expand_syntax_ext(parser.parser p,
p.err("malformed #env call");
}
+ // FIXME: if this was more thorough it would manufacture an
+ // Option.t[str] rather than just an maybe-empty string.
+
auto var = expr_to_str(p, args.(0));
- auto val = GenericOS.getenv(var);
- ret make_new_str(sp, val);
+ alt (GenericOS.getenv(var)) {
+ case (Option.none[str]) {
+ ret make_new_str(sp, "");
+ }
+ case (Option.some[str](?s)) {
+ ret make_new_str(sp, s);
+ }
+ }
}
// FIXME: duplicate code copied from extfmt.
diff --git a/src/lib/GenericOS.rs b/src/lib/GenericOS.rs
index c60fa2b8..30b1d1d0 100644
--- a/src/lib/GenericOS.rs
+++ b/src/lib/GenericOS.rs
@@ -1,4 +1,9 @@
-fn getenv(str n) -> str {
- ret Str.str_from_cstr(OS.libc.getenv(Str.buf(n)));
+fn getenv(str n) -> Option.t[str] {
+ auto s = OS.libc.getenv(Str.buf(n));
+ if (s == 0 as Str.sbuf) {
+ ret Option.none[str];
+ } else {
+ ret Option.some[str](Str.str_from_cstr(s));
+ }
}
diff --git a/src/lib/Term.rs b/src/lib/Term.rs
index fca04bff..b07dcc0c 100644
--- a/src/lib/Term.rs
+++ b/src/lib/Term.rs
@@ -31,7 +31,7 @@ fn reset(IO.buf_writer writer) {
}
fn color_supported() -> bool {
- ret Str.eq(GenericOS.getenv("TERM"), "xterm-color");
+ ret GenericOS.getenv("TERM") == Option.some[str]("xterm-color");
}
fn set_color(IO.buf_writer writer, u8 first_char, u8 color) {