This source file includes following definitions.
- handle_alarm
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <time.h>
22
23 #include "signature.h"
24 SIGNATURE_CHECK (nanosleep, int, (struct timespec const *, struct timespec *));
25
26 #include <errno.h>
27 #include <signal.h>
28 #include <unistd.h>
29
30 #include "macros.h"
31
32 #if HAVE_DECL_ALARM
33 static void
34 handle_alarm (int sig)
35 {
36 if (sig != SIGALRM)
37 _exit (1);
38 }
39 #endif
40
41 int
42 main (void)
43 {
44 struct timespec ts;
45
46 ts.tv_sec = 1000;
47 ts.tv_nsec = -1;
48 errno = 0;
49 ASSERT (nanosleep (&ts, NULL) == -1);
50 ASSERT (errno == EINVAL);
51 ts.tv_nsec = 1000000000;
52 errno = 0;
53 ASSERT (nanosleep (&ts, NULL) == -1);
54 ASSERT (errno == EINVAL);
55
56 ts.tv_sec = 0;
57 ts.tv_nsec = 1;
58 ASSERT (nanosleep (&ts, &ts) == 0);
59
60
61
62 ASSERT (ts.tv_sec == 0);
63 ASSERT (ts.tv_nsec == 0 || ts.tv_nsec == 1);
64 ts.tv_nsec = 0;
65 ASSERT (nanosleep (&ts, NULL) == 0);
66
67 #if HAVE_DECL_ALARM
68 {
69 const time_t pentecost = 50 * 24 * 60 * 60;
70 signal (SIGALRM, handle_alarm);
71 alarm (1);
72 ts.tv_sec = pentecost;
73 ts.tv_nsec = 999999999;
74 errno = 0;
75 ASSERT (nanosleep (&ts, &ts) == -1);
76 ASSERT (errno == EINTR);
77 ASSERT (pentecost - 10 < ts.tv_sec && ts.tv_sec <= pentecost);
78 ASSERT (0 <= ts.tv_nsec && ts.tv_nsec <= 999999999);
79 }
80 #endif
81
82 return 0;
83 }