1 /* Chunk handling: Flexible arrays
2 ** ===============================
4 ** This module implements a flexible array. It is a general utility module.
5 ** A chunk is a structure which may be extended. These routines create
6 ** and append data to chnuks, automatically reallocating them as necessary.
12 int size; /* In bytes */
13 int growby; /* Allocation unit in bytes */
14 int allocated; /* Current size of *data */
15 char * data; /* Pointer to malloced area or 0 */
20 #define HTChunkClear HTChClea
21 #define HTChunkPutc HTChPutc
22 #define HTChunkPuts HTChPuts
23 #define HTChunkCreate HTChCrea
24 #define HTChunkTerminate HTChTerm
25 #define HTChunkEnsure HtChEnsu
33 ** growby The number of bytes to allocate at a time
34 ** when the chunk is later extended. Arbitrary but
35 ** normally a trade-off time vs. memory
38 ** returns A chunk pointer to the new chunk,
40 extern HTChunk * HTChunkCreate PARAMS((int growby));
46 ** ch A valid chunk pointer made by HTChunkCreate()
49 ** *ch The size of the chunk is zero.
51 extern void HTChunkClear PARAMS((HTChunk * ch));
54 /* Ensure a chunk has a certain space in
57 ** ch A valid chunk pointer made by HTChunkCreate()
58 ** s The size required
61 ** *ch Has size at least s
63 extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
66 /* Append a character to a chunk
69 ** ch A valid chunk pointer made by HTChunkCreate()
70 ** c The character to be appended
72 ** *ch Is one character bigger
75 extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
77 /* Append a string to a chunk
80 ** ch A valid chunk pointer made by HTChunkCreate()
81 ** s Tpoints to a zero-terminated string to be appended
83 ** *ch Is bigger by strlen(s)
86 extern void HTChunkPuts PARAMS((HTChunk * ch, const char *s));
89 /* Append a zero character to a chunk
92 ** ch A valid chunk pointer made by HTChunkCreate()
94 ** *ch Is one character bigger
97 extern void HTChunkTerminate PARAMS((HTChunk * ch));