env.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: env.h
  4. // Created: 7/2010
  5. // Author: Vaclav Haisman
  6. //
  7. //
  8. // Copyright (C) 2010-2015, Vaclav Haisman. All rights reserved.
  9. //
  10. // Redistribution and use in source and binary forms, with or without modifica-
  11. // tion, are permitted provided that the following conditions are met:
  12. //
  13. // 1. Redistributions of source code must retain the above copyright notice,
  14. // this list of conditions and the following disclaimer.
  15. //
  16. // 2. Redistributions in binary form must reproduce the above copyright notice,
  17. // this list of conditions and the following disclaimer in the documentation
  18. // and/or other materials provided with the distribution.
  19. //
  20. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  21. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  22. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  25. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  27. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #ifndef LOG4CPLUS_INTERNAL_ENV_H
  31. #define LOG4CPLUS_INTERNAL_ENV_H
  32. #include <log4cplus/config.hxx>
  33. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  34. #pragma once
  35. #endif
  36. #include <vector>
  37. #include <log4cplus/tstring.h>
  38. #if defined (_WIN32)
  39. #include <log4cplus/config/windowsh-inc.h>
  40. #endif
  41. #ifdef LOG4CPLUS_HAVE_SYS_TYPES_H
  42. #include <sys/types.h>
  43. #endif
  44. #ifdef LOG4CPLUS_HAVE_UNISTD_H
  45. #include <unistd.h>
  46. #endif
  47. namespace log4cplus { namespace internal {
  48. //! Get environment variable value.
  49. bool get_env_var (tstring & value, tstring const & name);
  50. //! Parse a string as a boolean value.
  51. bool parse_bool (bool & val, tstring const & str);
  52. //! Parse a path into path components.
  53. bool split_path (std::vector<tstring> & components, std::size_t & special,
  54. tstring const & path);
  55. //! Makes directories leading to file.
  56. void make_dirs (tstring const & file_path);
  57. inline
  58. #if defined (_WIN32)
  59. DWORD
  60. get_process_id ()
  61. {
  62. return GetCurrentProcessId ();
  63. }
  64. #elif defined (LOG4CPLUS_HAVE_GETPID)
  65. pid_t
  66. get_process_id ()
  67. {
  68. return getpid ();
  69. }
  70. #else
  71. int
  72. get_process_id ()
  73. {
  74. return 0;
  75. }
  76. #endif
  77. } } // namespace log4cplus { namespace internal {
  78. #endif // LOG4CPLUS_INTERNAL_ENV_H