Skip to content

Commit

Permalink
env: Add Env type and set() and get() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Jan 27, 2022
1 parent df4fa6a commit 36b31de
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions env.jk
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
link_with("libc.so.6")

// FIXME: These functions can return NULL, how do we check for this?
// Do we promote NULL to an empty string? Do we return a Pointer instead?
ext func getenv(name: string) -> string;
ext func setenv(name: string, value: string);

type Env(from: string);

func get(env: Env) -> string {
getenv(env.from)
}

func set(env: Env, new_value: string) {
setenv(env.from, new_value)
}

// FIXME: Add assertions
test get_home() {
println(Env(from: "HOME").get())
}

test set_var() {
random_env_var = Env(from: "__jinko_RANDOM_ENV_VAR");
random_env_var.set("is_set")

// random_env_var.get().should_be("is_set")
}

0 comments on commit 36b31de

Please sign in to comment.