alarm.c 721 B

12345678910111213141516171819202122232425262728293031323334
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * alarm() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codpoet.org>
  6. *
  7. * GNU Library General Public License (LGPL) version 2 or later.
  8. */
  9. #include "syscalls.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