MCPcopy Create free account
hub / github.com/davisking/dlib / gz_error

Function gz_error

dlib/external/zlib/gzlib.c:579–618  ·  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

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

Callers 15

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

Calls

no outgoing calls

Tested by

no test coverage detected