summaryrefslogtreecommitdiff
path: root/klibc/klibc/alarm.c
blob: 40c0969432d0cc6d79b3b4d0be33e3957230d30a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * alarm.c
 */

#include <sys/time.h>
#include <sys/syscall.h>

#ifndef __NR_alarm

/* Emulate alarm() via setitimer() */

unsigned int alarm(unsigned int seconds)
{
  struct itimerval iv;

  iv.it_interval.tv_sec = iv.it_interval.tv_usec = 0;
  iv.it_value.tv_sec = seconds;
  iv.it_value.tv_usec = 0;

  setitimer(ITIMER_REAL, &iv, &iv);

  return iv.it_value.tv_sec + (iv.it_value.tv_usec ? 1 : 0);
}

#endif