Apache Mesos
temp.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_OS_POSIX_TEMP_HPP__
14 #define __STOUT_OS_POSIX_TEMP_HPP__
15 
16 #include <string>
17 
18 #include <stout/os/getenv.hpp>
19 
20 
21 namespace os {
22 
23 // Attempts to resolve the system-designated temporary directory before
24 // back on a sensible default. On POSIX platforms, this involves checking
25 // the POSIX-standard `TMPDIR` environment variable before falling
26 // back to `/tmp`.
27 inline std::string temp()
28 {
29  Option<std::string> tmpdir = os::getenv("TMPDIR");
30 
31  return tmpdir.getOrElse("/tmp");
32 }
33 
34 } // namespace os {
35 
36 #endif // __STOUT_OS_POSIX_TEMP_HPP__
T getOrElse(U &&u) const &
Definition: option.hpp:133
Definition: posix_signalhandler.hpp:23
Option< std::string > getenv(const std::string &key)
Definition: getenv.hpp:29
std::string temp()
Definition: temp.hpp:27