2 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
19 char *count_to_number(uint32_t num
)
21 uint32_t ptr
= 0, size
= 0;
22 uint32_t written
= 0, i
;
23 int new_line_every_n_numbers
= 30;
26 for (i
=0; i
< num
; ++i
) {
27 size
+= snprintf(NULL
, 0, "%u ", i
);
28 if (i
> 0 && i
% new_line_every_n_numbers
== 0)
31 size
++; /* one for null char */
33 s
= calloc(size
, sizeof(char));
37 for (i
=0; i
< num
; ++i
) {
38 written
= sprintf(&s
[ptr
], "%u ", i
);
40 if (i
> 0 && i
% new_line_every_n_numbers
== 0) {
41 sprintf(&s
[ptr
], "\n");