-- see zlib.h -- */
| 401 | |
| 402 | /* -- see zlib.h -- */ |
| 403 | int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) { |
| 404 | #if defined(NO_vsnprintf) && !defined(ZLIB_INSECURE) |
| 405 | #warning "vsnprintf() not available -- gzprintf() stub returns Z_STREAM_ERROR" |
| 406 | #warning "you can recompile with ZLIB_INSECURE defined to use vsprintf()" |
| 407 | /* prevent use of insecure vsprintf(), unless purposefully requested */ |
| 408 | (void)file, (void)format, (void)va; |
| 409 | return Z_STREAM_ERROR; |
| 410 | #else |
| 411 | int len, ret; |
| 412 | char *next; |
| 413 | gz_statep state; |
| 414 | z_streamp strm; |
| 415 | |
| 416 | /* get internal structure */ |
| 417 | if (file == NULL) |
| 418 | return Z_STREAM_ERROR; |
| 419 | state = (gz_statep)file; |
| 420 | strm = &(state->strm); |
| 421 | |
| 422 | /* check that we're writing and that there's no (serious) error */ |
| 423 | if (state->mode != GZ_WRITE || (state->err != Z_OK && !state->again)) |
| 424 | return Z_STREAM_ERROR; |
| 425 | gz_error(state, Z_OK, NULL); |
| 426 | |
| 427 | /* make sure we have some buffer space */ |
| 428 | if (state->size == 0 && gz_init(state) == -1) |
| 429 | return state->err; |
| 430 | |
| 431 | /* check for seek request */ |
| 432 | if (state->skip && gz_zero(state) == -1) |
| 433 | return state->err; |
| 434 | |
| 435 | /* do the printf() into the input buffer, put length in len -- the input |
| 436 | buffer is double-sized just for this function, so there should be |
| 437 | state->size bytes available after the current contents */ |
| 438 | ret = gz_vacate(state); |
| 439 | if (state->err) { |
| 440 | if (ret && state->again) { |
| 441 | /* There was a non-blocking stall on write, resulting in the part |
| 442 | of the second half of the output buffer being occupied. Return |
| 443 | a Z_BUF_ERROR to let the application know that this gzprintf() |
| 444 | needs to be retried. */ |
| 445 | gz_error(state, Z_BUF_ERROR, "stalled write on gzprintf"); |
| 446 | } |
| 447 | if (!state->again) |
| 448 | return state->err; |
| 449 | } |
| 450 | if (strm->avail_in == 0) |
| 451 | strm->next_in = state->in; |
| 452 | next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in); |
| 453 | next[state->size - 1] = 0; |
| 454 | #ifdef NO_vsnprintf |
| 455 | # ifdef HAS_vsprintf_void |
| 456 | (void)vsprintf(next, format, va); |
| 457 | for (len = 0; len < state->size; len++) |
| 458 | if (next[len] == 0) break; |
| 459 | # else |
| 460 | len = vsprintf(next, format, va); |