diff --git a/c/zlib/zlib.go b/c/zlib/zlib.go index 1cd6111d..1cd65e94 100644 --- a/c/zlib/zlib.go +++ b/c/zlib/zlib.go @@ -76,17 +76,169 @@ const ( DEFLATED = 8 ) +// ----------------------------------------------------------------------------- + +/* +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); + +compressBound() returns an upper bound on the compressed size after +compress() or compress2() on sourceLen bytes. It would be used before a +compress() or compress2() call to allocate the destination buffer. +*/ //go:linkname CompressBound C.compressBound func CompressBound(sourceLen c.Ulong) c.Ulong +/* +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); + +Compresses the source buffer into the destination buffer. sourceLen is +the byte length of the source buffer. Upon entry, destLen is the total size +of the destination buffer, which must be at least the value returned by +compressBound(sourceLen). Upon exit, destLen is the actual size of the +compressed data. compress() is equivalent to compress2() with a level +parameter of Z_DEFAULT_COMPRESSION. + +compress returns Z_OK if success, Z_MEM_ERROR if there was not +enough memory, Z_BUF_ERROR if there was not enough room in the output +buffer. +*/ //go:linkname Compress C.compress func Compress(dest *byte, destLen *c.Ulong, source *byte, sourceLen c.Ulong) c.Int +/* +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, int level)); + +Compresses the source buffer into the destination buffer. The level +parameter has the same meaning as in deflateInit. sourceLen is the byte +length of the source buffer. Upon entry, destLen is the total size of the +destination buffer, which must be at least the value returned by +compressBound(sourceLen). Upon exit, destLen is the actual size of the +compressed data. + +compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough +memory, Z_BUF_ERROR if there was not enough room in the output buffer, +Z_STREAM_ERROR if the level parameter is invalid. +*/ //go:linkname Compress2 C.compress2 func Compress2(dest *byte, destLen *c.Ulong, source *byte, sourceLen c.Ulong, level c.Int) c.Int +/* +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); + +Decompresses the source buffer into the destination buffer. sourceLen is +the byte length of the source buffer. Upon entry, destLen is the total size +of the destination buffer, which must be large enough to hold the entire +uncompressed data. (The size of the uncompressed data must have been saved +previously by the compressor and transmitted to the decompressor by some +mechanism outside the scope of this compression library.) Upon exit, destLen +is the actual size of the uncompressed data. + +uncompress returns Z_OK if success, Z_MEM_ERROR if there was not +enough memory, Z_BUF_ERROR if there was not enough room in the output +buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In +the case where there is not enough room, uncompress() will fill the output +buffer with the uncompressed data up to that point. +*/ //go:linkname Uncompress C.uncompress func Uncompress(dest *byte, destLen *c.Ulong, source *byte, sourceLen c.Ulong) c.Int +/* +ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen)); + +Same as uncompress, except that sourceLen is a pointer, where the +length of the source is *sourceLen. On return, *sourceLen is the number of +source bytes consumed. +*/ //go:linkname Uncompress2 C.uncompress2 func Uncompress2(dest *byte, destLen *c.Ulong, source *byte, sourceLen *c.Ulong) c.Int + +// ----------------------------------------------------------------------------- + +/* +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); + +Update a running CRC-32 with the bytes buf[0..len-1] and return the +updated CRC-32. If buf is Z_NULL, this function returns the required +initial value for the crc. Pre- and post-conditioning (one's complement) is +performed within this function so it shouldn't be done by the application. + +Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ +//go:linkname Crc32 C.crc32 +func Crc32(crc c.Ulong, buf *byte, len c.Uint) c.Ulong + +/* +ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf, z_size_t len)); + +Same as crc32(), but with a size_t length. +*/ +//go:linkname Crc32Z C.crc32_z +func Crc32Z(crc c.Ulong, buf *byte, len uintptr) c.Ulong + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + +Combine two CRC-32 check values into one. For two sequences of bytes, +seq1 and seq2 with lengths len1 and len2, CRC-32 check values were +calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 +check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and +len2. +*/ +//go:linkname Crc32Combine C.crc32_combine +func Crc32Combine(crc1 c.Ulong, crc2 c.Ulong, len2 int64) c.Ulong + +/* +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); + +Update a running Adler-32 checksum with the bytes buf[0..len-1] and +return the updated checksum. If buf is Z_NULL, this function returns the +required initial value for the checksum. + +An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed +much faster. + +Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ +//go:linkname Adler32 C.adler32 +func Adler32(adler c.Ulong, buf *byte, len c.Uint) c.Ulong + +/* +ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, z_size_t len)); + +Same as adler32(), but with a size_t length. +*/ +//go:linkname Adler32Z C.adler32_z +func Adler32Z(adler c.Ulong, buf *byte, len uintptr) c.Ulong + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, z_off_t len2)); + +Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 +and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for +each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of +seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note +that the z_off_t type (like off_t) is a signed integer. If len2 is +negative, the result has no meaning or utility. +*/ +//go:linkname Adler32Combine C.adler32_combine +func Adler32Combine(adler1 c.Ulong, adler2 c.Ulong, len2 int64) c.Ulong + +// -----------------------------------------------------------------------------