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

Function gzvprintf

freebsd/contrib/zstd/zlibWrapper/gzwrite.c:385–455  ·  view source on GitHub ↗

-- see zlib.h -- */

Source from the content-addressed store, hash-verified

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