Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / doze.c
blobecef20693fdbf43fe8bfe858ab2244142d8e906c
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* doze 3
6 /* SUMMARY
7 /* take a nap
8 /* SYNOPSIS
9 /* #include <iostuff.h>
11 /* void doze(microseconds)
12 /* unsigned microseconds;
13 /* DESCRIPTION
14 /* doze() sleeps for the specified number of microseconds. It is
15 /* a simple alternative for systems that lack usleep().
16 /* DIAGNOSTICS
17 /* All errors are fatal.
18 /* LICENSE
19 /* .ad
20 /* .fi
21 /* The Secure Mailer license must be distributed with this software.
22 /* AUTHOR(S)
23 /* Wietse Venema
24 /* IBM T.J. Watson Research
25 /* P.O. Box 704
26 /* Yorktown Heights, NY 10598, USA
27 /*--*/
29 /* System library. */
31 #include "sys_defs.h"
32 #include <sys/time.h>
33 #include <unistd.h>
34 #include <errno.h>
35 #ifdef USE_SYS_SELECT_H
36 #include <sys/select.h>
37 #endif
39 /* Utility library. */
41 #include <msg.h>
42 #include <iostuff.h>
44 /* doze - sleep a while */
46 void doze(unsigned delay)
48 struct timeval tv;
50 #define MILLION 1000000
52 tv.tv_sec = delay / MILLION;
53 tv.tv_usec = delay % MILLION;
54 while (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &tv) < 0)
55 if (errno != EINTR)
56 msg_fatal("doze: select: %m");
59 #ifdef TEST
61 #include <stdlib.h>
63 int main(int argc, char **argv)
65 unsigned delay;
67 if (argc != 2 || (delay = atol(argv[1])) == 0)
68 msg_fatal("usage: %s microseconds", argv[0]);
69 doze(delay);
70 exit(0);
73 #endif