@@ -27,10 +27,53 @@ struct strbuilder {
2727 char * buffer_end ;
2828};
2929
30+ /**
31+ * Appends a character buffer.
32+ *
33+ * **Thread Safety: MT-Unsafe**
34+ * This function is not thread safe.
35+ *
36+ * **Async Signal Safety: AS-Unsafe heap**
37+ * This function is not safe to call from signal handlers due to the potential
38+ * use of memory management functions.
39+ *
40+ * **Async Cancel Safety: AC-Unsafe heap**
41+ * This function is not safe to call from threads that may be asynchronously
42+ * cancelled, due to the potential use of memory management functions.
43+ *
44+ * @param builder The strbuilder to append the characters to.
45+ *
46+ * @param buffer The character buffer to append to the string.
47+ * @param size The number of bytes to copy from the character buffer.
48+ *
49+ * @return The modified builder if no error is encountered. If an error is
50+ * encountered, then NULL is returned and an error code is set appropriately.
51+ */
3052struct strbuilder *
3153strbuilder_append_buffer ( struct strbuilder * builder ,
3254 const char * buffer , size_t size );
3355
56+ /**
57+ * Appends a char value.
58+ *
59+ * **Thread Safety: MT-Unsafe**
60+ * This function is not thread safe.
61+ *
62+ * **Async Signal Safety: AS-Unsafe heap**
63+ * This function is not safe to call from signal handlers due to the potential
64+ * use of memory management functions.
65+ *
66+ * **Async Cancel Safety: AC-Unsafe heap**
67+ * This function is not safe to call from threads that may be asynchronously
68+ * cancelled, due to the potential use of memory management functions.
69+ *
70+ * @param builder The strbuilder to append the characters to.
71+ *
72+ * @param c The character to append to the string.
73+ *
74+ * @return The modified builder if no error is encountered. If an error is
75+ * encountered, then NULL is returned and an error code is set appropriately.
76+ */
3477struct strbuilder *
3578strbuilder_append_char ( struct strbuilder * builder , char c );
3679
@@ -39,7 +82,7 @@ strbuilder_append_char( struct strbuilder *builder, char c );
3982 * zero. If it is negative, a negative sign is NOT included in the sequence of
4083 * appended characters.
4184 *
42- * **Thread Safety: MT-Safe **
85+ * **Thread Safety: MT-Unsafe **
4386 * This function is not thread safe.
4487 *
4588 * **Async Signal Safety: AS-Unsafe heap**
@@ -60,19 +103,109 @@ strbuilder_append_char( struct strbuilder *builder, char c );
60103struct strbuilder *
61104strbuilder_append_positive_int ( struct strbuilder * builder , int i );
62105
106+ /**
107+ * Appends a string.
108+ *
109+ * **Thread Safety: MT-Unsafe**
110+ * This function is not thread safe.
111+ *
112+ * **Async Signal Safety: AS-Unsafe heap**
113+ * This function is not safe to call from signal handlers due to the potential
114+ * use of memory management functions.
115+ *
116+ * **Async Cancel Safety: AC-Unsafe heap**
117+ * This function is not safe to call from threads that may be asynchronously
118+ * cancelled, due to the potential use of memory management functions.
119+ *
120+ * @param builder The strbuilder to append the characters to.
121+ *
122+ * @param str The NULL terminated string to append to the buffer.
123+ *
124+ * @return The modified builder if no error is encountered. If an error is
125+ * encountered, then NULL is returned and an error code is set appropriately.
126+ */
63127struct strbuilder *
64128strbuilder_append_string ( struct strbuilder * builder ,
65129 const char * str );
66130
131+ /**
132+ * Frees all memory associated with any string builders that have been created.
133+ * Releases memory associated with the cache and also any buffers within each
134+ * item in the cache (via the teardown function).
135+ *
136+ * **Thread Safety: MT-Unsafe**
137+ * This function is not thread safe.
138+ *
139+ * **Async Signal Safety: AS-Unsafe heap**
140+ * This function is not safe to call from signal handlers due to the potential
141+ * use of memory management functions.
142+ *
143+ * **Async Cancel Safety: AC-Unsafe heap**
144+ * This function is not safe to call from threads that may be asynchronously
145+ * cancelled, due to the potential use of memory management functions.
146+ */
67147void
68148strbuilder_free_all ( void );
69149
150+ /**
151+ * Gets the buffer output from the string builder, returning the length of the
152+ * buffer in the supplied length parameter.
153+ *
154+ * **Thread Safety: MT-Unsafe**
155+ * This function is not thread safe.
156+ *
157+ * **Async Signal Safety: AS-Unsafe**
158+ * Mostly AS-Safe but there is an opportunity for tearing which could result
159+ * in a nonsensical length.
160+ *
161+ * **Async Cancel Safety: AC-Safe**
162+ *
163+ * @param builder The strbuilder to append the characters to.
164+ * @param length A pointer to a variable that will be set to the length
165+ * of the string. Must not be NULL.
166+ *
167+ * @return A pointer to the complete buffer.
168+ */
70169char *
71170strbuilder_get_buffer ( struct strbuilder * builder , size_t * length );
72171
172+ /**
173+ * Destroys a specific string builder but does not free the associated memory.
174+ *
175+ * **Thread Safety: MT-Safe**
176+ * This function is thread safe.
177+ *
178+ * **Async Signal Safety: AS-Unsafe lock heap**
179+ * This function is not safe to call from signal handlers due to the use of a
180+ * non-reentrant lock and possibly memory management functions.
181+ *
182+ * **Async Cancel Safety: AC-Unsafe lock heap**
183+ * This function is not safe to call from threads that may be asynchronously
184+ * cancelled due to the use of a lock that could be left locked and the possible
185+ * use of memory management functions.
186+ *
187+ * @param builder The strbuilder to destroy.
188+ */
73189void
74190strbuilder_destroy ( const struct strbuilder * builder );
75191
192+ /**
193+ * Creates a string builder.
194+ *
195+ * **Thread Safety: MT-Unsafe**
196+ * This function is not thread safe.
197+ *
198+ * **Async Signal Safety: AS-Unsafe lock heap**
199+ * This function is not safe to call from signal handlers due to the use of a
200+ * non-reentrant lock and possibly memory management functions.
201+ *
202+ * **Async Cancel Safety: AC-Unsafe lock heap**
203+ * This function is not safe to call from threads that may be asynchronously
204+ * cancelled due to the use of a lock that could be left locked and the possible
205+ * use of memory management functions.
206+ *
207+ * @return The new string builder.
208+ */
76209struct strbuilder *
77210strbuilder_new ( void );
78211
@@ -89,6 +222,22 @@ strbuilder_new( void );
89222struct strbuilder *
90223strbuilder_reset ( struct strbuilder * builder );
91224
225+ /**
226+ * Converts a string builder to a NULL terminated string.
227+ *
228+ * **Thread Safety: MT-Unsafe**
229+ * This function is not thread safe.
230+ *
231+ * **Async Signal Safety: AS-Unsafe heap**
232+ * This function is not safe to call from signal handlers due to the potential
233+ * use of memory management functions.
234+ *
235+ * **Async Cancel Safety: AC-Unsafe heap**
236+ * This function is not safe to call from threads that may be asynchronously
237+ * cancelled, due to the potential use of memory management functions.
238+ *
239+ * @return The new string builder.
240+ */
92241char *
93242strbuilder_to_string ( const struct strbuilder * builder );
94243
0 commit comments