Mercurial > dovecot > core-2.2
changeset 22029:5bb79b92618a
lib: Add dec2str_buf()
Conflicts:
src/lib/strfuncs.c
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 02 May 2017 15:38:00 +0300 |
parents | b914c4c07644 |
children | ba2b3089a728 |
files | src/lib/strfuncs.c src/lib/strfuncs.h |
diffstat | 2 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/strfuncs.c Tue May 02 18:40:43 2017 +0300 +++ b/src/lib/strfuncs.c Tue May 02 15:38:00 2017 +0300 @@ -733,12 +733,14 @@ const char *dec2str(uintmax_t number) { - char *buffer; + return dec2str_buf(t_malloc_no0(MAX_INT_STRLEN), number); +} + +char *dec2str_buf(char buffer[STATIC_ARRAY MAX_INT_STRLEN], uintmax_t number) +{ int pos; pos = MAX_INT_STRLEN; - buffer = t_malloc(pos); - buffer[--pos] = '\0'; do { buffer[--pos] = (number % 10) + '0';
--- a/src/lib/strfuncs.h Tue May 02 18:40:43 2017 +0300 +++ b/src/lib/strfuncs.h Tue May 02 15:38:00 2017 +0300 @@ -94,6 +94,10 @@ const char **t_strsplit_tab(const char *data) ATTR_MALLOC ATTR_RETURNS_NONNULL; const char *dec2str(uintmax_t number); +/* Use the given buffer to write out the number. Returns pointer to the + written number in the buffer. Note that this isn't the same as the beginning + of the buffer. */ +char *dec2str_buf(char buffer[STATIC_ARRAY MAX_INT_STRLEN], uintmax_t number); /* Return length of NULL-terminated list string array */ unsigned int str_array_length(const char *const *arr) ATTR_PURE;