OpenVPN 3 Core Library
Loading...
Searching...
No Matches
modstat.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
14#include <fcntl.h> // Definition of AT_* constants */
15#include <sys/stat.h>
16#include <cstdint> // for std::uint64_t
17#include <cerrno>
18
19#include <string>
20
22
23namespace openvpn {
24
25#if defined(OPENVPN_PLATFORM_LINUX)
26
27inline int update_file_mod_time_nanoseconds(const std::string &filename,
28 const std::uint64_t nanoseconds_since_epooch)
29{
30 struct timespec times[2];
31 times[0].tv_sec = nanoseconds_since_epooch / std::uint64_t(1000000000);
32 times[0].tv_nsec = nanoseconds_since_epooch % std::uint64_t(1000000000);
33 times[1] = times[0];
34 if (::utimensat(AT_FDCWD, filename.c_str(), times, 0) == -1)
35 return errno;
36 return 0;
37}
38
39inline int update_file_mod_time_nanoseconds(const int fd,
40 const std::uint64_t nanoseconds_since_epooch)
41{
42 struct timespec times[2];
43 times[0].tv_sec = nanoseconds_since_epooch / std::uint64_t(1000000000);
44 times[0].tv_nsec = nanoseconds_since_epooch % std::uint64_t(1000000000);
45 times[1] = times[0];
46 if (::futimens(fd, times) == -1)
47 return errno;
48 return 0;
49}
50
51#else
52
53inline int update_file_mod_time_nanoseconds(const std::string &filename,
54 const std::uint64_t nanoseconds_since_epooch)
55{
56 return 0;
57}
58
59inline int update_file_mod_time_nanoseconds(const int fd,
60 const std::uint64_t nanoseconds_since_epooch)
61{
62 return 0;
63}
64
65#endif
66
67} // namespace openvpn
Support deferred server-side state creation when client connects.
Definition ovpncli.cpp:95
int update_file_mod_time_nanoseconds(const std::string &filename, const std::uint64_t nanoseconds_since_epooch)
Definition modstat.hpp:53