ualarm.c 450 B

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