Ardour  9.2-654-gd2ed0bd940
msvc_gettimeofday.h
Go to the documentation of this file.
1 /*
2  * (C) 2026 EZ4Stephen <ez4stephen@tutamail.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #include <chrono>
20 
21 inline int gettimeofday(struct timeval* tv, struct timezone*) {
22  if (!tv) return -1;
23 
24  using namespace std::chrono;
25 
26  auto now = system_clock::now();
27  auto duration = now.time_since_epoch();
28 
29  auto secs = duration_cast<seconds>(duration);
30  auto usecs = duration_cast<microseconds>(duration - secs);
31 
32  tv->tv_sec = static_cast<long>(secs.count());
33  tv->tv_usec = static_cast<long>(usecs.count());
34 
35  return 0;
36 }
int gettimeofday(struct timeval *tv, struct timezone *)