Use read() to load a buffer -- return -1 on error, otherwise 0. Read from state->fd, and update state->eof, state->err, and state->msg as appropriate. This function needs to loop on read(), since read() is not guaranteed to read the number of bytes requested, depending on the type of descriptor. */
| 10 | This function needs to loop on read(), since read() is not guaranteed to |
| 11 | read the number of bytes requested, depending on the type of descriptor. */ |
| 12 | local int gz_load(gz_statep state, unsigned char *buf, unsigned len, |
| 13 | unsigned *have) { |
| 14 | int ret; |
| 15 | unsigned get, max = ((unsigned)-1 >> 2) + 1; |
| 16 | |
| 17 | *have = 0; |
| 18 | do { |
| 19 | get = len - *have; |
| 20 | if (get > max) |
| 21 | get = max; |
| 22 | ret = read(state->fd, buf + *have, get); |
| 23 | if (ret <= 0) |
| 24 | break; |
| 25 | *have += (unsigned)ret; |
| 26 | } while (*have < len); |
| 27 | if (ret < 0) { |
| 28 | gz_error(state, Z_ERRNO, zstrerror()); |
| 29 | return -1; |
| 30 | } |
| 31 | if (ret == 0) |
| 32 | state->eof = 1; |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | /* Load up input buffer and set eof flag if last data loaded -- return -1 on |
| 37 | error, 0 otherwise. Note that the eof flag is set when the end of the input |