From 4296771fa60c9e0994b5b5da9b399a73bde94614 Mon Sep 17 00:00:00 2001 From: Sergei Akhmatdinov Date: Sun, 14 Apr 2019 15:13:22 -0400 Subject: [PATCH 1/2] replace usleep() in msleep() with nanosleep() add default case in ASCII character processing --- rlutil.h | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/rlutil.h b/rlutil.h index 24b6322..a27ba45 100644 --- a/rlutil.h +++ b/rlutil.h @@ -1,4 +1,5 @@ -#pragma once +/* #pragma once */ +/* ^ Not entirely portable ^ */ /** * File: rlutil.h * @@ -49,6 +50,7 @@ } #else #include // for getch() / printf() + #include // for strlen() RLUTIL_INLINE void locate(int x, int y); // Forward declare for C to avoid warnings #endif // __cplusplus @@ -61,7 +63,8 @@ #define kbhit _kbhit #else #include // for getch() and kbhit() - #include // for getch(), kbhit() and (u)sleep() + #include // for getch() and kbhit() + #include // for nanosleep() #include // for getkey() #include // for kbhit() #include // for kbhit() @@ -392,6 +395,7 @@ RLUTIL_INLINE int getkey(void) { case 'B': return KEY_DOWN; case 'C': return KEY_RIGHT; case 'D': return KEY_LEFT; + default: return -1; } } else return KEY_ESCAPE; } @@ -637,9 +641,14 @@ RLUTIL_INLINE void msleep(unsigned int ms) { #ifdef _WIN32 Sleep(ms); #else - // usleep argument must be under 1 000 000 - if (ms > 1000) sleep(ms/1000000); - usleep((ms % 1000000) * 1000); + struct timespec ts; + + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000000L; + + if(nanosleep(&ts, NULL) < 0) { + perror("sleep failed"); + } #endif } From e119ea621d23a5b16b7d6c622eac2f67e3f6fc3f Mon Sep 17 00:00:00 2001 From: Sergei Akhmatdinov Date: Sun, 14 Apr 2019 15:16:03 -0400 Subject: [PATCH 2/2] puts pragma once back --- rlutil.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rlutil.h b/rlutil.h index a27ba45..55c55ff 100644 --- a/rlutil.h +++ b/rlutil.h @@ -1,5 +1,4 @@ -/* #pragma once */ -/* ^ Not entirely portable ^ */ +#pragma once /** * File: rlutil.h *