static bool imap_mktime(struct tm *tm, time_t *time_r) { *time_r = utc_mktime(tm); if (*time_r != (time_t)-1) return TRUE; /* the date is outside valid range for time_t. it might still be technically valid though, so try to handle this case. with 64bit time_t the full 0..9999 year range is valid. */ if (tm->tm_year <= 100) { /* too old. time_t can be signed or unsigned, handle both cases. */ *time_r = (time_t)-1 < (int)0 ? INT_MIN : 0; } else { /* too high. return the highest allowed value. we shouldn't get here with 64bit time_t, but handle that anyway. */ /* APPLE */ if (time_t_max_bits() == 32 || time_t_max_bits() == 64) *time_r = (1UL << (time_t_max_bits()-1)) - 1; else *time_r = (1UL << time_t_max_bits()) - 1; } return FALSE; }
int io_loop_get_wait_time(struct ioloop *ioloop, struct timeval *tv_r) { struct timeval tv_now; struct priorityq_item *item; struct timeout *timeout; int msecs; item = priorityq_peek(ioloop->timeouts); timeout = (struct timeout *)item; if (timeout == NULL) { /* no timeouts. use INT_MAX msecs for timeval and return -1 for poll/epoll infinity. */ tv_r->tv_sec = INT_MAX / 1000; tv_r->tv_usec = 0; /* APPLE */ ioloop->next_max_time = (1ULL << (time_t_max_bits()-1)) - 1; return -1; } tv_now.tv_sec = 0; msecs = timeout_get_wait_time(timeout, tv_r, &tv_now); ioloop->next_max_time = (tv_now.tv_sec + msecs/1000) + 1; return msecs; }