]> git.ipfire.org Git - thirdparty/glibc.git/blame - support/xtime.h
support: Provide xclock_settime test helper function
[thirdparty/glibc.git] / support / xtime.h
CommitLineData
33647a72 1/* Support functionality for using time.
2b778ceb 2 Copyright (C) 2019-2021 Free Software Foundation, Inc.
33647a72
MC
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but 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 the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
33647a72
MC
18
19#ifndef SUPPORT_TIME_H
20#define SUPPORT_TIME_H
21
22#include <time.h>
23
24__BEGIN_DECLS
25
a1565550
LM
26/* Name of the env variable, which indicates if it is possible to
27 adjust time on target machine. */
28#define SETTIME_ENV_NAME "GLIBC_TEST_ALLOW_TIME_SETTING"
29
33647a72
MC
30/* The following functions call the corresponding libc functions and
31 terminate the process on error. */
32
33void xclock_gettime (clockid_t clock, struct timespec *ts);
a1565550 34void xclock_settime (clockid_t clock, const struct timespec *ts);
33647a72 35
db13e32c
MC
36/* This helper can often simplify tests by avoiding an explicit
37 variable declaration or allowing that declaration to be const. */
38
39static inline struct timespec xclock_now (clockid_t clock)
40{
41 struct timespec ts;
42 xclock_gettime (clock, &ts);
43 return ts;
44}
45
33647a72
MC
46__END_DECLS
47
48#endif /* SUPPORT_TIME_H */