cstdlib.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #ifndef BOOST_NOWIDE_CSTDLIB_HPP_INCLUDED
  7. #define BOOST_NOWIDE_CSTDLIB_HPP_INCLUDED
  8. #include <boost/nowide/config.hpp>
  9. #if !defined(BOOST_WINDOWS)
  10. #include <cstdlib>
  11. #endif
  12. namespace boost {
  13. namespace nowide {
  14. #if !defined(BOOST_WINDOWS) && !defined(BOOST_NOWIDE_DOXYGEN)
  15. using std::getenv;
  16. using std::system;
  17. #else
  18. ///
  19. /// \brief UTF-8 aware getenv. Returns 0 if the variable is not set.
  20. ///
  21. /// The string pointed to shall not be modified by the program.
  22. /// This function is thread-safe as long as no other thread modifies the host environment.
  23. /// However subsequent calls to this function might overwrite the string pointed to.
  24. ///
  25. /// Warning: The returned pointer might only be valid for as long as the calling thread is alive.
  26. /// So avoid passing it across thread boundaries.
  27. ///
  28. BOOST_NOWIDE_DECL char* getenv(const char* key);
  29. ///
  30. /// Same as std::system but cmd is UTF-8.
  31. ///
  32. BOOST_NOWIDE_DECL int system(const char* cmd);
  33. #endif
  34. ///
  35. /// \brief Set environment variable \a key to \a value
  36. ///
  37. /// if overwrite is not 0, that the old value is always overwritten, otherwise,
  38. /// if the variable exists it remains unchanged
  39. ///
  40. /// \a key and \a value are UTF-8 on Windows
  41. /// \return zero on success, else nonzero
  42. ///
  43. BOOST_NOWIDE_DECL int setenv(const char* key, const char* value, int overwrite);
  44. ///
  45. /// \brief Remove environment variable \a key
  46. ///
  47. /// \a key is UTF-8 on Windows
  48. /// \return zero on success, else nonzero
  49. ///
  50. BOOST_NOWIDE_DECL int unsetenv(const char* key);
  51. ///
  52. /// \brief Adds or changes an environment variable, \a string must be in format KEY=VALUE
  53. ///
  54. /// \a string MAY become part of the environment, hence changes to the value MAY change
  55. /// the environment. For portability it is hence recommended NOT to change it.
  56. /// \a string is UTF-8 on Windows
  57. /// \return zero on success, else nonzero
  58. ///
  59. BOOST_NOWIDE_DECL int putenv(char* string);
  60. } // namespace nowide
  61. } // namespace boost
  62. #endif