diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-13 22:48:14 -0800 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2018-12-13 22:48:14 -0800 |
commit | 7bb13eac112443cbeb27c3f613759e292274c385 (patch) | |
tree | e1c762bc63f3d3594cbf6746bdb836a00d9560bf /nasmlib/asprintf.c | |
parent | be99ebd656a6805fbe4d5de8136b5e5a19cf0b3c (diff) | |
download | nasm-7bb13eac112443cbeb27c3f613759e292274c385.tar.gz |
strlist: can be unique or not, add printf functions
Make it a selectable option at allocation time if a strlist should
contain only unique strings or not. If not, we omit the hash table and
strlist_find() will not do anything.
Add printf()-style functions to a strlist.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'nasmlib/asprintf.c')
-rw-r--r-- | nasmlib/asprintf.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/nasmlib/asprintf.c b/nasmlib/asprintf.c index 3e7b8ef9..be88d491 100644 --- a/nasmlib/asprintf.c +++ b/nasmlib/asprintf.c @@ -38,12 +38,16 @@ /* * nasm_[v]asprintf() are variants of the semi-standard [v]asprintf() * functions, except that we return the pointer instead of a count. - * Use %n if you need the count, too. + * The size of the string (including the final NUL!) is available + * by calling nasm_aprintf_size() afterwards. * * nasm_[v]axprintf() are similar, but allocates a user-defined amount * of storage before the string, and returns a pointer to the * allocated buffer. */ + +size_t _nasm_aprintf_size; + void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap) { char *strp; @@ -51,7 +55,7 @@ void *nasm_vaxprintf(size_t extra, const char *fmt, va_list ap) size_t bytes; va_copy(xap, ap); - bytes = vsnprintf(NULL, 0, fmt, xap) + 1; + _nasm_aprintf_size = bytes = vsnprintf(NULL, 0, fmt, xap) + 1; va_end(xap); strp = nasm_malloc(extra+bytes); vsnprintf(strp+extra, bytes, fmt, ap); |