Mercurial > emacs
changeset 14279:085bc709c11d
(sys_select): Use time macros to prevent time values
from overflowing.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 24 Jan 1996 21:21:40 +0000 |
parents | 3562c5f43780 |
children | 0134b04bc92d |
files | src/msdos.c |
diffstat | 1 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/msdos.c Wed Jan 24 21:21:07 1996 +0000 +++ b/src/msdos.c Wed Jan 24 21:21:40 1996 +0000 @@ -2461,6 +2461,14 @@ last_time = *t; } +#ifndef EMACS_TIME_ZERO_OR_NEG_P +#define EMACS_TIME_ZERO_OR_NEG_P(time) \ + ((long)(time).tv_sec < 0 \ + || ((time).tv_sec == 0 \ + && (long)(time).tv_usec <= 0)) +#endif + + /* Only event queue is checked. */ int sys_select (nfds, rfds, wfds, efds, timeout) @@ -2469,7 +2477,6 @@ EMACS_TIME *timeout; { int check_input; - long timeoutval, clnow, cllast; struct time t; check_input = 0; @@ -2496,19 +2503,25 @@ } else { - timeoutval = EMACS_SECS (*timeout) * 100 + EMACS_USECS (*timeout) / 10000; + EMACS_TIME clnow, cllast, cldiff; + check_timer (&t); - cllast = t.ti_sec * 100 + t.ti_hund; + EMACS_SET_SECS_USECS (cllast, t.ti_sec, t.ti_hund * 10000L); while (!check_input || !detect_input_pending ()) { check_timer (&t); - clnow = t.ti_sec * 100 + t.ti_hund; - if (clnow < cllast) /* time wrap */ - timeoutval -= clnow + 6000 - cllast; - else - timeoutval -= clnow - cllast; - if (timeoutval <= 0) /* Stop on timer being cleared */ + EMACS_SET_SECS_USECS (clnow, t.ti_sec, t.ti_hund * 10000L); + EMACS_SUB_TIME (cldiff, clnow, cllast); + + /* When seconds wrap around, we assume that no more than + 1 minute passed since last `check_timer'. */ + if (EMACS_TIME_NEG_P (cldiff)) + EMACS_SET_SECS (cldiff, EMACS_SECS (cldiff) + 60); + EMACS_SUB_TIME (*timeout, *timeout, cldiff); + + /* Stop when timeout value crosses zero. */ + if (EMACS_TIME_ZERO_OR_NEG_P (*timeout)) return 0; cllast = clnow; }