您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ BZ2_bzBuffToBuffDecompress函数代码示例

51自学网 2021-06-01 19:54:21
  C++
这篇教程C++ BZ2_bzBuffToBuffDecompress函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中BZ2_bzBuffToBuffDecompress函数的典型用法代码示例。如果您正苦于以下问题:C++ BZ2_bzBuffToBuffDecompress函数的具体用法?C++ BZ2_bzBuffToBuffDecompress怎么用?C++ BZ2_bzBuffToBuffDecompress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了BZ2_bzBuffToBuffDecompress函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: crm_ipcs_recv

xmlNode *crm_ipcs_recv(crm_client_t * c, void *data, size_t size, uint32_t * id, uint32_t * flags){    xmlNode *xml = NULL;    char *uncompressed = NULL;    char *text = ((char *)data) + sizeof(struct crm_ipc_response_header);    struct crm_ipc_response_header *header = data;    if (id) {        *id = ((struct qb_ipc_response_header *)data)->id;    }    if (flags) {        *flags = header->flags;    }    if (is_set(header->flags, crm_ipc_proxied)) {        /* mark this client as being the endpoint of a proxy connection.         * Proxy connections responses are sent on the event channel to avoid         * blocking the proxy daemon (crmd) */        c->flags |= crm_client_flag_ipc_proxied;    }    if(header->version > PCMK_IPC_VERSION) {        crm_err("Filtering incompatible v%d IPC message, we only support versions <= %d",                header->version, PCMK_IPC_VERSION);        return NULL;    }    if (header->size_compressed) {        int rc = 0;        unsigned int size_u = 1 + header->size_uncompressed;        uncompressed = calloc(1, size_u);        crm_trace("Decompressing message data %d bytes into %d bytes",                  header->size_compressed, size_u);        rc = BZ2_bzBuffToBuffDecompress(uncompressed, &size_u, text, header->size_compressed, 1, 0);        text = uncompressed;        if (rc != BZ_OK) {            crm_err("Decompression failed: %s (%d)", bz2_strerror(rc), rc);            free(uncompressed);            return NULL;        }    }    CRM_ASSERT(text[header->size_uncompressed - 1] == 0);    crm_trace("Received %.200s", text);    xml = string2xml(text);    free(uncompressed);    return xml;}
开发者ID:KevenChang,项目名称:pacemaker,代码行数:54,


示例2: bz2_decompress

/*ARGSUSED*/intbz2_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n){	ASSERT(d_len >= s_len);	if (BZ2_bzBuffToBuffDecompress(d_start, (unsigned int *)&d_len, s_start,			   s_len, 0, 0) != Z_OK)		return (-1);	return (0);}
开发者ID:ElCoyote27,项目名称:zfs-fuse,代码行数:12,


示例3: Read_compressed_record

static void Read_compressed_record(){  int bytes_to_read = 0;  int bytes_read = 0;  int error = 0;  int size_of_record = Control_word;  /* Byte-swap size flag so we can use it. */  bytes_to_read = ntohl( size_of_record );  P_debug( "Read_compressed_record: read %d", bytes_to_read );  /* Negative size indicates this is the last record of the volume. */  if( bytes_to_read < 0 )  {    P_debug( "Read_compressed_record: EOV" );    bytes_to_read = -bytes_to_read;    End_of_volume_flag = YES;  }  /* Read in compressed record according to expected size. If fewer     bytes are read than expected, that's a problem. */  bytes_read = Read_stdin( (char *)Read_buf, bytes_to_read );  if( bytes_read != bytes_to_read )  {    P_err( "Read_compressed_record: Bytes read (%d) less than (%d)",               bytes_read, bytes_to_read );    Print_stats( INSUFFICIENT_STDIN_BYTES_READ );  }  /* Decompress the compressed record and put in different buffer. */  Uncompressed_length = sizeof( Uncompressed_buf );  error = BZ2_bzBuffToBuffDecompress( Uncompressed_buf, &Uncompressed_length,                                      Read_buf, bytes_read,                                      0, 1 );  if( error )  {    P_err( "Read_compressed_record: Decompress error - %d", error );    Print_stats( DECOMPRESS_ERROR );  }  Uncompressed_bytes += Uncompressed_length;  Compressed_bytes += bytes_read;  Compression_ratio = (float) Uncompressed_bytes / (float) Compressed_bytes;  P_debug( "Radial size - Comp: %d Uncomp: %d Ratio: %f", Compressed_bytes, Uncompressed_bytes, Compression_ratio );}
开发者ID:likev,项目名称:CodeOrpgPub,代码行数:52,


示例4: throw

