⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htchunk.h

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 H
字号:
/*    					W3C Sample Code Library libwww Chunk Class!  The Chunk Class!*//***	(c) COPYRIGHT MIT 1995.**	Please first read the full copyright statement in the file COPYRIGH.*//*The Chunk Class defines a way to automatically handle dynamic strings andother data types. You create a chunk with an initial size and it will thenautomatically grow to accommodate added data to the chunk. It is a generalutility module. It is guaranteed that the array is '\0' terminatedat all times (and hence is a valid C type string). The methodHTChunkTerminate can be used to explicitlyadd a terminating '\0' and then to include this character inthe chunk size. If left out, the terminating character is not consideredpart of the chunk.Note: The names without a "_" (made as a #define's) areonly provided for backwards compatibility and should not be used.This module is implemented by HTChunk.c, and it isa part of the  W3C Sample CodeLibrary.*/#ifndef HTCHUNK_H#define HTCHUNK_H/*.  Create new chunk.Create a new chunk and specify the number of bytes to allocate at a timewhen the chunk is later extended. Arbitrary but normally a trade-off timevs. memory*/typedef struct _HTChunk HTChunk;extern HTChunk * HTChunk_new (int growby);/*.  Free a chunk.Free a chunk created by HTChunk_newfrom memory*/extern void HTChunk_delete (HTChunk * ch);/*.  Clear a chunk.Keep the chunk in memory but clear all data kept inside. This can be usedif you know that you can reuse the allocated memory instead of allocatingnew memory.  This zeros out all the allocated data (even data past theindicated size) and sets the size of the chunk to 0.  If you have not usedany bytes past the indicated size, it is more efficient to truncate thechunk to 0 instead.*/extern void HTChunk_clear (HTChunk * ch);/*.  Ensure a Chunk has a Certain Amount of Free Space.Make sure that a chunk has enough memory allocated to grow by theindicated extra size. If this is not the case, then the chunk is expanded(in multiples of the chunk's "growby" size).  Nothing is done if thecurrent size plus the requested extra space fits within the chunk'scurrently allocated memory.*/extern void HTChunk_ensure (HTChunk * ch, int extra_size);/*.  Append a character to a chunk.Add the character and increment the size of the chunk by one character*/extern void HTChunk_putc (HTChunk * ch, char c);/*.  Append a string to a chunk.Add the string and increment the size of the chunk by the length of the string(without the trailing zero)*/extern void HTChunk_puts (HTChunk * ch, const char *str);/*.  Append a block to a chunk.Add the block and increment the size of the chunk by the len*/extern void HTChunk_putb (HTChunk * ch, const char *block, int len);/*.  Return Pointer to Data.This define converts a chunk to a normal char pointer so that it can be parsedto any ANSI C string function.*/extern char * HTChunk_data (HTChunk * ch);/*.  Return Current Size.Returns the current size of the chunk*/extern int HTChunk_size (HTChunk * ch);/*.  Setting the Size of a Chunk.If you want to cut off a piece of a chunk or extend it to make roomfor some direct buffer manipulation, then you can use one of thesefunctions.  Both of these calls set the size of the chunk to besize, but the truncate call only allows you to make thestring shorter. If the string is made shorter, the formerly-used bytesare cleared, so truncating a chunk to 0 is analogous to clearing it,but slightly more efficient.*/extern BOOL HTChunk_truncate (HTChunk * ch, int size);extern BOOL HTChunk_setSize (HTChunk * ch, int size);/*.  Zero Terminate a chunk.As a chunk often is a dynamic string, it needs to be terminated by a zeroin order to be used in C. However, by default any chunk isalways zero terminated, so the only purpose of this function is toincrement the size counter with one corresponding to the zero.*/extern void HTChunk_terminate (HTChunk * ch);/*.  CString Conversions.A Chunk may be built from an allocated string. The chunk assumes controlof the passed string, eliminating the need for additional allocations andstring copies.When you take control of the CString from a chunk, the chunk is destroyed.*/extern HTChunk * HTChunk_fromCString	(char * str, int grow);extern char * HTChunk_toCString		(HTChunk * ch);/*. Creating a Chunk from an allocated buffer.A Chunk may be built from an allocted buffer.  You must specify how muchmemory is allocated in the buffer (buflen) and what the size the newChunk should be (size).  All memory between size and buflen is zeroed.Note that is is legal to specify a size equal to the buflen if you don'texpect the Chunk to be null terminated.  The chunk takes control of thememory, and will free it when the Chunk is destroyed. Note that in orderto avoid conflicts, the buffer's memory should be allocated usinglibwww's dedicated functions.*/extern HTChunk * HTChunk_fromBuffer (char * buf, int buflen, int size, int grow);/*.  Old Interface Names.Don't use these in new applications*/#define HTChunkCreate(growby) HTChunk_new(growby)#define HTChunkFree(ch)       HTChunk_delete(ch)#define HTChunkClear(ch)      HTChunk_clear(ch)#define HTChunkEnsure(ch, s)  HTChunk_ensure((ch), (s))#define HTChunkPutc(ch, c)    HTChunk_putc((ch), (c))#define HTChunkPuts(ch, str)  HTChunk_puts((ch), (str))#define HTChunkTerminate(ch)  HTChunk_terminate(ch)#define HTChunkData(ch)       HTChunk_data(ch)#define HTChunkSize(ch)       HTChunk_size(ch)/**/#endif/*    @(#) $Id: HTChunk.html,v 2.39 2000/09/01 13:47:14 kahan Exp $*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -