X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftty%2Flib_twait.c;fp=ncurses%2Ftty%2Flib_twait.c;h=c698110afce2fc6240994f53f04f0cfe9b236537;hp=a7604b3e293ba0acc39135b5432d77114dddc35c;hb=6315e1a380ecdb706d4f6518d2e8c7eb0db8fbe2;hpb=e27924b560884229fa4c9cf5a90778aa6b7e5e96 diff --git a/ncurses/tty/lib_twait.c b/ncurses/tty/lib_twait.c index a7604b3e..c698110a 100644 --- a/ncurses/tty/lib_twait.c +++ b/ncurses/tty/lib_twait.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018,2020 Thomas E. Dickey * + * Copyright 2018-2020,2023 Thomas E. Dickey * * Copyright 1998-2015,2016 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -76,8 +76,11 @@ #endif #undef CUR -MODULE_ID("$Id: lib_twait.c,v 1.75 2020/02/29 15:46:00 anonymous.maarten Exp $") +MODULE_ID("$Id: lib_twait.c,v 1.79 2023/02/25 21:59:30 tom Exp $") +/* + * Returns an elapsed time, in milliseconds (if possible). + */ static long _nc_gettime(TimeType * t0, int first) { @@ -85,18 +88,20 @@ _nc_gettime(TimeType * t0, int first) #if PRECISE_GETTIME TimeType t1; - gettimeofday(&t1, (struct timezone *) 0); - if (first) { + if (GetClockTime(&t1) == -1) { + *t0 = t1; + res = first ? 0 : 1; + } else if (first) { *t0 = t1; res = 0; } else { /* .tv_sec and .tv_usec are unsigned, be careful when subtracting */ - if (t0->tv_usec > t1.tv_usec) { - t1.tv_usec += 1000000; /* Convert 1s in 1e6 microsecs */ + if (t0->sub_secs > t1.sub_secs) { + t1.sub_secs += TimeScale; t1.tv_sec--; } - res = (t1.tv_sec - t0->tv_sec) * 1000 - + (t1.tv_usec - t0->tv_usec) / 1000; + res = (t1.tv_sec - t0->tv_sec) * 1000L + + (t1.sub_secs - t0->sub_secs) / (TimeScale / 1000L); } #else time_t t1 = time((time_t *) 0);