tools/nolibc: add difftime()

This is used in various selftests and will be handy when integrating
those with nolibc.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250428-nolibc-misc-v2-11-3c043eeab06c@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
This commit is contained in:
Thomas Weißschuh 2025-04-28 14:40:12 +02:00 committed by Thomas Weißschuh
parent da69cfb17b
commit 7ff3c71a47
2 changed files with 19 additions and 0 deletions

View File

@ -108,6 +108,13 @@ int clock_settime(clockid_t clockid, struct timespec *tp)
}
static __inline__
double difftime(time_t time1, time_t time2)
{
return time1 - time2;
}
static __attribute__((unused))
time_t time(time_t *tptr)
{

View File

@ -1304,6 +1304,17 @@ int run_syscall(int min, int max)
return ret;
}
int test_difftime(void)
{
if (difftime(200., 100.) != 100.)
return 1;
if (difftime(100., 200.) != -100.)
return 1;
return 0;
}
int run_stdlib(int min, int max)
{
int test;
@ -1426,6 +1437,7 @@ int run_stdlib(int min, int max)
CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break;
CASE_TEST(abs); EXPECT_EQ(1, abs(-10), 10); break;
CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break;
CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break;
case __LINE__:
return ret; /* must be last */