1 #ifndef CCAN_ASPRINTF_H
2 #define CCAN_ASPRINTF_H
4 #include <ccan/compiler/compiler.h>
7 * afmt - allocate and populate a string with the given format.
8 * @fmt: printf-style format.
10 * This is a simplified asprintf interface. Returns NULL on error.
12 char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...);
19 * asprintf - printf to a dynamically-allocated string.
20 * @strp: pointer to the string to allocate.
21 * @fmt: printf-style format.
23 * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
24 * number of bytes printed into @strp.
27 * static char *greeting(const char *name)
30 * int len = asprintf(&str, "Hello %s", name);
36 int PRINTF_FMT(2, 3) asprintf(char **strp, const char *fmt, ...);
39 * vasprintf - vprintf to a dynamically-allocated string.
40 * @strp: pointer to the string to allocate.
41 * @fmt: printf-style format.
43 * Returns -1 (and leaves @strp undefined) on an error. Otherwise returns
44 * number of bytes printed into @strp.
46 int vasprintf(char **strp, const char *fmt, va_list ap);
49 #endif /* CCAN_ASPRINTF_H */