/** /brief uncompress the /ref datum_t and return the uncompressed result *  * @param datum		the data /ref datum_t to uncompress * @param max_len	the maximum length of the result * @return		a /ref datum_t containing the uncompressed data. the /ref datum_t * 			is null if the result is larger than /ref max_len. */datum_t	compress_bzip_t::uncompress(const datum_t &datum, size_t max_len)	throw(){	unsigned int	outlen	= max_len;	// allocate the output buffer	char	*outbuf = (char *)nipmem_alloca(max_len);	// try to uncompress the data and put them in the output buffer	int	err	= BZ2_bzBuffToBuffDecompress(outbuf, &outlen, (char *)datum.get_data()							, datum.get_len(), 1, 0);	// if the decompression failed, return a NULL datum_t()	if( err != BZ_OK )	return	datum_t();	// copy the decompressed data into a datum_t	return datum_t(outbuf, outlen);}
开发者ID:jeromeetienne,项目名称:neoip,代码行数:20,


示例5: BZ2_bzBuffToBuffDecompress

extern intbzip2_decode(const unsigned char *in_start, size_t in_len, unsigned char *out_start, size_t *pout_len, size_t out_max){	int	small      = 1;	int verbosity  = 0;	size_t destlen = n;	int x = BZ2_bzBuffToBuffDecompress( (char*)out_start, &destlen, (char*)in_start, in_len,                               small, verbosity);	*pout_len = destlen;	return x == BZ_OK;}
开发者ID:B4dT0bi,项目名称:JniChessEngines,代码行数:13,


示例6: while

void NetChannel::CopyNormalFragments(){	fragbuf_t *p, *n;	int totalSize;	if (!m_incomingbufs[FRAG_NORMAL_STREAM]) {		m_System->DPrintf("WARNING! NetChannel::CopyNormalFragments: called with no fragments readied./n");		return;	}	totalSize = 0;	p = m_incomingbufs[FRAG_NORMAL_STREAM];	while (p)	{		totalSize += p->size;		p = p->next;	}	NetPacket *packet = new NetPacket;	packet->seqnr = m_incoming_sequence;	packet->connectionless = false;	packet->time = m_System->GetTime();	packet->address.FromNetAddress(&m_remote_address);	packet->data.Resize(totalSize);	p = m_incomingbufs[FRAG_NORMAL_STREAM];	while (p)	{		n = p->next;		packet->data.WriteBuf(p->data, p->size);		Mem_Free(p);		p = n;	}	if (*(uint32 *)packet->data.GetData() == MAKEID('B', 'Z', '2', '/0'))	{		char uncompressed[65536];		unsigned int uncompressedSize = 65536;		BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char *)packet->data.GetData() + 4, totalSize - 4, 1, 0);		packet->data.Resize(uncompressedSize);		packet->data.WriteBuf(uncompressed, uncompressedSize);	}	packet->data.Reset();	m_incomingPackets.AddHead(packet);	m_incomingbufs[FRAG_NORMAL_STREAM] = nullptr;}
开发者ID:theAsmodai,项目名称:rehlds,代码行数:51,


示例7: uncompress_using_bzip2

static int uncompress_using_bzip2(void *in, unsigned long in_size,				  void *out, unsigned long out_max,				  unsigned long *out_size){	int ret;	unsigned int inout_size = out_max;	ret = BZ2_bzBuffToBuffDecompress(out, &inout_size, in, in_size,			CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);	if (out_size)		*out_size = inout_size;	return (ret != BZ_OK);}
开发者ID:AeroGirl,项目名称:u-boot-VAR-SOM-AM33-SDK7,代码行数:14,


示例8: convert_xml_child

