libaaruformat 1.0 Aaru Data Preservation Suite - Format Library

Loading...
Searching...
No Matches
time.c
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stddef.h>
20#include <stdint.h>
21
22#ifdef _WIN32
23#include <windows.h>
24
25uint64_t get_filetime_uint64()
26{
27 FILETIME ft;
28 SYSTEMTIME st;
29 GetSystemTime(&st); // UTC time
30 SystemTimeToFileTime(&st, &ft);
31 return ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
32}
33
34#else
35#include <sys/time.h>
36
45uint64_t get_filetime_uint64()
46{
47 struct timeval tv;
48 gettimeofday(&tv, NULL); // seconds + microseconds since 1970
49
50 const uint64_t epoch_diff = 11644473600ULL; // seconds between 1601 and 1970
51 uint64_t ft = (tv.tv_sec + epoch_diff) * 10000000ULL + tv.tv_usec * 10;
52 return ft;
53}
54#endif
get_filetime_uint64
uint64_t get_filetime_uint64()
Gets the current time as a 64-bit FILETIME value.
Definition time.c:45