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 /include | |
parent | be99ebd656a6805fbe4d5de8136b5e5a19cf0b3c (diff) | |
download | nasm-7bb13eac112443cbeb27c3f613759e292274c385.tar.gz nasm-7bb13eac112443cbeb27c3f613759e292274c385.tar.xz nasm-7bb13eac112443cbeb27c3f613759e292274c385.zip |
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 'include')
-rw-r--r-- | include/nasmlib.h | 9 | ||||
-rw-r--r-- | include/strlist.h | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/include/nasmlib.h b/include/nasmlib.h index 239f60e1..66fbebcf 100644 --- a/include/nasmlib.h +++ b/include/nasmlib.h @@ -67,7 +67,8 @@ char * safe_alloc end_with_null nasm_strcatn(const char *one, ...); /* * 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 @@ -78,6 +79,12 @@ char * safe_alloc nasm_vasprintf(const char *fmt, va_list ap); void * safe_alloc printf_func(2, 3) nasm_axprintf(size_t extra, const char *fmt, ...); void * safe_alloc nasm_vaxprintf(size_t extra, const char *fmt, va_list ap); +extern size_t _nasm_aprintf_size; +static inline size_t nasm_aprintf_size(void) +{ + return _nasm_aprintf_size; +} + /* Assert the argument is a pointer without evaluating it */ #define nasm_assert_pointer(p) ((void)sizeof(*(p))) diff --git a/include/strlist.h b/include/strlist.h index fc9f38ef..b0e2919b 100644 --- a/include/strlist.h +++ b/include/strlist.h @@ -53,6 +53,7 @@ struct strlist { struct hash_table hash; struct strlist_entry *head, **tailp; size_t nstr, size; + bool uniq; }; static inline const struct strlist_entry * @@ -69,9 +70,13 @@ static inline size_t strlist_size(const struct strlist *list) return list ? list->size : 0; } -struct strlist safe_alloc *strlist_alloc(void); +struct strlist safe_alloc *strlist_alloc(bool uniq); void strlist_free(struct strlist *list); -const struct strlist_entry *strlist_add(struct strlist *list, const char *str); +const struct strlist_entry * never_null strlist_add(struct strlist *list, const char *str); +const struct strlist_entry * printf_func(2, 3) never_null + strlist_printf(struct strlist *list, const char *fmt, ...); +const struct strlist_entry * never_null + strlist_vprintf(struct strlist *list, const char *fmt, va_list ap); const struct strlist_entry * strlist_find(const struct strlist *list, const char *str); void * safe_alloc strlist_linearize(const struct strlist *list, char sep); |