]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Thu, 11 May 2017 19:02:28 +0000 (22:02 +0300)
Conflicts:
src/lib/strfuncs.c

src/lib/strfuncs.c
src/lib/strfuncs.h

index c320b261b46aaff13d8e2d5df03937c27182196f..c30a189afc48d264b23bdff2e62fb49d9a10e72a 100644 (file)
@@ -733,12 +733,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(pos);
-
        buffer[--pos] = '\0';
        do {
                buffer[--pos] = (number % 10) + '0';
index 3e22409d9a024556e1047e19468e043415848513..428abcda707cfbf22bcbf6af1799f3bbcd30563f 100644 (file)
@@ -94,6 +94,10 @@ void p_strsplit_free(pool_t pool, char **arr);
 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;