Mercurial > emacs
comparison src/msdos.c @ 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 | ef10a42c21f4 |
children | 0eaecdc13142 |
comparison
equal
deleted
inserted
replaced
14278:3562c5f43780 | 14279:085bc709c11d |
---|---|
2459 } | 2459 } |
2460 | 2460 |
2461 last_time = *t; | 2461 last_time = *t; |
2462 } | 2462 } |
2463 | 2463 |
2464 #ifndef EMACS_TIME_ZERO_OR_NEG_P | |
2465 #define EMACS_TIME_ZERO_OR_NEG_P(time) \ | |
2466 ((long)(time).tv_sec < 0 \ | |
2467 || ((time).tv_sec == 0 \ | |
2468 && (long)(time).tv_usec <= 0)) | |
2469 #endif | |
2470 | |
2471 | |
2464 /* Only event queue is checked. */ | 2472 /* Only event queue is checked. */ |
2465 int | 2473 int |
2466 sys_select (nfds, rfds, wfds, efds, timeout) | 2474 sys_select (nfds, rfds, wfds, efds, timeout) |
2467 int nfds; | 2475 int nfds; |
2468 SELECT_TYPE *rfds, *wfds, *efds; | 2476 SELECT_TYPE *rfds, *wfds, *efds; |
2469 EMACS_TIME *timeout; | 2477 EMACS_TIME *timeout; |
2470 { | 2478 { |
2471 int check_input; | 2479 int check_input; |
2472 long timeoutval, clnow, cllast; | |
2473 struct time t; | 2480 struct time t; |
2474 | 2481 |
2475 check_input = 0; | 2482 check_input = 0; |
2476 if (rfds) | 2483 if (rfds) |
2477 { | 2484 { |
2494 check_timer (&t); /* check timer even if some input is pending */ | 2501 check_timer (&t); /* check timer even if some input is pending */ |
2495 while (!detect_input_pending ()); | 2502 while (!detect_input_pending ()); |
2496 } | 2503 } |
2497 else | 2504 else |
2498 { | 2505 { |
2499 timeoutval = EMACS_SECS (*timeout) * 100 + EMACS_USECS (*timeout) / 10000; | 2506 EMACS_TIME clnow, cllast, cldiff; |
2507 | |
2500 check_timer (&t); | 2508 check_timer (&t); |
2501 cllast = t.ti_sec * 100 + t.ti_hund; | 2509 EMACS_SET_SECS_USECS (cllast, t.ti_sec, t.ti_hund * 10000L); |
2502 | 2510 |
2503 while (!check_input || !detect_input_pending ()) | 2511 while (!check_input || !detect_input_pending ()) |
2504 { | 2512 { |
2505 check_timer (&t); | 2513 check_timer (&t); |
2506 clnow = t.ti_sec * 100 + t.ti_hund; | 2514 EMACS_SET_SECS_USECS (clnow, t.ti_sec, t.ti_hund * 10000L); |
2507 if (clnow < cllast) /* time wrap */ | 2515 EMACS_SUB_TIME (cldiff, clnow, cllast); |
2508 timeoutval -= clnow + 6000 - cllast; | 2516 |
2509 else | 2517 /* When seconds wrap around, we assume that no more than |
2510 timeoutval -= clnow - cllast; | 2518 1 minute passed since last `check_timer'. */ |
2511 if (timeoutval <= 0) /* Stop on timer being cleared */ | 2519 if (EMACS_TIME_NEG_P (cldiff)) |
2520 EMACS_SET_SECS (cldiff, EMACS_SECS (cldiff) + 60); | |
2521 EMACS_SUB_TIME (*timeout, *timeout, cldiff); | |
2522 | |
2523 /* Stop when timeout value crosses zero. */ | |
2524 if (EMACS_TIME_ZERO_OR_NEG_P (*timeout)) | |
2512 return 0; | 2525 return 0; |
2513 cllast = clnow; | 2526 cllast = clnow; |
2514 } | 2527 } |
2515 } | 2528 } |
2516 | 2529 |