- int
- main ()
- {
- static struct timespec ts_sleep;
- static struct timespec ts_remaining;
- static struct sigaction act;
- if (! nanosleep)
- return 1;
- act.sa_handler = check_for_SIGALRM;
- sigemptyset (&act.sa_mask);
- sigaction (SIGALRM, &act, NULL);
- ts_sleep.tv_sec = 0;
- ts_sleep.tv_nsec = 1;
- alarm (1);
- if (nanosleep (&ts_sleep, NULL) != 0)
- return 1;
- ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
- ts_sleep.tv_nsec = 999999999;
- alarm (1);
- if (nanosleep (&ts_sleep, &ts_remaining) == -1 && errno == EINTR
- && TYPE_MAXIMUM (time_t) - 10 < ts_remaining.tv_sec)
+ int
+ main ()
+ {
+ static struct timespec ts_sleep;
+ static struct timespec ts_remaining;
+ static struct sigaction act;
+ /* Test for major problems first. */
+ if (! nanosleep)
+ return 2;
+ act.sa_handler = check_for_SIGALRM;
+ sigemptyset (&act.sa_mask);
+ sigaction (SIGALRM, &act, NULL);
+ ts_sleep.tv_sec = 0;
+ ts_sleep.tv_nsec = 1;
+ alarm (1);
+ if (nanosleep (&ts_sleep, NULL) != 0)
+ return 3;
+ /* Test for a minor problem: the handling of large arguments. */
+ ts_sleep.tv_sec = TYPE_MAXIMUM (time_t);
+ ts_sleep.tv_nsec = 999999999;
+ alarm (1);
+ if (nanosleep (&ts_sleep, &ts_remaining) != -1)
+ return 4;
+ if (errno != EINTR)
+ return 5;
+ if (ts_remaining.tv_sec <= TYPE_MAXIMUM (time_t) - 10)
+ return 6;