env.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #include <util/generic/fwd.h>
  3. #include <util/generic/string.h>
  4. /**
  5. * Search the environment list provided by the host environment for associated variable.
  6. *
  7. * @param key String identifying the name of the environmental variable to look for
  8. * @param def String that returns if environmental variable not found by key
  9. *
  10. * @return String that is associated with the matched environment variable or empty string if
  11. * such variable is missing.
  12. *
  13. * @note Use it only in pair with `SetEnv` as there may be inconsistency in their behaviour
  14. * otherwise.
  15. * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized.
  16. * @see SetEnv
  17. */
  18. TString GetEnv(const TString& key, const TString& def = TString());
  19. /**
  20. * Search the environment list provided by the host environment for associated variable.
  21. *
  22. * @param key String identifying the name of the environmental variable to look for
  23. *
  24. * @return String that is associated with the matched environment
  25. * variable or empty optional value if such variable is missing.
  26. *
  27. * @throws TSystemError If name of the variable has invalid format
  28. *
  29. * @note Use it only in pair with `SetEnv` as there may be inconsistency
  30. * in their behaviour otherwise.
  31. * @note Calls to `TryGetEnv` and `SetEnv` from different threads must be synchronized.
  32. * @see SetEnv
  33. */
  34. TMaybe<TString> TryGetEnv(const TString& key);
  35. /**
  36. * Add or change environment variable provided by the host environment.
  37. *
  38. * @param key String identifying the name of the environment variable to set or change
  39. * @param value Value to assign
  40. * @note Use it only in pair with `GetEnv` as there may be inconsistency in their behaviour
  41. * otherwise.
  42. * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized.
  43. * @see GetEnv
  44. */
  45. void SetEnv(const TString& key, const TString& value);
  46. /**
  47. * Remove environment variable from the host environment.
  48. *
  49. * @param key String identifying the name of the environment variable to remove
  50. *
  51. * @note If key does not exist in the environment, then the environment is unchanged,
  52. * and the function returns normally.
  53. * @note Calls to `GetEnv` and `SetEnv` from different threads must be synchronized.
  54. * @see GetEnv
  55. */
  56. void UnsetEnv(const TString& key);