Mercurial > hg > orthanc
comparison Core/SystemToolbox.cpp @ 2920:ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 07 Nov 2018 11:13:30 +0100 |
parents | 9d277f8ad698 |
children | 4a38d7d4f0e0 |
comparison
equal
deleted
inserted
replaced
2919:2ca9cd064b15 | 2920:ad0e7def3338 |
---|---|
36 | 36 |
37 | 37 |
38 #if defined(_WIN32) | 38 #if defined(_WIN32) |
39 # include <windows.h> | 39 # include <windows.h> |
40 # include <process.h> // For "_spawnvp()" and "_getpid()" | 40 # include <process.h> // For "_spawnvp()" and "_getpid()" |
41 # include <stdlib.h> // For "environ" | |
41 #else | 42 #else |
42 # include <unistd.h> // For "execvp()" | 43 # include <unistd.h> // For "execvp()" |
43 # include <sys/wait.h> // For "waitpid()" | 44 # include <sys/wait.h> // For "waitpid()" |
44 #endif | 45 #endif |
45 | 46 |
68 | 69 |
69 #include <boost/filesystem.hpp> | 70 #include <boost/filesystem.hpp> |
70 #include <boost/filesystem/fstream.hpp> | 71 #include <boost/filesystem/fstream.hpp> |
71 #include <boost/date_time/posix_time/posix_time.hpp> | 72 #include <boost/date_time/posix_time/posix_time.hpp> |
72 #include <boost/thread.hpp> | 73 #include <boost/thread.hpp> |
74 | |
75 | |
76 /*========================================================================= | |
77 The section below comes from the Boost 1.68.0 project: | |
78 https://github.com/boostorg/program_options/blob/boost-1.68.0/src/parsers.cpp | |
79 | |
80 Copyright Vladimir Prus 2002-2004. | |
81 Distributed under the Boost Software License, Version 1.0. | |
82 (See accompanying file LICENSE_1_0.txt | |
83 or copy at http://www.boost.org/LICENSE_1_0.txt) | |
84 =========================================================================*/ | |
85 | |
86 // The 'environ' should be declared in some cases. E.g. Linux man page says: | |
87 // (This variable must be declared in the user program, but is declared in | |
88 // the header file unistd.h in case the header files came from libc4 or libc5, | |
89 // and in case they came from glibc and _GNU_SOURCE was defined.) | |
90 // To be safe, declare it here. | |
91 | |
92 // It appears that on Mac OS X the 'environ' variable is not | |
93 // available to dynamically linked libraries. | |
94 // See: http://article.gmane.org/gmane.comp.lib.boost.devel/103843 | |
95 // See: http://lists.gnu.org/archive/html/bug-guile/2004-01/msg00013.html | |
96 #if defined(__APPLE__) && defined(__DYNAMIC__) | |
97 // The proper include for this is crt_externs.h, however it's not | |
98 // available on iOS. The right replacement is not known. See | |
99 // https://svn.boost.org/trac/boost/ticket/5053 | |
100 extern "C" | |
101 { | |
102 extern char ***_NSGetEnviron(void); | |
103 } | |
104 # define environ (*_NSGetEnviron()) | |
105 #else | |
106 # if defined(__MWERKS__) | |
107 # include <crtl.h> | |
108 # else | |
109 # if !defined(_WIN32) || defined(__COMO_VERSION__) | |
110 extern char** environ; | |
111 # endif | |
112 # endif | |
113 #endif | |
114 | |
115 | |
116 /*========================================================================= | |
117 End of section from the Boost 1.68.0 project | |
118 =========================================================================*/ | |
73 | 119 |
74 | 120 |
75 namespace Orthanc | 121 namespace Orthanc |
76 { | 122 { |
77 static bool finish_; | 123 static bool finish_; |
643 else | 689 else |
644 { | 690 { |
645 return MimeType_Binary; | 691 return MimeType_Binary; |
646 } | 692 } |
647 } | 693 } |
694 | |
695 | |
696 void SystemToolbox::GetEnvironmentVariables(std::map<std::string, std::string>& env) | |
697 { | |
698 env.clear(); | |
699 | |
700 for (char **p = environ; *p != NULL; p++) | |
701 { | |
702 std::string v(*p); | |
703 size_t pos = v.find('='); | |
704 | |
705 if (pos != std::string::npos) | |
706 { | |
707 std::string key = v.substr(0, pos); | |
708 std::string value = v.substr(pos + 1); | |
709 env[key] = value; | |
710 } | |
711 } | |
712 } | |
648 } | 713 } |