| 997 | Pass LEN == 0 to get the current remainder. */ |
| 998 | |
| 999 | static off_t |
| 1000 | cache_round (int fd, off_t len) |
| 1001 | { |
| 1002 | static off_t i_pending, o_pending; |
| 1003 | off_t *pending = (fd == STDIN_FILENO ? &i_pending : &o_pending); |
| 1004 | |
| 1005 | if (len) |
| 1006 | { |
| 1007 | intmax_t c_pending; |
| 1008 | if (ckd_add (&c_pending, *pending, len)) |
| 1009 | c_pending = INTMAX_MAX; |
| 1010 | *pending = c_pending % IO_BUFSIZE; |
| 1011 | if (c_pending > *pending) |
| 1012 | len = c_pending - *pending; |
| 1013 | else |
| 1014 | len = 0; |
| 1015 | } |
| 1016 | else |
| 1017 | len = *pending; |
| 1018 | |
| 1019 | return len; |
| 1020 | } |
| 1021 | |
| 1022 | /* Discard the cache from the current offset of either |
| 1023 | STDIN_FILENO or STDOUT_FILENO. |