History

bstr: add missing function docs

Kacper Michajłow committed 2 years ago

Commit 216abbc1 parent 3fd6c312 files · +43 −6Browse files

Unified · Split

2 files
  1. misc/bstr.c +0 −6
  2. misc/bstr.h +43 −0
misc/bstr.c+0−6
@@ -361,11 +361,6 @@ static void resize_append(void *talloc_ctx, bstr *s, size_t append_min) · 360 unmodified lines
361361 }
362362 }
363363
364−// Append the string, so that *s = *s + append. s->start is expected to be
365−// a talloc allocation (which can be realloced) or NULL.
366−// This function will always implicitly append a \0 after the new string for
367−// convenience.
368−// talloc_ctx will be used as parent context, if s->start is NULL.
369364 void bstr_xappend(void *talloc_ctx, bstr *s, bstr append)
370365 {
371366 if (!append.len)
@@ -385,7 +380,6 @@ int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) · 13 unmodified lines
385380 return ret;
386381 }
387382
388−// Exactly as bstr_xappend(), but with a formatted string.
389383 int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt,
390384 va_list ap)
391385 {
misc/bstr.h+43−0
@@ -135,9 +135,52 @@ static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest) · 134 unmodified lines
135135 // and will remove the trailing \n or \r\n sequence.
136136 struct bstr bstr_strip_linebreaks(struct bstr str);
137137
138+/**
139+ * @brief Append a string to the existing bstr.
140+ *
141+ * This function appends the content of the `append` bstr to the `s` bstr.
142+ * `s->start` is expected to be a talloc allocation (which can be resized) or NULL.
143+ * A null terminator ('\0') is always appended for convenience. If `s->start`
144+ * is NULL, the `talloc_ctx` will be used as the parent context to allocate
145+ * memory.
146+ *
147+ * @param talloc_ctx The parent talloc context.
148+ * @param s The destination bstr to which the `append` string is appended.
149+ * @param append The string to append to `s`.
150+ */
138151 void bstr_xappend(void *talloc_ctx, bstr *s, bstr append);
152+
153+/**
154+ * @brief Append a formatted string to the existing bstr.
155+ *
156+ * This function works like bstr_xappend() but appends a formatted string using
157+ * a format string and additional arguments. The formatted string is created
158+ * using vsnprintf. The function takes care of resizing the destination
159+ * buffer if necessary.
160+ *
161+ * @param talloc_ctx The parent talloc context.
162+ * @param s The destination bstr to which the formatted string is appended.
163+ * @param fmt The format string (same as in vsnprintf).
164+ * @param ... Additional arguments for the format string.
165+ * @return The number of characters added (excluding the null terminator)
166+ * or a negative value on error.
167+ */
139168 int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...)
140169 PRINTF_ATTRIBUTE(3, 4);
170+
171+/**
172+ * @brief Append a formatted string to the existing bstr using a va_list.
173+ *
174+ * This function is identical to bstr_xappend_asprintf() but takes a `va_list`
175+ * instead of a variable number of arguments.
176+ *
177+ * @param talloc_ctx The parent talloc context.
178+ * @param s The destination bstr to which the formatted string is appended.
179+ * @param fmt The format string (same as in printf).
180+ * @param ap The `va_list` containing the arguments for the format string.
181+ * @return The number of characters added (excluding the null terminator)
182+ * or a negative value on error.
183+ */
141184 int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va)
142185 PRINTF_ATTRIBUTE(3, 0);
143186

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t