| @@ -135,9 +135,52 @@ static inline struct bstr bstr_getline(struct bstr str, struct bstr *rest) · 134 unmodified lines |
| 135 | // and will remove the trailing \n or \r\n sequence. | 135 | // and will remove the trailing \n or \r\n sequence. |
| 136 | struct bstr bstr_strip_linebreaks(struct bstr str); | 136 | struct bstr bstr_strip_linebreaks(struct bstr str); |
| 137 | | 137 | |
| | 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 | */ |
| 138 | void bstr_xappend(void *talloc_ctx, bstr *s, bstr append); | 151 | 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 | */ |
| 139 | int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) | 168 | int bstr_xappend_asprintf(void *talloc_ctx, bstr *s, const char *fmt, ...) |
| 140 | PRINTF_ATTRIBUTE(3, 4); | 169 | 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 | */ |
| 141 | int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va) | 184 | int bstr_xappend_vasprintf(void *talloc_ctx, bstr *s, const char *fmt, va_list va) |
| 142 | PRINTF_ATTRIBUTE(3, 0); | 185 | PRINTF_ATTRIBUTE(3, 0); |
| 143 | | 186 | |