add sleep() function and improve Windows support

I could only test Windows support by compiling with gcc MinGW-w64 and
running with Wine.
This commit is contained in:
r4
2021-12-25 14:06:20 +01:00
parent dd67a1bf5d
commit b4c369e1d9
5 changed files with 46 additions and 6 deletions

17
util.c
View File

@@ -2,6 +2,23 @@
#include <stdarg.h>
#ifdef WIN32
#include <windows.h> /* Sleep */
#else
#include <time.h> /* nanosleep */
#endif
void sleep_secs(double secs) {
#ifdef WIN32
Sleep(secs * 1000.0);
#else
struct timespec ts;
ts.tv_sec = (time_t)secs;
ts.tv_nsec = (secs - (double)ts.tv_sec) * 1000000000.0;
nanosleep(&ts, NULL);
#endif
}
char errbuf[ERRSZ];
bool err;
size_t err_ln, err_col;