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

Function gzvprintf

freebsd/contrib/zlib/gzwrite.c:382–452  ·  view source on GitHub ↗

-- see zlib.h -- */

Source from the content-addressed store, hash-verified

380
381/* -- see zlib.h -- */
382int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
383{
384 int len;
385 unsigned left;
386 char *next;
387 gz_statep state;
388 z_streamp strm;
389
390 /* get internal structure */
391 if (file == NULL)
392 return Z_STREAM_ERROR;
393 state = (gz_statep)file;
394 strm = &(state->strm);
395
396 /* check that we're writing and that there's no error */
397 if (state->mode != GZ_WRITE || state->err != Z_OK)
398 return Z_STREAM_ERROR;
399
400 /* make sure we have some buffer space */
401 if (state->size == 0 && gz_init(state) == -1)
402 return state->err;
403
404 /* check for seek request */
405 if (state->seek) {
406 state->seek = 0;
407 if (gz_zero(state, state->skip) == -1)
408 return state->err;
409 }
410
411 /* do the printf() into the input buffer, put length in len -- the input
412 buffer is double-sized just for this function, so there is guaranteed to
413 be state->size bytes available after the current contents */
414 if (strm->avail_in == 0)
415 strm->next_in = state->in;
416 next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
417 next[state->size - 1] = 0;
418#ifdef NO_vsnprintf
419# ifdef HAS_vsprintf_void
420 (void)vsprintf(next, format, va);
421 for (len = 0; len < state->size; len++)
422 if (next[len] == 0) break;
423# else
424 len = vsprintf(next, format, va);
425# endif
426#else
427# ifdef HAS_vsnprintf_void
428 (void)vsnprintf(next, state->size, format, va);
429 len = strlen(next);
430# else
431 len = vsnprintf(next, state->size, format, va);
432# endif
433#endif
434
435 /* check that printf() results fit in buffer */
436 if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
437 return 0;
438
439 /* update buffer and position, compress first half if past that */

Callers 1

gzprintfFunction · 0.70

Calls 6

vsprintfFunction · 0.85
vsnprintfFunction · 0.85
gz_initFunction · 0.70
gz_zeroFunction · 0.70
gz_compFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected