alarm.c 755 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * alarm() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #include <unistd.h>
  11. #ifdef __NR_alarm
  12. _syscall1(unsigned int, alarm, unsigned int, seconds)
  13. #else
  14. # include <sys/time.h>
  15. unsigned int alarm(unsigned int seconds)
  16. {
  17. struct itimerval old, new;
  18. unsigned int retval;
  19. new.it_value.tv_usec = 0;
  20. new.it_interval.tv_sec = 0;
  21. new.it_interval.tv_usec = 0;
  22. new.it_value.tv_sec = (long int) seconds;
  23. if (setitimer(ITIMER_REAL, &new, &old) < 0) {
  24. return 0;
  25. }
  26. retval = old.it_value.tv_sec;
  27. if (old.it_value.tv_usec) {
  28. ++retval;
  29. }
  30. return retval;
  31. }
  32. #endif
  33. libc_hidden_def(alarm)