alarm.c 851 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * alarm() for uClibc
  4. *
  5. * Copyright (C) 2000-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * GNU Library General Public License (LGPL) version 2 or later.
  8. */
  9. #define setitimer __setitimer
  10. #include "syscalls.h"
  11. #include <unistd.h>
  12. #ifdef __NR_alarm
  13. #define __NR___alarm __NR_alarm
  14. attribute_hidden _syscall1(unsigned int, __alarm, unsigned int, seconds);
  15. #else
  16. #include <sys/time.h>
  17. unsigned int attribute_hidden __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. strong_alias(__alarm,alarm)