Postfix3.3.1
doze.c
[詳解]
1 /*++
2 /* NAME
3 /* doze 3
4 /* SUMMARY
5 /* take a nap
6 /* SYNOPSIS
7 /* #include <iostuff.h>
8 /*
9 /* void doze(microseconds)
10 /* unsigned microseconds;
11 /* DESCRIPTION
12 /* doze() sleeps for the specified number of microseconds. It is
13 /* a simple alternative for systems that lack usleep().
14 /* DIAGNOSTICS
15 /* All errors are fatal.
16 /* LICENSE
17 /* .ad
18 /* .fi
19 /* The Secure Mailer license must be distributed with this software.
20 /* AUTHOR(S)
21 /* Wietse Venema
22 /* IBM T.J. Watson Research
23 /* P.O. Box 704
24 /* Yorktown Heights, NY 10598, USA
25 /*--*/
26 
27 /* System library. */
28 
29 #include "sys_defs.h"
30 #include <sys/time.h>
31 #include <unistd.h>
32 #include <errno.h>
33 #ifdef USE_SYS_SELECT_H
34 #include <sys/select.h>
35 #endif
36 
37 /* Utility library. */
38 
39 #include <msg.h>
40 #include <iostuff.h>
41 
42 /* doze - sleep a while */
43 
44 void doze(unsigned delay)
45 {
46  struct timeval tv;
47 
48 #define MILLION 1000000
49 
50  tv.tv_sec = delay / MILLION;
51  tv.tv_usec = delay % MILLION;
52  while (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &tv) < 0)
53  if (errno != EINTR)
54  msg_fatal("doze: select: %m");
55 }
56 
57 #ifdef TEST
58 
59 #include <stdlib.h>
60 
61 int main(int argc, char **argv)
62 {
63  unsigned delay;
64 
65  if (argc != 2 || (delay = atol(argv[1])) == 0)
66  msg_fatal("usage: %s microseconds", argv[0]);
67  doze(delay);
68  exit(0);
69 }
70 
71 #endif
int main(int argc, char **argv)
Definition: anvil.c:1010
#define MILLION
void doze(unsigned delay)
Definition: doze.c:44
NORETURN msg_fatal(const char *fmt,...)
Definition: msg.c:249