env.odin 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. @(require_results)
  8. get_env :: proc(key: string, allocator: runtime.Allocator) -> string {
  9. value, _ := lookup_env(key, allocator)
  10. return value
  11. }
  12. // lookup_env gets the value of the environment variable named by the key
  13. // If the variable is found in the environment the value (which can be empty) is returned and the boolean is true
  14. // Otherwise the returned value will be empty and the boolean will be false
  15. // NOTE: the value will be allocated with the supplied allocator
  16. @(require_results)
  17. lookup_env :: proc(key: string, allocator: runtime.Allocator) -> (value: string, found: bool) {
  18. return _lookup_env(key, allocator)
  19. }
  20. // set_env sets the value of the environment variable named by the key
  21. // Returns true on success, false on failure
  22. set_env :: proc(key, value: string) -> bool {
  23. return _set_env(key, value)
  24. }
  25. // unset_env unsets a single environment variable
  26. // Returns true on success, false on failure
  27. unset_env :: proc(key: string) -> bool {
  28. return _unset_env(key)
  29. }
  30. clear_env :: proc() {
  31. _clear_env()
  32. }
  33. // environ returns a copy of strings representing the environment, in the form "key=value"
  34. // NOTE: the slice of strings and the strings with be allocated using the supplied allocator
  35. @(require_results)
  36. environ :: proc(allocator: runtime.Allocator) -> []string {
  37. return _environ(allocator)
  38. }