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

Function gz_load

freebsd/contrib/zstd/zlibWrapper/gzread.c:32–58  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

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