Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Thomas Weißschuh and committed by
Thomas Weißschuh
7ff3c71a da69cfb1

+19
+7
tools/include/nolibc/time.h
··· 108 108 } 109 109 110 110 111 + static __inline__ 112 + double difftime(time_t time1, time_t time2) 113 + { 114 + return time1 - time2; 115 + } 116 + 117 + 111 118 static __attribute__((unused)) 112 119 time_t time(time_t *tptr) 113 120 {
+12
tools/testing/selftests/nolibc/nolibc-test.c
··· 1304 1304 return ret; 1305 1305 } 1306 1306 1307 + int test_difftime(void) 1308 + { 1309 + if (difftime(200., 100.) != 100.) 1310 + return 1; 1311 + 1312 + if (difftime(100., 200.) != -100.) 1313 + return 1; 1314 + 1315 + return 0; 1316 + } 1317 + 1307 1318 int run_stdlib(int min, int max) 1308 1319 { 1309 1320 int test; ··· 1437 1426 CASE_TEST(toupper_noop); EXPECT_EQ(1, toupper('A'), 'A'); break; 1438 1427 CASE_TEST(abs); EXPECT_EQ(1, abs(-10), 10); break; 1439 1428 CASE_TEST(abs_noop); EXPECT_EQ(1, abs(10), 10); break; 1429 + CASE_TEST(difftime); EXPECT_ZR(1, test_difftime()); break; 1440 1430 1441 1431 case __LINE__: 1442 1432 return ret; /* must be last */