MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / gzvprintf

Function gzvprintf

extern/zlib/src/gzwrite.c:359–428  ·  view source on GitHub ↗

-- see zlib.h -- */

Source from the content-addressed store, hash-verified

357
358/* -- see zlib.h -- */
359int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) {
360 int len;
361 unsigned left;
362 char *next;
363 gz_statep state;
364 z_streamp strm;
365
366 /* get internal structure */
367 if (file == NULL)
368 return Z_STREAM_ERROR;
369 state = (gz_statep)file;
370 strm = &(state->strm);
371
372 /* check that we're writing and that there's no error */
373 if (state->mode != GZ_WRITE || state->err != Z_OK)
374 return Z_STREAM_ERROR;
375
376 /* make sure we have some buffer space */
377 if (state->size == 0 && gz_init(state) == -1)
378 return state->err;
379
380 /* check for seek request */
381 if (state->seek) {
382 state->seek = 0;
383 if (gz_zero(state, state->skip) == -1)
384 return state->err;
385 }
386
387 /* do the printf() into the input buffer, put length in len -- the input
388 buffer is double-sized just for this function, so there is guaranteed to
389 be state->size bytes available after the current contents */
390 if (strm->avail_in == 0)
391 strm->next_in = state->in;
392 next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
393 next[state->size - 1] = 0;
394#ifdef NO_vsnprintf
395# ifdef HAS_vsprintf_void
396 (void)vsprintf(next, format, va);
397 for (len = 0; len < state->size; len++)
398 if (next[len] == 0) break;
399# else
400 len = vsprintf(next, format, va);
401# endif
402#else
403# ifdef HAS_vsnprintf_void
404 (void)vsnprintf(next, state->size, format, va);
405 len = strlen(next);
406# else
407 len = vsnprintf(next, state->size, format, va);
408# endif
409#endif
410
411 /* check that printf() results fit in buffer */
412 if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
413 return 0;
414
415 /* update buffer and position, compress first half if past that */
416 strm->avail_in += (unsigned)len;

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