env.odin 1.5 KB

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