wherefileistheinputfilewithdeflatedata,nnnisthenumberofbytes ofinputtoskipbeforeinflating(e.g.toskipazliborgzipheader),and -wisusedtowritethedecompresseddatatostdout.-fisforcoverage testing,andcausespufftesttofailwithnotenoughoutputspace(-fdoes
a write like -w, so -w is not required). */
/* Return size times approximately the cube root of 2, keeping the result as 1, 3,or5timesapowerof2--theresultisalways>size,untiltheresult isthemaximumvalueofanunsignedlong,whereitremains.Thisisuseful
to keep reallocations less than ~33% over the actual data. */
local size_t bythirds(size_t size)
{ int n;
size_t m;
m = size; for (n = 0; m; n++)
m >>= 1; if (n < 3) return size + 1;
n -= 3;
m = size >> n;
m += m == 6 ? 2 : 1;
m <<= n; return m > size ? m : (size_t)(-1);
}
/* Read the input file *name, or stdin if name is NULL, into allocated memory. Reallocatetolargerbuffersuntiltheentirefileisreadin.Returna pointertotheallocateddata,orNULLiftherewasamemoryallocation failure.*lenisthenumberofbytesofdatareadfromtheinputfile(even ifload()returnsNULL).Iftheinputfilewasemptyorcouldnotbeopened
or read, *len is zero. */
local void *load(constchar *name, size_t *len)
{
size_t size; void *buf, *swap;
FILE *in;
*len = 0;
buf = malloc(size = 4096); if (buf == NULL) return NULL;
in = name == NULL ? stdin : fopen(name, "rb"); if (in != NULL) { for (;;) {
*len += fread((char *)buf + *len, 1, size - *len, in); if (*len < size) break;
size = bythirds(size); if (size == *len || (swap = realloc(buf, size)) == NULL) {
free(buf);
buf = NULL; break;
}
buf = swap;
}
fclose(in);
} return buf;
}
int main(int argc, char **argv)
{ int ret, put = 0, fail = 0; unsigned skip = 0; char *arg, *name = NULL; unsignedchar *source = NULL, *dest;
size_t len = 0; unsignedlong sourcelen, destlen;
/* process arguments */ while (arg = *++argv, --argc) if (arg[0] == '-') { if (arg[1] == 'w' && arg[2] == 0)
put = 1; elseif (arg[1] == 'f' && arg[2] == 0)
fail = 1, put = 1; elseif (arg[1] >= '0' && arg[1] <= '9')
skip = (unsigned)atoi(arg + 1); else {
fprintf(stderr, "invalid option %s\n", arg); return3;
}
} elseif (name != NULL) {
fprintf(stderr, "only one file name allowed\n"); return3;
} else
name = arg;
source = load(name, &len); if (source == NULL) {
fprintf(stderr, "memory allocation failure\n"); return4;
} if (len == 0) {
fprintf(stderr, "could not read %s, or it was empty\n",
name == NULL ? "<stdin>" : name);
free(source); return3;
} if (skip >= len) {
fprintf(stderr, "skip request of %d leaves no input\n", skip);
free(source); return3;
}
/* test inflate data with offset skip */
len -= skip;
sourcelen = (unsignedlong)len;
ret = puff(NIL, &destlen, source + skip, &sourcelen); if (ret)
fprintf(stderr, "puff() failed with return code %d\n", ret); else {
fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen); if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n",
len - sourcelen);
}
/* if requested, inflate again and write decompressed data to stdout */ if (put && ret == 0) { if (fail)
destlen >>= 1;
dest = malloc(destlen); if (dest == NULL) {
fprintf(stderr, "memory allocation failure\n");
free(source); return4;
}
puff(dest, &destlen, source + skip, &sourcelen);
SET_BINARY_MODE(stdout);
fwrite(dest, 1, destlen, stdout);
free(dest);
}
/* clean up */
free(source); return ret;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-17)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.