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