vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / sleepus.c
blob47ed1cf12e228d83bfc40eba82f3b9888401ddb7
1 /* -*- c-basic-offset: 8; -*- */
2 #include <sys/types.h>
3 #include <sys/time.h>
4 #include <errno.h>
5 #include <stddef.h>
6 #include "ourhdr.h"
8 void
9 sleep_us(unsigned int nusecs)
11 struct timeval tval;
13 for ( ; ; ) {
14 tval.tv_sec = nusecs / 1000000;
15 tval.tv_usec = nusecs % 1000000;
16 if (select(0, NULL, NULL, NULL, &tval) == 0)
17 break; /* all OK */
19 * Note than on an interrupted system call (i.e, SIGIO) there's not
20 * much we can do, since the timeval{} isn't updated with the time
21 * remaining. We could obtain the clock time before the call, and
22 * then obtain the clock time here, subtracting them to determine
23 * how long select() blocked before it was interrupted, but that
24 * seems like too much work :-)
26 if (errno == EINTR)
27 continue;
28 err_sys("sleep_us: select error");