ualarm.c 419 B

12345678910111213141516171819
  1. #define _GNU_SOURCE
  2. #include <time.h>
  3. #include <sys/time.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. useconds_t ualarm(useconds_t value, useconds_t interval)
  7. {
  8. struct itimerval otimer;
  9. const struct itimerval itimer = {
  10. { 0, interval },
  11. { 0, value}
  12. };
  13. if (setitimer(ITIMER_REAL, &itimer, &otimer) < 0) {
  14. return -1;
  15. }
  16. return((otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec);
  17. }