alarm.c 771 B

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