Apache Mesos
utime.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_UTIME_HPP__
14 #define __STOUT_OS_UTIME_HPP__
15 
16 #include <string>
17 
18 #ifdef __WINDOWS__
19 #include <sys/utime.h>
20 #else
21 #include <utime.h>
22 #endif // __WINDOWS__
23 
24 #include <stout/error.hpp>
25 #include <stout/nothing.hpp>
26 #include <stout/try.hpp>
27 
28 
29 namespace os {
30 
31 // Sets the access and modification times of 'path' to the current time.
32 inline Try<Nothing> utime(const std::string& path)
33 {
34  // NOTE: on Windows, this correctly dispatches to `_utime`, so there is no
35  // need to create a function alias in `stout/windows.hpp` as we have done for
36  // `stout/os/mkdir.hpp` and friends.
37  if (::utime(path.c_str(), nullptr) == -1) {
38  return ErrnoError();
39  }
40 
41  return Nothing();
42 }
43 
44 } // namespace os {
45 
46 
47 #endif // __STOUT_OS_UTIME_HPP__
Definition: path.hpp:29
Definition: nothing.hpp:16
Definition: check.hpp:33
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
Try< Nothing > utime(const std::string &path)
Definition: utime.hpp:32