ualarm.c 549 B

12345678910111213141516171819202122232425
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <time.h>
  7. #include <sys/time.h>
  8. #include <sys/types.h>
  9. #include <unistd.h>
  10. useconds_t ualarm(useconds_t value, useconds_t interval)
  11. {
  12. struct itimerval otimer;
  13. const struct itimerval itimer = {
  14. { 0, interval },
  15. { 0, value}
  16. };
  17. if (setitimer(ITIMER_REAL, &itimer, &otimer) < 0) {
  18. return -1;
  19. }
  20. return((otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec);
  21. }