alarm.c 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /* libc_hidden_proto(alarm) */
  12. #ifdef __NR_alarm
  13. _syscall1(unsigned int, alarm, unsigned int, seconds)
  14. #else
  15. #include <sys/time.h>
  16. /* libc_hidden_proto(setitimer) */
  17. unsigned int alarm(unsigned int seconds)
  18. {
  19. struct itimerval old, new;
  20. unsigned int retval;
  21. new.it_value.tv_usec = 0;
  22. new.it_interval.tv_sec = 0;
  23. new.it_interval.tv_usec = 0;
  24. new.it_value.tv_sec = (long int) seconds;
  25. if (setitimer(ITIMER_REAL, &new, &old) < 0) {
  26. return 0;
  27. }
  28. retval = old.it_value.tv_sec;
  29. if (old.it_value.tv_usec) {
  30. ++retval;
  31. }
  32. return retval;
  33. }
  34. #endif
  35. libc_hidden_def(alarm)