Annotation of libwww/Library/src/HTChunk.html, revision 2.4
2.1 timbl 1: <PRE>
2: /* Chunk handling: Flexible arrays
3: ** ===============================
4: **
5: ** This module implements a flexible array. It is a general utility module.
6: ** A chunk is a structure which may be extended. These routines create
7: ** and append data to chnuks, automatically reallocating them as necessary.
8: **
9: */
10:
11:
12: typedef struct {
13: int size; /* In bytes */
14: int growby; /* Allocation unit in bytes */
15: int allocated; /* Current size of *data */
16: char * data; /* Pointer to malloced area or 0 */
17: } HTChunk;
18:
19:
20: #ifdef SHORT_NAMES
21: #define HTChunkClear HTChClea
22: #define HTChunkPutc HTChPutc
23: #define HTChunkPuts HTChPuts
24: #define HTChunkCreate HTChCrea
25: #define HTChunkTerminate HTChTerm
26: #define HTChunkEnsure HtChEnsu
27: #endif
28:
29:
30: /* Create new chunk
31: **
32: ** On entry,
33: **
34: ** growby The number of bytes to allocate at a time
35: ** when the chunk is later extended. Arbitrary but
36: ** normally a trade-off time vs. memory
37: **
38: ** On exit,
39: ** returns A chunk pointer to the new chunk,
40: */
41: extern HTChunk * HTChunkCreate PARAMS((int growby));
42:
43:
44: /* Free a chunk
45: **
46: ** On entry,
47: ** ch A valid chunk pointer made by HTChunkCreate()
48: **
49: ** On exit,
50: ** ch is invalid and may not be used.
51: */
52: extern void HTChunkFree PARAMS((HTChunk * ch));
53:
54:
55: /* Clear a chunk
56: **
57: ** On entry,
58: ** ch A valid chunk pointer made by HTChunkCreate()
59: **
60: ** On exit,
61: ** *ch The size of the chunk is zero.
62: */
63: extern void HTChunkClear PARAMS((HTChunk * ch));
64:
65:
66: /* Ensure a chunk has a certain space in
67: **
68: ** On entry,
69: ** ch A valid chunk pointer made by HTChunkCreate()
70: ** s The size required
71: **
72: ** On exit,
73: ** *ch Has size at least s
74: */
75: extern void HTChunkEnsure PARAMS((HTChunk * ch, int s));
76:
77:
78: /* Append a character to a chunk
79: **
80: ** On entry,
81: ** ch A valid chunk pointer made by HTChunkCreate()
82: ** c The character to be appended
83: ** On exit,
84: ** *ch Is one character bigger
85: */
86:
87: extern void HTChunkPutc PARAMS((HTChunk * ch, char c));
88:
89: /* Append a string to a chunk
90: **
91: ** On entry,
92: ** ch A valid chunk pointer made by HTChunkCreate()
93: ** s Tpoints to a zero-terminated string to be appended
94: ** On exit,
95: ** *ch Is bigger by strlen(s)
96: */
97:
98: extern void HTChunkPuts PARAMS((HTChunk * ch, const char *s));
99:
100:
101: /* Append a zero character to a chunk
102: **
103: ** On entry,
104: ** ch A valid chunk pointer made by HTChunkCreate()
105: ** On exit,
106: ** *ch Is one character bigger
107: */
108:
109: extern void HTChunkTerminate PARAMS((HTChunk * ch));
110: </PRE>
Webmaster