Get the length of time before the given timeout time arrives. Returns 1 if the time has already arrived, and 0 otherwise. */
| 2023 | /* Get the length of time before the given timeout time arrives. |
| 2024 | Returns 1 if the time has already arrived, and 0 otherwise. */ |
| 2025 | static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime, |
| 2026 | double const* userTimeout, |
| 2027 | kwsysProcessTimeNative* timeoutLength, |
| 2028 | int zeroIsExpired) |
| 2029 | { |
| 2030 | if (timeoutTime->tv_sec < 0) { |
| 2031 | /* No timeout time has been requested. */ |
| 2032 | return 0; |
| 2033 | } |
| 2034 | /* Calculate the remaining time. */ |
| 2035 | kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent(); |
| 2036 | kwsysProcessTime timeLeft = |
| 2037 | kwsysProcessTimeSubtract(*timeoutTime, currentTime); |
| 2038 | if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) { |
| 2039 | /* Caller has explicitly requested a zero timeout. */ |
| 2040 | timeLeft.tv_sec = 0; |
| 2041 | timeLeft.tv_usec = 0; |
| 2042 | } |
| 2043 | |
| 2044 | if (timeLeft.tv_sec < 0 || |
| 2045 | (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) { |
| 2046 | /* Timeout has already expired. */ |
| 2047 | return 1; |
| 2048 | } |
| 2049 | /* There is some time left. */ |
| 2050 | timeoutLength->tv_sec = timeLeft.tv_sec; |
| 2051 | timeoutLength->tv_usec = timeLeft.tv_usec; |
| 2052 | return 0; |
| 2053 | } |
| 2054 | |
| 2055 | static kwsysProcessTime kwsysProcessTimeGetCurrent(void) |
| 2056 | { |
no test coverage detected
searching dependent graphs…