1 /* Licensed under BSD-MIT - see LICENSE file for details */
2 #ifndef CCAN_ASPRINTF_H
3 #define CCAN_ASPRINTF_H
5 #include <ccan/compiler/compiler.h>
8 * afmt - allocate and populate a string with the given format.
9 * @fmt: printf-style format.
11 * This is a simplified asprintf interface. Returns NULL on error.
13 char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...);
20 * asprintf - printf to a dynamically-allocated string.
21 * @strp: pointer to the string to allocate.
22 * @fmt: printf-style format.
24 * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
25 * number of bytes printed into @strp.
28 * static char *greeting(const char *name)
31 * int len = asprintf(&str, "Hello %s", name);
37 int PRINTF_FMT(2, 3) asprintf(char **strp, const char *fmt, ...);
40 * vasprintf - vprintf to a dynamically-allocated string.
41 * @strp: pointer to the string to allocate.
42 * @fmt: printf-style format.
44 * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
45 * number of bytes printed into @strp.
47 int vasprintf(char **strp, const char *fmt, va_list ap);
50 #endif /* CCAN_ASPRINTF_H */