From 60e8d00b5b0659df28ded1a68916c2042a12b95b Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Sun, 7 Apr 2024 17:38:40 +0300 Subject: [PATCH] freadln.c: test: support POSIX `sleep` --- c-programming/io/freadln.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/c-programming/io/freadln.c b/c-programming/io/freadln.c index 6f7c867..36a0ea2 100644 --- a/c-programming/io/freadln.c +++ b/c-programming/io/freadln.c @@ -4,6 +4,9 @@ * The `freadln` function reads a line from STDIN into a string, allocating * memory for it. * + * NOTE: Test: Declare macro POSIX when compiling if you're using a POSIX + * system. + * * TODO: Figure out potential problems * TODO: Add 'flushing' of STDIN (while there are characters, read them) before * the input reading loop to avoid input queues @@ -76,7 +79,11 @@ int freadln(FILE* f, char** output, size_t* length_out) { } #ifdef TEST -# if defined(_WIN32) || defined(WIN32) +# if POSIX +# include +# define SLEEP_FN sleep +# define DO_SLEEP 1 +# elif defined(_WIN32) || defined(WIN32) # include # define SLEEP_FN(x) Sleep((DWORD) x) # define DO_SLEEP 1