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

Function gz_error

freebsd/contrib/zlib/gzlib.c:582–621  ·  view source on GitHub ↗

Create an error message in allocated memory and set state->err and state->msg accordingly. Free any previous error message already there. Do not try to free or allocate space if the error is Z_MEM_ERROR (out of memory). Simply save the error message as a static string. If there is an allocation failure constructing the error message, then convert the error to out of memory. */

(state, err, msg)

Source from the content-addressed store, hash-verified

580 allocation failure constructing the error message, then convert the error to
581 out of memory. */
582void ZLIB_INTERNAL gz_error(state, err, msg)
583 gz_statep state;
584 int err;
585 const char *msg;
586{
587 /* free previously allocated message and clear */
588 if (state->msg != NULL) {
589 if (state->err != Z_MEM_ERROR)
590 free(state->msg);
591 state->msg = NULL;
592 }
593
594 /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */
595 if (err != Z_OK && err != Z_BUF_ERROR)
596 state->x.have = 0;
597
598 /* set error code, and if no message, then done */
599 state->err = err;
600 if (msg == NULL)
601 return;
602
603 /* for an out of memory error, return literal string when requested */
604 if (err == Z_MEM_ERROR)
605 return;
606
607 /* construct error message with path */
608 if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) ==
609 NULL) {
610 state->err = Z_MEM_ERROR;
611 return;
612 }
613#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
614 (void)snprintf(state->msg, strlen(state->path) + strlen(msg) + 3,
615 "%s%s%s", state->path, ": ", msg);
616#else
617 strcpy(state->msg, state->path);
618 strcat(state->msg, ": ");
619 strcat(state->msg, msg);
620#endif
621}
622
623#ifndef INT_MAX
624/* portably return maximum value for an int (when limits.h presumed not

Callers 15

gz_loadFunction · 0.70
gz_lookFunction · 0.70
gz_decompFunction · 0.70
gzreadFunction · 0.70
gzfreadFunction · 0.70
gzungetcFunction · 0.70
gzclose_rFunction · 0.70
gz_initFunction · 0.70
gz_compFunction · 0.70
gzwriteFunction · 0.70
gzfwriteFunction · 0.70
gzclose_wFunction · 0.70

Calls 4

mallocFunction · 0.85
snprintfFunction · 0.85
strcatFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected