tmpdir.hpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef BOOST_ARCHIVE_TMPDIR_HPP
  2. #define BOOST_ARCHIVE_TMPDIR_HPP
  3. // MS compatible compilers support #pragma once
  4. #if defined(_MSC_VER)
  5. # pragma once
  6. #endif
  7. /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
  8. // tmpdir.hpp:
  9. // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
  10. // Use, modification and distribution is subject to the Boost Software
  11. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. // See http://www.boost.org for updates, documentation, and revision history.
  14. #include <cstdlib> // getenv
  15. #include <cstddef> // NULL
  16. #include <boost/config.hpp>
  17. #ifdef BOOST_NO_STDC_NAMESPACE
  18. namespace std {
  19. using ::getenv;
  20. }
  21. #endif
  22. namespace boost {
  23. namespace archive {
  24. inline const char * tmpdir(){
  25. const char *dirname;
  26. dirname = std::getenv("TMP");
  27. if(NULL == dirname)
  28. dirname = std::getenv("TMPDIR");
  29. if(NULL == dirname)
  30. dirname = std::getenv("TEMP");
  31. if(NULL == dirname){
  32. //BOOST_ASSERT(false); // no temp directory found
  33. dirname = ".";
  34. }
  35. return dirname;
  36. }
  37. } // archive
  38. } // boost
  39. #endif // BOOST_ARCHIVE_TMPDIR_HPP