static voidconvert_xml_child(HA_Message * msg, xmlNode * xml){    int orig = 0;    int rc = BZ_OK;    unsigned int len = 0;    char *buffer = NULL;    char *compressed = NULL;    const char *name = NULL;    name = (const char *)xml->name;    buffer = dump_xml_unformatted(xml);    orig = strlen(buffer);    if (orig < CRM_BZ2_THRESHOLD) {        ha_msg_add(msg, name, buffer);        goto done;    }    len = (orig * 1.1) + 600;   /* recomended size */    compressed = malloc(len);    rc = BZ2_bzBuffToBuffCompress(compressed, &len, buffer, orig, CRM_BZ2_BLOCKS, 0, CRM_BZ2_WORK);    if (rc != BZ_OK) {        crm_err("Compression failed: %d", rc);        free(compressed);        convert_xml_message_struct(msg, xml, name);        goto done;    }    free(buffer);    buffer = compressed;    crm_trace("Compression details: %d -> %d", orig, len);    ha_msg_addbin(msg, name, buffer, len);  done:    free(buffer);#  if 0    {        unsigned int used = orig;        char *uncompressed = NULL;        crm_debug("Trying to decompress %d bytes", len);        uncompressed = calloc(1, orig);        rc = BZ2_bzBuffToBuffDecompress(uncompressed, &used, compressed, len, 1, 0);        CRM_CHECK(rc == BZ_OK,;            );        CRM_CHECK(used == orig,;            );
开发者ID:bubble75,项目名称:pacemaker,代码行数:50,


示例9: BZ2_bzBuffToBuffDecompress

void BZ2Stream::decompress(uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len) {    int result = BZ2_bzBuffToBuffDecompress((char*) dest, &dest_len, (char*) source, source_len, 0, verbosity_);    switch (result) {    case BZ_OK:               break;    case BZ_CONFIG_ERROR:     throw BagException("library has been mis-compiled"); break;    case BZ_PARAM_ERROR:      throw BagException("dest is NULL or destLen is NULL or small != 0 && small != 1 or verbosity < 0 or verbosity > 4"); break;    case BZ_MEM_ERROR:        throw BagException("insufficient memory is available"); break;    case BZ_OUTBUFF_FULL:     throw BagException("size of the compressed data exceeds *destLen"); break;    case BZ_DATA_ERROR:       throw BagException("data integrity error was detected in the compressed data"); break;    case BZ_DATA_ERROR_MAGIC: throw BagException("compressed data doesn't begin with the right magic bytes"); break;    case BZ_UNEXPECTED_EOF:   throw BagException("compressed data ends unexpectedly"); break;    }}
开发者ID:OSUrobotics,项目名称:palantir_backup,代码行数:14,


示例10: runtime_error

void CIszImageStream::ReadBz2Block(uint32 compressedBlockSize){	m_baseStream->Read(m_readBuffer, compressedBlockSize);	//Force BZ2 header	m_readBuffer[0] = 'B';	m_readBuffer[1] = 'Z';	m_readBuffer[2] = 'h';	unsigned int destLength = m_header.blockSize;	if(BZ2_bzBuffToBuffDecompress(								  reinterpret_cast<char*>(m_cachedBlock), &destLength,								  reinterpret_cast<char*>(m_readBuffer), compressedBlockSize, 0, 0) != BZ_OK)	{		throw std::runtime_error("Error decompressing bz2 block.");	}}
开发者ID:bigianb,项目名称:Play-,代码行数:15,


示例11: ZIP_Decompress

static void ZIP_Decompress( DaoProcess *proc, DaoValue *p[], int N ){	DString *source = p[0]->xString.value;	DString *res = DaoProcess_PutChars( proc, "" );	unsigned int resLen;	/* TODO: get decompressed size from the compressed data? */	DString_Reserve( res, source->size );	resLen = res->bufSize;	while( resLen == res->bufSize ){		DString_Reserve( res, 2*resLen );		resLen = res->bufSize;		BZ2_bzBuffToBuffDecompress( res->chars, & resLen, source->chars, source->size, 0, 0 );	}	DString_Reset( res, resLen );}
开发者ID:DawidvC,项目名称:dao-modules,代码行数:16,


示例12: bz2decompress

EXPORT BOOL WINAPI bz2decompress(HSPEXINFO *hei){	char* dest = (char *)hei->HspFunc_prm_getv();	unsigned int destBufSize = hei->HspFunc_prm_geti();	char* source = (char *)hei->HspFunc_prm_getv();	unsigned int sourceLen = hei->HspFunc_prm_geti();	unsigned int* destLen = &destBufSize;	int ret;	if (*hei->er) return *hei->er;	ret = BZ2_bzBuffToBuffDecompress(dest, destLen, source, sourceLen, 0, 0);	if (ret == BZ_OK) *hei->strsize = *destLen;	return -abs(ret);	return 0;}
开发者ID:MihailJP,项目名称:HSPBZ2,代码行数:17,


示例13: uncompress_block_bzip2

int uncompress_block_bzip2(u64 compsize, u64 *origsize, u8 *origbuf, u64 origbufsize, u8 *compbuf){    unsigned int destsize=origbufsize;    int res;    switch ((res=BZ2_bzBuffToBuffDecompress((char*)origbuf, &destsize, (char*)compbuf, compsize, 0, 0)))    {    case BZ_OK:        *origsize=(u64)destsize;        return FSAERR_SUCCESS;    default:        errprintf("BZ2_bzBuffToBuffDecompress() failed, res=%d/n", res);        return FSAERR_UNKNOWN;    }    return FSAERR_UNKNOWN;}
开发者ID:philip-wernersbach,项目名称:fsarchiver-plus,代码行数:17,


示例14: crm_ipc_decompress

static intcrm_ipc_decompress(crm_ipc_t * client){    struct crm_ipc_response_header *header = (struct crm_ipc_response_header *)(void*)client->buffer;    if (header->size_compressed) {        int rc = 0;        unsigned int size_u = 1 + header->size_uncompressed;        /* never let buf size fall below our max size required for ipc reads. */        unsigned int new_buf_size = QB_MAX((hdr_offset + size_u), client->max_buf_size);        char *uncompressed = calloc(1, new_buf_size);        crm_trace("Decompressing message data %u bytes into %u bytes",                 header->size_compressed, size_u);        rc = BZ2_bzBuffToBuffDecompress(uncompressed + hdr_offset, &size_u,                                        client->buffer + hdr_offset, header->size_compressed, 1, 0);        if (rc != BZ_OK) {            crm_err("Decompression failed: %s (%d)", bz2_strerror(rc), rc);            free(uncompressed);            return -EILSEQ;        }        /*         * This assert no longer holds true.  For an identical msg, some clients may         * require compression, and others may not. If that same msg (event) is sent         * to multiple clients, it could result in some clients receiving a compressed         * msg even though compression was not explicitly required for them.         *         * CRM_ASSERT((header->size_uncompressed + hdr_offset) >= ipc_buffer_max);         */        CRM_ASSERT(size_u == header->size_uncompressed);        memcpy(uncompressed, client->buffer, hdr_offset);       /* Preserve the header */        header = (struct crm_ipc_response_header *)(void*)uncompressed;        free(client->buffer);        client->buf_size = new_buf_size;        client->buffer = uncompressed;    }    CRM_ASSERT(client->buffer[hdr_offset + header->size_uncompressed - 1] == 0);    return pcmk_ok;}
开发者ID:credativ,项目名称:pacemaker,代码行数:45,


示例15: bz2_decompress

int bz2_decompress(shared_ptr<FileBuffer> pbz, FileBuffer *p, vector<bz2_blk> * pblk, size_t start, size_t skip){	for (int i = start; i < pblk->size(); i += skip)	{		unsigned int len;		if (i) /*skip first dummy one*/		{			(*pblk)[i].error = BZ2_bzBuffToBuffDecompress((char*)p->data() + pblk->at(i).decompress_offset,				&len,				(char*)pbz->data() + pblk->at(i).start,				pblk->at(i).size,				0,				0);			(*pblk)[i].actual_size = len;		}	}	return 0;}
开发者ID:NXPmicro,项目名称:mfgtools,代码行数:18,


示例16: squash_bz2_decompress_buffer

static SquashStatussquash_bz2_decompress_buffer (SquashCodec* codec,                              uint8_t* uncompressed, size_t* uncompressed_length,                              const uint8_t* compressed, size_t compressed_length,                              SquashOptions* options) {  int small = (options != NULL) ? ((SquashBZ2Options*) options)->small : SQUASH_BZ2_DEFAULT_SMALL;  unsigned int uncompressed_length_ui = (unsigned int) *uncompressed_length;  int bz2_res;  bz2_res = BZ2_bzBuffToBuffDecompress ((char*) uncompressed, &uncompressed_length_ui,                                        (char*) compressed, (unsigned int) compressed_length,                                        small, 0);  if (bz2_res == BZ_OK) {    *uncompressed_length = uncompressed_length_ui;  }  return squash_bz2_status_to_squash_status (bz2_res);}
开发者ID:anthrotype,项目名称:squash,代码行数:18,


示例17: Netchan_CopyNormalFragments

/* <66786> ../engine/net_chan.c:1723 */qboolean Netchan_CopyNormalFragments(netchan_t *chan){	fragbuf_t *p, *n;	if (!chan->incomingready[FRAG_NORMAL_STREAM])		return FALSE;	if (!chan->incomingbufs[FRAG_NORMAL_STREAM])	{		Con_Printf("Netchan_CopyNormalFragments:  Called with no fragments readied/n");		chan->incomingready[FRAG_NORMAL_STREAM] = FALSE;		return FALSE;	}	p = chan->incomingbufs[FRAG_NORMAL_STREAM];	SZ_Clear(&net_message);	MSG_BeginReading();	while (p)	{		n = p->next;		SZ_Write(&net_message, p->frag_message.data, p->frag_message.cursize);		Mem_Free(p);		p = n;	}	if (*(uint32 *)net_message.data == MAKEID('B', 'Z', '2', '/0'))	{		char uncompressed[65536];		unsigned int uncompressedSize = 65536;		BZ2_bzBuffToBuffDecompress(uncompressed, &uncompressedSize, (char*)net_message.data + 4, net_message.cursize - 4, 1, 0);		Q_memcpy(net_message.data, uncompressed, uncompressedSize);		net_message.cursize = uncompressedSize;	}	chan->incomingbufs[FRAG_NORMAL_STREAM] = NULL;	chan->incomingready[FRAG_NORMAL_STREAM] = false;	return TRUE;}
开发者ID:omertelli,项目名称:rehlds,代码行数:44,


示例18: BZ2Decompress

bool BZ2Decompress(Buffer &dst, const void *src, size_t src_len){    const size_t initial_buffer_size = 1024 * 1024;    if (dst.empty()) { dst.resize(initial_buffer_size); }    int ret = 0;    for (;;) {        uint32_t dst_len = (uint32_t)dst.size();        BZ2_bzBuffToBuffDecompress(&dst[0], &dst_len, (char*)src, (uint32_t)src_len, 0, 0);        if (ret == BZ_OUTBUFF_FULL) {            dst.resize(dst.size() * 2);        }        else {            dst.resize(dst_len);            break;        }    }    return ret == BZ_OK;}
开发者ID:unity3d-jp,项目名称:FrameCapturer,代码行数:19,


示例19: squash_bz2_decompress_buffer

static SquashStatussquash_bz2_decompress_buffer (SquashCodec* codec,                              size_t* decompressed_length,                              uint8_t decompressed[SQUASH_ARRAY_PARAM(*decompressed_length)],                              size_t compressed_length,                              const uint8_t compressed[SQUASH_ARRAY_PARAM(compressed_length)],                              SquashOptions* options) {  int small = squash_codec_get_option_bool_index (codec, options, SQUASH_BZ2_OPT_SMALL) ? 1 : 0;  unsigned int decompressed_length_ui = (unsigned int) *decompressed_length;  int bz2_res;  bz2_res = BZ2_bzBuffToBuffDecompress ((char*) decompressed, &decompressed_length_ui,                                        (char*) compressed, (unsigned int) compressed_length,                                        small, 0);  if (bz2_res == BZ_OK) {    *decompressed_length = decompressed_length_ui;  }  return squash_bz2_status_to_squash_status (bz2_res);}
开发者ID:Bulat-Ziganshin,项目名称:squash,代码行数:20,


示例20: LLVMFuzzerTestOneInput

intLLVMFuzzerTestOneInput(const uint8_t *data, size_t size){    int r, small;    unsigned int nZ, nOut;    // See: https://github.com/google/bzip2-rpc/blob/master/unzcrash.c#L39    nOut = size*2;    char *outbuf = malloc(nOut);    small = size % 2;    r = BZ2_bzBuffToBuffDecompress(outbuf, &nOut, (char *)data, size,            small, /*verbosity=*/0);    if (r != BZ_OK) {#ifdef __DEBUG__        fprintf(stdout, "Decompression error: %d/n", r);#endif    }    free(outbuf);    return 0;}
开发者ID:google,项目名称:oss-fuzz,代码行数:21,


示例21: while

void Bzip2Compress::Decode(void){	direct = 1;	// set direction needed by parent [Get|Send]Chars()	// get buffer	char chunk[1024];	char *zbuf = (char *)calloc(1, 1024);	char *chunkbuf = zbuf;	int chunklen;	unsigned long zlen = 0;	while((chunklen = GetChars(chunk, 1023))) {		memcpy(chunkbuf, chunk, chunklen);		zlen += chunklen;		if (chunklen < 1023)			break;		else	zbuf = (char *)realloc(zbuf, zlen + 1024);		chunkbuf = zbuf + zlen;	}	//printf("Decoding complength{%ld} uncomp{%ld}/n", zlen, blen);	if (zlen) {		unsigned int blen = zlen*20;	// trust compression is less than 1000%		char *buf = new char[blen]; 		//printf("Doing decompress {%s}/n", zbuf);		slen = 0;		switch (BZ2_bzBuffToBuffDecompress(buf, &blen, zbuf, zlen, 0, 0)){			case BZ_OK: SendChars(buf, blen); slen = blen; break;			case BZ_MEM_ERROR: fprintf(stderr, "ERROR: not enough memory during decompression./n"); break;			case BZ_OUTBUFF_FULL: fprintf(stderr, "ERROR: not enough room in the out buffer during decompression./n"); break;			case BZ_DATA_ERROR: fprintf(stderr, "ERROR: corrupt data during decompression./n"); break;			default: fprintf(stderr, "ERROR: an unknown error occured during decompression./n"); break;		}		delete [] buf;	}	else {		fprintf(stderr, "ERROR: no buffer to decompress!/n");	}	//printf("Finished decoding/n");	free (zbuf);}
开发者ID:bluehavana,项目名称:sword,代码行数:40,


示例22: G_bz2_expand

intG_bz2_expand(unsigned char *src, int src_sz, unsigned char *dst,	      int dst_sz){    int err;    unsigned int nbytes;#ifndef HAVE_BZLIB_H    G_fatal_error(_("GRASS needs to be compiled with BZIP2 for BZIP2 compression"));    return -2;#else    /* Catch error condition */    if (src == NULL || dst == NULL)	return -2;    /* Don't do anything if either of these are true */    if (src_sz <= 0 || dst_sz <= 0)	return 0;    /* Do single pass decompression */    nbytes = dst_sz;    err = BZ2_bzBuffToBuffDecompress((char *)dst, &nbytes,  /* destination */                                     (char *)src, src_sz,   /* source */				     0,                     /* small */				     0);                    /* verbosity */    /* Number of bytes inflated to output stream is     * updated buffer size     */    if (!(err == BZ_OK)) {	return -1;    }    return nbytes;#endif}
开发者ID:rashadkm,项目名称:grass_cmake,代码行数:39,


示例23: strcpy

/* replacement for GZOPEN */static gzFile *mem_open(const char *name, const char *mode){	if (*mode == 'w') {		/* open for write (save) */		openmode = OM_WRITE;		strcpy(savename, name); /* remember name */		plainmembuf = Util_malloc(ALLOC_LEN);		plainmemoff = 0; /*HDR_LEN;*/		return (gzFile *) plainmembuf;	}	else {		/* open for read (read) */		FILE *f;		size_t len;		openmode = OM_READ;		unclen = ALLOC_LEN;		f = fopen(name, mode);		if (f == NULL)			return NULL;		plainmembuf = Util_malloc(ALLOC_LEN);		comprmembuf = Util_malloc(ALLOC_LEN);		len = fread(comprmembuf, 1, ALLOC_LEN, f);		fclose(f);		/* XXX: does DREAMCAST's fread return ((size_t) -1) ? */		if (len != 0		 && BZ2_bzBuffToBuffDecompress(plainmembuf, &unclen, comprmembuf + HDR_LEN, len - HDR_LEN, 1, 0) == BZ_OK) {#ifdef DEBUG			printf("decompress: old len %lu, new len %lu/n",				   (unsigned long) len - 1024, (unsigned long) unclen);#endif			free(comprmembuf);			plainmemoff = 0;			return (gzFile *) plainmembuf;		}		free(comprmembuf);		free(plainmembuf);		return NULL;	}}
开发者ID:HolgerGuenther,项目名称:Atari800Win-PLus,代码行数:40,


示例24: get_ais_data

char *get_ais_data(const AIS_Message * msg){    int rc = BZ_OK;    char *uncompressed = NULL;    unsigned int new_size = msg->size + 1;    if (msg->is_compressed == FALSE) {        crm_trace("Returning uncompressed message data");        uncompressed = strdup(msg->data);    } else {        crm_trace("Decompressing message data");        uncompressed = calloc(1, new_size);        rc = BZ2_bzBuffToBuffDecompress(uncompressed, &new_size, (char *)msg->data,                                        msg->compressed_size, 1, 0);        CRM_ASSERT(rc == BZ_OK);        CRM_ASSERT(new_size == msg->size);    }    return uncompressed;}
开发者ID:buaaspy,项目名称:pacemaker,代码行数:24,


示例25: bootm_load_os

static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress){	uint8_t comp = os.comp;	ulong load = os.load;	ulong blob_start = os.start;	ulong blob_end = os.end;	ulong image_start = os.image_start;	ulong image_len = os.image_len;	uint unc_len = CONFIG_SYS_BOOTM_LEN;	const char *type_name = genimg_get_type_name (os.type);	switch (comp) {	case IH_COMP_NONE:		if (load == blob_start) {			printf ("   XIP %s ... ", type_name);		} else {			printf ("   Loading %s ... ", type_name);			if (load != image_start) {				memmove_wd ((void *)load,						(void *)image_start, image_len, CHUNKSZ);			}		}		*load_end = load + image_len;		puts("OK/n");		break;	case IH_COMP_GZIP:		printf ("   Uncompressing %s ... ", type_name);		if (gunzip ((void *)load, unc_len,					(uchar *)image_start, &image_len) != 0) {			puts ("GUNZIP: uncompress, out-of-mem or overwrite error "				"- must RESET board to recover/n");			if (boot_progress)				show_boot_progress (-6);			return BOOTM_ERR_RESET;		}		*load_end = load + image_len;		break;#ifdef CONFIG_BZIP2	case IH_COMP_BZIP2:		printf ("   Uncompressing %s ... ", type_name);		/*		 * If we've got less than 4 MB of malloc() space,		 * use slower decompression algorithm which requires		 * at most 2300 KB of memory.		 */		int i = BZ2_bzBuffToBuffDecompress ((char*)load,					&unc_len, (char *)image_start, image_len,					CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);		if (i != BZ_OK) {			printf ("BUNZIP2: uncompress or overwrite error %d "				"- must RESET board to recover/n", i);			if (boot_progress)				show_boot_progress (-6);			return BOOTM_ERR_RESET;		}		*load_end = load + unc_len;		break;#endif /* CONFIG_BZIP2 */#ifdef CONFIG_LZMA	case IH_COMP_LZMA:		printf ("   Uncompressing %s ... ", type_name);		int ret = lzmaBuffToBuffDecompress(			(unsigned char *)load, &unc_len,			(unsigned char *)image_start, image_len);		if (ret != SZ_OK) {			printf ("LZMA: uncompress or overwrite error %d "				"- must RESET board to recover/n", ret);			show_boot_progress (-6);			return BOOTM_ERR_RESET;		}		*load_end = load + unc_len;		break;#endif /* CONFIG_LZMA */	default:		printf ("Unimplemented compression type %d/n", comp);		return BOOTM_ERR_UNIMPLEMENTED;	}	puts ("OK/n");	debug ("   kernel loaded at 0x%08lx, end = 0x%08lx/n", load, *load_end);	if (boot_progress)		show_boot_progress (7);	if ((load < blob_end) && (*load_end > blob_start)) {		debug ("images.os.start = 0x%lX, images.os.end = 0x%lx/n", blob_start, blob_end);		debug ("images.os.load = 0x%lx, load_end = 0x%lx/n", load, *load_end);		return BOOTM_ERR_OVERLAP;	}	return 0;}
开发者ID:KlemensWinter,项目名称:ecafe_uboot,代码行数:96,


示例26: convert_ha_field

static voidconvert_ha_field(xmlNode * parent, void *msg_v, int lpc){    int type = 0;    const char *name = NULL;    const char *value = NULL;    xmlNode *xml = NULL;    HA_Message *msg = msg_v;    int rc = BZ_OK;    size_t orig_len = 0;    unsigned int used = 0;    char *uncompressed = NULL;    char *compressed = NULL;    int size = orig_len * 10;    CRM_CHECK(parent != NULL, return);    CRM_CHECK(msg != NULL, return);    name = msg->names[lpc];    type = cl_get_type(msg, name);    switch (type) {        case FT_STRUCT:            convert_ha_message(parent, msg->values[lpc], name);            break;        case FT_COMPRESS:        case FT_UNCOMPRESS:            convert_ha_message(parent, cl_get_struct(msg, name), name);            break;        case FT_STRING:            value = msg->values[lpc];            CRM_CHECK(value != NULL, return);            crm_trace("Converting %s/%d/%s", name, type, value[0] == '<' ? "xml" : "field");            if (value[0] != '<') {                crm_xml_add(parent, name, value);                break;            }            /* unpack xml string */            xml = string2xml(value);            if (xml == NULL) {                crm_err("Conversion of field '%s' failed", name);                return;            }            add_node_nocopy(parent, NULL, xml);            break;        case FT_BINARY:            value = cl_get_binary(msg, name, &orig_len);            size = orig_len * 10 + 1;   /* +1 because an exact 10x compression factor happens occasionally */            if (orig_len < 3 || value[0] != 'B' || value[1] != 'Z' || value[2] != 'h') {                if (strstr(name, "uuid") == NULL) {                    crm_err("Skipping non-bzip binary field: %s", name);                }                return;            }            compressed = calloc(1, orig_len);            memcpy(compressed, value, orig_len);            crm_trace("Trying to decompress %d bytes", (int)orig_len);  retry:            uncompressed = realloc_safe(uncompressed, size);            memset(uncompressed, 0, size);            used = size - 1;    /* always leave room for a trailing '/0'                                 * BZ2_bzBuffToBuffDecompress won't say anything if                                 * the uncompressed data is exactly 'size' bytes                                 */            rc = BZ2_bzBuffToBuffDecompress(uncompressed, &used, compressed, orig_len, 1, 0);            if (rc == BZ_OUTBUFF_FULL) {                size = size * 2;                /* don't try to allocate more memory than we have */                if (size > 0) {                    goto retry;                }            }            if (rc != BZ_OK) {                crm_err("Decompression of %s (%d bytes) into %d failed: %d",                        name, (int)orig_len, size, rc);            } else if (used >= size) {                CRM_ASSERT(used < size);            } else {                CRM_LOG_ASSERT(uncompressed[used] == 0);                uncompressed[used] = 0;                xml = string2xml(uncompressed);            }            if (xml != NULL) {                add_node_copy(parent, xml);                free_xml(xml);            }//.........这里部分代码省略.........
开发者ID:bubble75,项目名称:pacemaker,代码行数:101,


示例27: decomptrk

/*-------------------------------------------------------------------*/int decomptrk(              BYTE *ibuf,         /* input buffer address            */              int ibuflen,        /* input buffer length             */              BYTE *obuf,         /* output buffer address           */              int obuflen,        /* output buffer length            */              int heads,          /* >=0 means CKD, else FBA         */              int trk,            /* relative track or block number  */              char *msg           /* addr of 80 byte msg buf or NULL */             )/* ibuf points at CKDDASD_TRKHDR header followed by track data       *//* ibuflen specifies length of TRKHDR and data                       *//* This code based on decompression logic in cdsk_valid_trk.         *//* Returns length of decompressed data or -1 on error.               */{#if defined( HAVE_LIBZ ) || defined( CCKD_BZIP2 )int             rc;                     /* Return code               */#endifunsigned int    bufl;                   /* Buffer length             */#ifdef CCKD_BZIP2unsigned int    ubufl;                  /* when size_t != unsigned int */#endif#if !defined( HAVE_LIBZ ) && !defined( CCKD_BZIP2 )    UNREFERENCED(heads);    UNREFERENCED(trk);    UNREFERENCED(msg);#endif    memset(obuf, 0, obuflen);  /* clear output buffer             */    /* Uncompress the track/block image */    switch (ibuf[0] & CCKD_COMPRESS_MASK) {    case CCKD_COMPRESS_NONE:        bufl = (ibuflen < obuflen) ? ibuflen : obuflen;        memcpy (obuf, ibuf, bufl);        break;#ifdef HAVE_LIBZ    case CCKD_COMPRESS_ZLIB:        memcpy (obuf, ibuf, CKDDASD_TRKHDR_SIZE);        bufl = obuflen - CKDDASD_TRKHDR_SIZE;        rc = uncompress(&obuf[CKDDASD_TRKHDR_SIZE],                         (void *)&bufl,                         &ibuf[CKDDASD_TRKHDR_SIZE],                         ibuflen);        if (rc != Z_OK) {            if (msg)                MSGBUF(msg, "%s %d uncompress error, rc=%d;"                         "%2.2x%2.2x%2.2x%2.2x%2.2x",                         heads >= 0 ? "trk" : "blk", trk, rc,                         ibuf[0], ibuf[1], ibuf[2], ibuf[3], ibuf[4]);            return -1;        }        bufl += CKDDASD_TRKHDR_SIZE;        break;#endif#ifdef CCKD_BZIP2    case CCKD_COMPRESS_BZIP2:        memcpy(obuf, ibuf, CKDDASD_TRKHDR_SIZE);        ubufl = obuflen - CKDDASD_TRKHDR_SIZE;        rc = BZ2_bzBuffToBuffDecompress (                 (char *)&obuf[CKDDASD_TRKHDR_SIZE],                 &ubufl,                 (char *)&ibuf[CKDDASD_TRKHDR_SIZE],                 ibuflen, 0, 0);        if (rc != BZ_OK) {            if (msg)                MSGBUF(msg, "%s %d decompress error, rc=%d;"                         "%2.2x%2.2x%2.2x%2.2x%2.2x",                         heads >= 0 ? "trk" : "blk", trk, rc,                         ibuf[0], ibuf[1], ibuf[2], ibuf[3], ibuf[4]);            return -1;        }        bufl=ubufl;        bufl += CKDDASD_TRKHDR_SIZE;        break;#endif    default:        return -1;    } /* switch (buf[0] & CCKD_COMPRESS_MASK) */    return bufl;}
开发者ID:opensourcemainframes,项目名称:hercules,代码行数:87,


示例28: crm_remote_parse_buffer

/*! * /internal * /brief handles the recv buffer and parsing out msgs. * /note new_data is owned by this function once it is passed in. */xmlNode *crm_remote_parse_buffer(crm_remote_t * remote){    xmlNode *xml = NULL;    struct crm_remote_header_v0 *header = crm_remote_header(remote);    if (remote->buffer == NULL || header == NULL) {        return NULL;    }    /* take ownership of the buffer */    remote->buffer_offset = 0;    /* Support compression on the receiving end now, in case we ever want to add it later */    if (header->payload_compressed) {        int rc = 0;        unsigned int size_u = 1 + header->payload_uncompressed;        char *uncompressed = calloc(1, header->payload_offset + size_u);        crm_trace("Decompressing message data %d bytes into %d bytes",                 header->payload_compressed, size_u);        rc = BZ2_bzBuffToBuffDecompress(uncompressed + header->payload_offset, &size_u,                                        remote->buffer + header->payload_offset,                                        header->payload_compressed, 1, 0);        if (rc != BZ_OK && header->version > REMOTE_MSG_VERSION) {            crm_warn("Couldn't decompress v%d message, we only understand v%d",                     header->version, REMOTE_MSG_VERSION);            free(uncompressed);            return NULL;        } else if (rc != BZ_OK) {            crm_err("Decompression failed: %s (%d)", bz2_strerror(rc), rc);            free(uncompressed);            return NULL;        }        CRM_ASSERT(size_u == header->payload_uncompressed);        memcpy(uncompressed, remote->buffer, header->payload_offset);       /* Preserve the header */        remote->buffer_size = header->payload_offset + size_u;        free(remote->buffer);        remote->buffer = uncompressed;        header = crm_remote_header(remote);    }    CRM_LOG_ASSERT(remote->buffer[sizeof(struct crm_remote_header_v0) + header->payload_uncompressed - 1] == 0);    xml = string2xml(remote->buffer + header->payload_offset);    if (xml == NULL && header->version > REMOTE_MSG_VERSION) {        crm_warn("Couldn't parse v%d message, we only understand v%d",                 header->version, REMOTE_MSG_VERSION);    } else if (xml == NULL) {        crm_err("Couldn't parse: '%.120s'", remote->buffer + header->payload_offset);    }    return xml;}
开发者ID:KevenChang,项目名称:pacemaker,代码行数:66,


示例29: main

int main ( int argc, char** argv ){   FILE* f;   int   r;   int   bit;   int   i;   if (argc != 2) {      fprintf ( stderr, "usage: unzcrash filename/n" );      return 1;   }   f = fopen ( argv[1], "r" );   if (!f) {      fprintf ( stderr, "unzcrash: can't open %s/n", argv[1] );      return 1;   }   nIn = fread ( inbuf, 1, M_BLOCK, f );   fprintf ( stderr, "%d bytes read/n", nIn );   nZ = M_BLOCK;   r = BZ2_bzBuffToBuffCompress (         zbuf, &nZ, inbuf, nIn, 9, 0, 30 );   assert (r == BZ_OK);   fprintf ( stderr, "%d after compression/n", nZ );   for (bit = 0; bit < nZ*8; bit++) {      fprintf ( stderr, "bit %d  ", bit );      flip_bit ( bit );      nOut = M_BLOCK_OUT;      r = BZ2_bzBuffToBuffDecompress (            outbuf, &nOut, zbuf, nZ, 0, 0 );      fprintf ( stderr, " %d  %s ", r, bzerrorstrings[-r] );      if (r != BZ_OK) {         fprintf ( stderr, "/n" );      } else {         if (nOut != nIn) {           fprintf(stderr, "nIn/nOut mismatch %d %d/n", nIn, nOut );           return 1;         } else {           for (i = 0; i < nOut; i++)             if (inbuf[i] != outbuf[i]) {                 fprintf(stderr, "mismatch at %d/n", i );                 return 1;            }           if (i == nOut) fprintf(stderr, "really ok!/n" );         }      }      flip_bit ( bit );   }#if 0   assert (nOut == nIn);   for (i = 0; i < nOut; i++) {     if (inbuf[i] != outbuf[i]) {        fprintf ( stderr, "difference at %d !/n", i );        return 1;     }   }#endif   fprintf ( stderr, "all ok/n" );   return 0;}
开发者ID:AscNHalf,项目名称:AscNHalf,代码行数:68,



注:本文中的BZ2_bzBuffToBuffDecompress函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ BZ2_bzDecompress函数代码示例
C++ BYTWJ函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。