mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-09-14 15:42:01 +00:00
deploy: 06a1bdf735
This commit is contained in:
32
vendor/gopl.io/ch13/bzip/bzip2.c
generated
vendored
Normal file
32
vendor/gopl.io/ch13/bzip/bzip2.c
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
// See page 362.
|
||||
//
|
||||
// The version of this program that appeared in the first and second
|
||||
// printings did not comply with the proposed rules for passing
|
||||
// pointers between Go and C, described here:
|
||||
// https://github.com/golang/proposal/blob/master/design/12416-cgo-pointers.md
|
||||
//
|
||||
// The version below, which appears in the third printing,
|
||||
// has been corrected. See bzip2.go for explanation.
|
||||
|
||||
//!+
|
||||
/* This file is gopl.io/ch13/bzip/bzip2.c, */
|
||||
/* a simple wrapper for libbzip2 suitable for cgo. */
|
||||
#include <bzlib.h>
|
||||
|
||||
int bz2compress(bz_stream *s, int action,
|
||||
char *in, unsigned *inlen, char *out, unsigned *outlen) {
|
||||
s->next_in = in;
|
||||
s->avail_in = *inlen;
|
||||
s->next_out = out;
|
||||
s->avail_out = *outlen;
|
||||
int r = BZ2_bzCompress(s, action);
|
||||
*inlen -= s->avail_in;
|
||||
*outlen -= s->avail_out;
|
||||
s->next_in = s->next_out = NULL;
|
||||
return r;
|
||||
}
|
||||
|
||||
//!-
|
Reference in New Issue
Block a user