Use read() to load a buffer -- return -1 on error, otherwise 0. Read from state.state->fd, and update state.state->eof, state.state->err, and state.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. */
(state, buf, len, have)
| 30 | This function needs to loop on read(), since read() is not guaranteed to |
| 31 | read the number of bytes requested, depending on the type of descriptor. */ |
| 32 | local int gz_load(state, buf, len, have) |
| 33 | gz_statep state; |
| 34 | unsigned char *buf; |
| 35 | unsigned len; |
| 36 | unsigned *have; |
| 37 | { |
| 38 | ssize_t ret; |
| 39 | unsigned get, max = ((unsigned)-1 >> 2) + 1; |
| 40 | |
| 41 | *have = 0; |
| 42 | do { |
| 43 | get = len - *have; |
| 44 | if (get > max) |
| 45 | get = max; |
| 46 | ret = read(state.state->fd, buf + *have, get); |
| 47 | if (ret <= 0) |
| 48 | break; |
| 49 | *have += (unsigned)ret; |
| 50 | } while (*have < len); |
| 51 | if (ret < 0) { |
| 52 | gz_error(state, Z_ERRNO, zstrerror()); |
| 53 | return -1; |
| 54 | } |
| 55 | if (ret == 0) |
| 56 | state.state->eof = 1; |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* Load up input buffer and set eof flag if last data loaded -- return -1 on |
| 61 | error, 0 otherwise. Note that the eof flag is set when the end of the input |