setitimer_time32.c 917 B

1234567891011121314151617181920212223
  1. #include "time32.h"
  2. #include <time.h>
  3. #include <sys/time.h>
  4. int __setitimer_time32(int which, const struct itimerval32 *restrict new32, struct itimerval32 *restrict old32)
  5. {
  6. struct itimerval old;
  7. int r = setitimer(which, (&(struct itimerval){
  8. .it_interval.tv_sec = new32->it_interval.tv_sec,
  9. .it_interval.tv_usec = new32->it_interval.tv_usec,
  10. .it_value.tv_sec = new32->it_value.tv_sec,
  11. .it_value.tv_usec = new32->it_value.tv_usec}), &old);
  12. if (r) return r;
  13. /* The above call has already committed to success by changing the
  14. * timer setting, so we can't fail on out-of-range old value.
  15. * Since these are relative times, values large enough to overflow
  16. * don't make sense anyway. */
  17. old32->it_interval.tv_sec = old.it_interval.tv_sec;
  18. old32->it_interval.tv_usec = old.it_interval.tv_usec;
  19. old32->it_value.tv_sec = old.it_value.tv_sec;
  20. old32->it_value.tv_usec = old.it_value.tv_usec;
  21. return 0;
  22. }