MCPcopy Create free account
hub / github.com/MariaDB/server / gz_write

Function gz_write

zlib/gzwrite.c:188–252  ·  view source on GitHub ↗

Write len bytes from buf to file. Return the number of bytes written. If the returned value is less than len, then there was an error. If the error was a non-blocking stall, then the number of bytes consumed is returned. For any other error, 0 is returned. */

Source from the content-addressed store, hash-verified

186 was a non-blocking stall, then the number of bytes consumed is returned.
187 For any other error, 0 is returned. */
188local z_size_t gz_write(gz_statep state, voidpc buf, z_size_t len) {
189 z_size_t put = len;
190 int ret;
191
192 /* if len is zero, avoid unnecessary operations */
193 if (len == 0)
194 return 0;
195
196 /* allocate memory if this is the first time through */
197 if (state->size == 0 && gz_init(state) == -1)
198 return 0;
199
200 /* check for seek request */
201 if (state->skip && gz_zero(state) == -1)
202 return 0;
203
204 /* for small len, copy to input buffer, otherwise compress directly */
205 if (len < state->size) {
206 /* copy to input buffer, compress when full */
207 for (;;) {
208 unsigned have, copy;
209
210 if (state->strm.avail_in == 0)
211 state->strm.next_in = state->in;
212 have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
213 state->in);
214 copy = state->size - have;
215 if (copy > len)
216 copy = (unsigned)len;
217 memcpy(state->in + have, buf, copy);
218 state->strm.avail_in += copy;
219 state->x.pos += copy;
220 buf = (const char *)buf + copy;
221 len -= copy;
222 if (len == 0)
223 break;
224 if (gz_comp(state, Z_NO_FLUSH) == -1)
225 return state->again ? put - len : 0;
226 }
227 }
228 else {
229 /* consume whatever's left in the input buffer */
230 if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
231 return 0;
232
233 /* directly compress user buffer to file */
234 state->strm.next_in = (z_const Bytef *)buf;
235 do {
236 unsigned n = (unsigned)-1;
237
238 if (n > len)
239 n = (unsigned)len;
240 state->strm.avail_in = n;
241 ret = gz_comp(state, Z_NO_FLUSH);
242 n -= state->strm.avail_in;
243 state->x.pos += n;
244 len -= n;
245 if (ret == -1)

Callers 4

gzwriteFunction · 0.85
gzfwriteFunction · 0.85
gzputcFunction · 0.85
gzputsFunction · 0.85

Calls 3

gz_initFunction · 0.85
gz_zeroFunction · 0.85
gz_compFunction · 0.85

Tested by

no test coverage detected