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