Apache Mesos
open.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_OPEN_HPP__
14 #define __STOUT_OS_POSIX_OPEN_HPP__
15 
16 #include <sys/stat.h>
17 #include <sys/types.h>
18 
19 #include <string>
20 
21 #include <stout/error.hpp>
22 #include <stout/nothing.hpp>
23 #include <stout/try.hpp>
24 
25 #include <stout/os/close.hpp>
26 #include <stout/os/fcntl.hpp>
27 #include <stout/os/int_fd.hpp>
28 
29 #ifndef O_CLOEXEC
30 #error "missing O_CLOEXEC support on this platform"
31 #endif
32 
33 namespace os {
34 
35 inline Try<int_fd> open(const std::string& path, int oflag, mode_t mode = 0)
36 {
37  int_fd fd = ::open(path.c_str(), oflag, mode);
38  if (fd < 0) {
39  return ErrnoError();
40  }
41 
42  return fd;
43 }
44 
45 } // namespace os {
46 
47 #endif // __STOUT_OS_POSIX_OPEN_HPP__
Definition: path.hpp:29
Definition: check.hpp:33
Try< int_fd > open(const std::string &path, int oflag, mode_t mode=0)
Definition: open.hpp:35
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
int mode_t
Definition: windows.hpp:177
Try< mode_t > mode(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:168
int int_fd
Definition: int_fd.hpp:35