ualarm.c 584 B

1234567891011121314151617181920212223242526
  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. /* libc_hidden_proto(setitimer) */
  11. useconds_t ualarm(useconds_t value, useconds_t interval)
  12. {
  13. struct itimerval otimer;
  14. const struct itimerval itimer = {
  15. { 0, interval },
  16. { 0, value}
  17. };
  18. if (setitimer(ITIMER_REAL, &itimer, &otimer) < 0) {
  19. return -1;
  20. }
  21. return((otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec);
  22. }