env.odin 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package os2
  2. import "base:runtime"
  3. // get_env retrieves the value of the environment variable named by the key
  4. // It returns the value, which will be empty if the variable is not present
  5. // To distinguish between an empty value and an unset value, use lookup_env
  6. // NOTE: the value will be allocated with the supplied allocator
  7. get_env :: proc(key: string, allocator: runtime.Allocator) -> string {
  8. value, _ := lookup_env(key, allocator)
  9. return value
  10. }
  11. // lookup_env gets the value of the environment variable named by the key
  12. // If the variable is found in the environment the value (which can be empty) is returned and the boolean is true
  13. // Otherwise the returned value will be empty and the boolean will be false
  14. // NOTE: the value will be allocated with the supplied allocator
  15. lookup_env :: proc(key: string, allocator: runtime.Allocator) -> (value: string, found: bool) {
  16. return _lookup_env(key, allocator)
  17. }
  18. // set_env sets the value of the environment variable named by the key
  19. // Returns true on success, false on failure
  20. set_env :: proc(key, value: string) -> bool {
  21. return _set_env(key, value)
  22. }
  23. // unset_env unsets a single environment variable
  24. // Returns true on success, false on failure
  25. unset_env :: proc(key: string) -> bool {
  26. return _unset_env(key)
  27. }
  28. clear_env :: proc() {
  29. _clear_env()
  30. }
  31. // environ returns a copy of strings representing the environment, in the form "key=value"
  32. // NOTE: the slice of strings and the strings with be allocated using the supplied allocator
  33. environ :: proc(allocator: runtime.Allocator) -> []string {
  34. return _environ(allocator)
  35. }