diff options
| author | Simon Glass <[email protected]> | 2025-05-02 08:46:04 -0600 |
|---|---|---|
| committer | Simon Glass <[email protected]> | 2025-05-30 09:49:31 +0100 |
| commit | 4f4b9477f4476cd86ffd4219111065d610c5237a (patch) | |
| tree | 3daecd9ea2c917e972afba0969d30d79f0bbd35d /include | |
| parent | d58cebbbc7617fbc45e604c883e8501a58d25e62 (diff) | |
abuf: Add a way to printf() into a buffer
It is useful to format a string into a buffer, with the sizing handled
automatically. Add a function for this.
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'include')
| -rw-r--r-- | include/abuf.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/abuf.h b/include/abuf.h index bbb3c51f334..7872e9c9b27 100644 --- a/include/abuf.h +++ b/include/abuf.h @@ -123,6 +123,27 @@ bool abuf_realloc_inc(struct abuf *abuf, size_t inc); bool abuf_copy(const struct abuf *old, struct abuf *new); /** + * abuf_printf() - Format a string and place it in an abuf + * + * @buf: The buffer to place the result into + * @fmt: The format string to use + * @...: Arguments for the format string + * Return: the number of characters writtenwhich would be + * generated for the given input, excluding the trailing null, + * as per ISO C99. + * + * The abuf is expanded as necessary to fit the formated string + * + * See the vsprintf() documentation for format string extensions over C99. + * + * Returns: number of characters written (excluding trailing nul) on success, + * -E2BIG if the size exceeds 4K, -ENOMEM if out of memory, -EFAULT if there is + * an internal bug in the vsnprintf() implementation + */ +int abuf_printf(struct abuf *buf, const char *fmt, ...) + __attribute__ ((format (__printf__, 2, 3))); + +/** * abuf_uninit_move() - Return the allocated contents and uninit the abuf * * This returns the abuf data to the caller, allocating it if necessary, so that |
