diff --git a/rlutil.h b/rlutil.h index 24b6322..55c55ff 100644 --- a/rlutil.h +++ b/rlutil.h @@ -49,6 +49,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 +62,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 +394,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 +640,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 }