]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add dec2str_buf()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 2 May 2017 12:38:00 +0000 (15:38 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 9 May 2017 13:58:21 +0000 (16:58 +0300)
src/lib/strfuncs.c
src/lib/strfuncs.h

index 6c056ef61d4cfeeb2fe4aaaa1de32e90cc5a2de5..05c3c7f5e41a598bb1df186eb7e03828ae1d8f11 100644 (file)
@@ -725,12 +725,14 @@ const char **p_strarray_dup(pool_t pool, const char *const *arr)
 
 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_no0(pos);
-
        buffer[--pos] = '\0';
        do {
                buffer[--pos] = (number % 10) + '0';
index c5ab3a58ae4cb755ff39ce4ee2a5f4ff6784eb48..222976dcd4f209c571a99f65cebdd6c741cecdbf 100644 (file)
@@ -94,6 +94,10 @@ const char **t_strsplit_spaces(const char *data, const char *separators)
 void p_strsplit_free(pool_t pool, char **arr);
 
 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;