1 /* Test for settimeofday
2 Copyright (C) 2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <support/check.h>
23 #include <support/xtime.h>
25 #define TIMESPEC_SEC_Y2038_OV 0x7FFFFFFF
26 #define FUTURE_TIME (TIMESPEC_SEC_Y2038_OV - 10)
31 const struct timeval tv
= { FUTURE_TIME
, 0};
32 struct timespec tv_future
, tv_now
;
34 /* Check if altering target time is allowed. */
35 if (getenv (SETTIME_ENV_NAME
) == NULL
)
36 FAIL_UNSUPPORTED ("settimeofday is executed only when "\
37 SETTIME_ENV_NAME
" is set\n");
39 tv_now
= xclock_now (CLOCK_REALTIME
);
40 int ret
= settimeofday (&tv
, NULL
);
42 FAIL_EXIT1 ("settimeofday failed: %m\n");
44 tv_future
= xclock_now (CLOCK_REALTIME
);
46 /* Restore old time value on target machine. */
47 xclock_settime (CLOCK_REALTIME
, (const struct timespec
*) &tv_now
);
49 if (tv_future
.tv_sec
< tv
.tv_sec
)
50 FAIL_EXIT1 ("settimeofday set wrong time!\n");
55 #include <support/test-driver.c>