aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gleam/os.gleam69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/gleam/os.gleam b/src/gleam/os.gleam
deleted file mode 100644
index af67e35..0000000
--- a/src/gleam/os.gleam
+++ /dev/null
@@ -1,69 +0,0 @@
-//// Function to interact with the host operating system.
-
-if erlang {
- import gleam/list
- import gleam/map.{Map}
- import gleam/string
-
- // Internal type for erlang interop.
- external type CharList
-
- external fn os_getenv() -> List(CharList) =
- "os" "getenv"
-
- external fn os_putenv(key: CharList, value: CharList) -> Bool =
- "os" "putenv"
-
- external fn os_unsetenv(key: CharList) -> Bool =
- "os" "unsetenv"
-
- external fn char_list_to_string(CharList) -> String =
- "unicode" "characters_to_binary"
-
- external fn string_to_char_list(String) -> CharList =
- "unicode" "characters_to_list"
-
- /// Returns all environment variables set on the system.
- pub fn get_env() -> Map(String, String) {
- list.map(
- os_getenv(),
- fn(char_list) {
- assert Ok(value) =
- string.split_once(char_list_to_string(char_list), "=")
- value
- },
- )
- |> map.from_list()
- }
-
- /// Sets an environment variable.
- pub fn insert_env(key: String, value: String) -> Nil {
- os_putenv(string_to_char_list(key), string_to_char_list(value))
- Nil
- }
-
- /// Deletes an environment variable.
- pub fn delete_env(key: String) -> Nil {
- os_unsetenv(string_to_char_list(key))
- Nil
- }
-
- pub type TimeUnit {
- Second
- Millisecond
- Microsecond
- Nanosecond
- }
-
- /// Returns the current OS system time.
- ///
- /// https://erlang.org/doc/apps/erts/time_correction.html#OS_System_Time
- pub external fn system_time(TimeUnit) -> Int =
- "os" "system_time"
-
- /// Returns the current OS system time as a tuple of Ints
- ///
- /// http://erlang.org/doc/man/os.html#timestamp-0
- pub external fn erlang_timestamp() -> #(Int, Int, Int) =
- "os" "timestamp"
-}