ADDED: library(os), reasoning about environment variables.

Together with library(files), this addresses #511.
This commit is contained in:
Markus Triska
2020-07-11 18:41:18 +02:00
parent 5fd78320dd
commit eb872f8fca
5 changed files with 99 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ use std::net::{TcpListener, TcpStream};
use std::ops::Sub;
use std::rc::Rc;
use std::num::NonZeroU32;
use std::env;
use std::time::{Duration, SystemTime};
use crate::cpu_time::ProcessTime;
@@ -5637,6 +5638,28 @@ impl MachineState {
}
}
}
&SystemClauseType::GetEnv => {
let key = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
match env::var(key) {
Ok(value) => {
let cstr = self.heap.put_complete_string(&value);
self.unify(self[temp_v!(2)], cstr);
}
_ => {
self.fail = true;
return Ok(());
}
}
}
&SystemClauseType::SetEnv => {
let key = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
let value = self.heap_pstr_iter(self[temp_v!(2)]).to_string();
env::set_var(key, value);
}
&SystemClauseType::UnsetEnv => {
let key = self.heap_pstr_iter(self[temp_v!(1)]).to_string();
env::remove_var(key);
}
};
return_from_clause!(self.last_call, self)