MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / gzvprintf

Function gzvprintf

ZLib/gzwrite.c:310–370  ·  view source on GitHub ↗

-- see zlib.h -- */

Source from the content-addressed store, hash-verified

308
309/* -- see zlib.h -- */
310int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
311{
312 int size, len;
313 gz_statep state;
314 z_streamp strm;
315
316 /* get internal structure */
317 if (file == NULL)
318 return -1;
319 state = (gz_statep)file;
320 strm = &(state->strm);
321
322 /* check that we're writing and that there's no error */
323 if (state->mode != GZ_WRITE || state->err != Z_OK)
324 return 0;
325
326 /* make sure we have some buffer space */
327 if (state->size == 0 && gz_init(state) == -1)
328 return 0;
329
330 /* check for seek request */
331 if (state->seek) {
332 state->seek = 0;
333 if (gz_zero(state, state->skip) == -1)
334 return 0;
335 }
336
337 /* consume whatever's left in the input buffer */
338 if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
339 return 0;
340
341 /* do the printf() into the input buffer, put length in len */
342 size = (int)(state->size);
343 state->in[size - 1] = 0;
344#ifdef NO_vsnprintf
345# ifdef HAS_vsprintf_void
346 (void)vsprintf((char *)(state->in), format, va);
347 for (len = 0; len < size; len++)
348 if (state->in[len] == 0) break;
349# else
350 len = vsprintf((char *)(state->in), format, va);
351# endif
352#else
353# ifdef HAS_vsnprintf_void
354 (void)vsnprintf((char *)(state->in), size, format, va);
355 len = strlen((char *)(state->in));
356# else
357 len = vsnprintf((char *)(state->in), size, format, va);
358# endif
359#endif
360
361 /* check that printf() results fit in buffer */
362 if (len <= 0 || len >= (int)size || state->in[size - 1] != 0)
363 return 0;
364
365 /* update buffer and position, defer compression until needed */
366 strm->avail_in = (unsigned)len;
367 strm->next_in = state->in;

Callers 1

gzprintfFunction · 0.85

Calls 3

gz_initFunction · 0.85
gz_zeroFunction · 0.85
gz_compFunction · 0.85

Tested by

no test coverage detected