1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-06 09:36:47 +02:00

Replace deprecated usleep function with nanosleep

usleep was declared obsolete in POSIX.1-2001
This commit is contained in:
jfreegman
2020-11-03 12:17:48 -05:00
parent f64300d1d6
commit 42763905d7
7 changed files with 32 additions and 13 deletions

View File

@ -70,6 +70,19 @@ int timed_out(time_t timestamp, time_t timeout)
return timestamp + timeout <= get_unix_time();
}
/* Sleeps the caller's thread for `usec` microseconds */
void sleep_thread(long int usec)
{
struct timespec req;
req.tv_sec = 0;
req.tv_nsec = usec * 1000L;
if (nanosleep(&req, NULL) == -1) {
fprintf(stderr, "nanosleep() returned -1\n");
}
}
/* Get the current local time */
struct tm *get_time(void)
{