1
0

setitimer_time32.c 938 B

12345678910111213141516171819202122232425
  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. if (old32) {
  18. old32->it_interval.tv_sec = old.it_interval.tv_sec;
  19. old32->it_interval.tv_usec = old.it_interval.tv_usec;
  20. old32->it_value.tv_sec = old.it_value.tv_sec;
  21. old32->it_value.tv_usec = old.it_value.tv_usec;
  22. }
  23. return 0;
  24. }