aboutsummaryrefslogtreecommitdiffstats
path: root/src/libposixplz/millisleep.c
blob: e781f5892b3217f010edfee188cf300014a801b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
/* ISC license. */

#include <time.h>

#include <skalibs/posixplz.h>

unsigned int millisleep (unsigned int msec)
{
  struct timespec ts = { .tv_sec = msec / 1000, .tv_nsec = (long)(msec % 1000) * 1000000U } ;
  struct timespec tr ;
  return nanosleep(&ts, &tr) == -1 ? 1000 * tr.tv_sec + tr.tv_nsec / 1000000U : 0 ;
}