Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

45 строки
959 B

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. #include <string> // std::string
  14. #include <cstdlib> // _dupenv_s / std::getenv
  15. namespace lol
  16. {
  17. namespace sys
  18. {
  19. static inline std::string getenv(std::string const &var)
  20. {
  21. #if _MSC_VER
  22. char *buf = nullptr;
  23. size_t count = 0;
  24. if (_dupenv_s(&buf, &count, var.c_str()) == 0 && buf)
  25. {
  26. std::string ret(buf);
  27. free(buf);
  28. return ret;
  29. }
  30. #else
  31. if (auto val = std::getenv(var.c_str()))
  32. return std::string(val);
  33. #endif
  34. return std::string();
  35. }
  36. } // namespace os
  37. } // namespace lol