typedef void * strbuff_t; /* Creates and returns a pointer to a new string buffer of size 0 and * capacity 1. * * Returns NULL if out of memory. */ strbuff_t mk_strbuff(void); /* Returns a pointer to a newly allocated string whose contents is * a copy of the entire contents of the buffer. The client may modify * or free the returned string without affecting the string buffer. * * Returns NULL if out of memory or if sb is NULL. */ char *strbuff_to_string(strbuff_t sb); /* Returns the character at position given by index (0-based) of the * contents. * * Returns -1 if index is out of range or sb is NULL. */ int strbuff_getchar(strbuff_t sb, int index); /* Sets the character at position given by index (0-based) of the * contents to c and returns c. * * Returns -1 if index is out of range or sb is NULL. */ int strbuff_setchar(strbuff_t sb, int index, char c); /* Returns the current size of sb or -1 if sb is NULL. */ inline int strbuff_size(strbuff_t sb); /* Returns the current capacity of sb or -1 if sb is NULL. */ inline int strbuff_capacity(strbuff_t sb); /* Appends the character c to the contents of the buffer. * * Returns 0 on success, ENOMEM if there is insufficient memory, * EINVAL if sb is NULL. */ int strbuff_append(strbuff_t sb, char c); /* Appends the contents of the NUL-terminated string s (excluding the * terminating NUL character) to the contents of sb. Subsequent * modifications to the contents of the string pointed to by s have * no effect on the contents of the string buffer, i.e., the data are * copied out. Returns 0 on success, ENOMEM if there is insufficient * memory, EINVAL if either sb or s is NULL. */ int strbuff_append_str(strbuff_t sb, char *s); /* Truncates the string buffer to given size and returns 0. * Returns EINVAL if newsize is negative or larger than the current * size or if sb is NULL. */ int strbuff_truncate(strbuff_t sb, int newsize); /* Frees sb and all its associated space. */ void strbuff_destroy(strbuff_t sb);