#include #include #include #include #include static uint8_t zbuf[0x1000]; static uint8_t buf[0x1000 * 0x1000]; int main(int argc, char **argv) { size_t zbuf_len, buf_len; ssize_t n; z_stream stream; int error; n = read(STDIN_FILENO, zbuf, sizeof(zbuf)); if (n == -1) err(1, "read"); zbuf_len = n; stream.next_in = zbuf; stream.avail_in = zbuf_len; stream.next_out = buf; stream.avail_out = sizeof(buf); stream.zalloc = NULL; stream.zfree = NULL; error = inflateInit2(&stream, -15); if (error != Z_OK) errx(1, "inflateInit2: %s (%d)", zError(error), error); error = inflate(&stream, Z_FINISH); if (error != Z_STREAM_END) { inflateEnd(&stream); errx(1, "inflate: %s (%d)", zError(error), error); } buf_len = stream.total_out; n = write(STDOUT_FILENO, buf, buf_len); if (n == -1) err(1, "write"); if (n < 0) errx(1, "negative write: %zd", n); if ((size_t)n != buf_len) errx(1, "short write: %zd", n); return 0; }