MCPcopy Create free account
hub / github.com/F-Stack/f-stack / gz_load

Function gz_load

freebsd/contrib/zlib/gzread.c:24–50  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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. */
24local 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

Callers 3

gz_availFunction · 0.70
gz_fetchFunction · 0.70
gz_readFunction · 0.70

Calls 2

gz_errorFunction · 0.70
readFunction · 0.50

Tested by

no test coverage detected