mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-10-17 17:59:38 +00:00
![]() When displaying sizes of various sorts, tc commonly uses the function sprint_size() to format the size into a buffer as a human-readable string. This string is then displayed either using print_string(), or in some code even fprintf(). As a result, a typical sequence of code when formatting a size is something like the following: SPRINT_BUF(b); print_uint(PRINT_JSON, "foo", NULL, foo); print_string(PRINT_FP, NULL, "foo %s ", sprint_size(foo, b)); For a concept as broadly useful as size, it would be better to have a dedicated function in json_print. To that end, move sprint_size() from tc_util to json_print. Add helpers print_size() and print_color_size() that wrap arount sprint_size() and provide the JSON dispatch as appropriate. Since print_size() should be the preferred interface, convert vast majority of uses of sprint_size() to print_size(). Two notable exceptions are: - q_tbf, which does not show the size as such, but uses the string "$human_readable_size/$cell_size" even in JSON. There is simply no way to have print_size() emit the same text, because print_size() in JSON mode should of course just use the raw number, without human-readable frills. - q_cake, which relies on the existence of sprint_size() in its macro-based formatting helpers. There might be ways to convert this particular case, but given q_tbf simply cannot be converted, leave it as is. Signed-off-by: Petr Machata <me@pmachata.org> Signed-off-by: David Ahern <dsahern@gmail.com> |
||
---|---|---|
.. | ||
iptables | ||
libiptc | ||
netinet | ||
uapi | ||
bpf_api.h | ||
bpf_elf.h | ||
bpf_scm.h | ||
bpf_util.h | ||
cg_map.h | ||
color.h | ||
dlfcn.h | ||
ip6tables.h | ||
iptables.h | ||
json_print.h | ||
json_writer.h | ||
libgenl.h | ||
libnetlink.h | ||
list.h | ||
ll_map.h | ||
mnl_utils.h | ||
names.h | ||
namespace.h | ||
rt_names.h | ||
rtm_map.h | ||
utils.h | ||
version.h | ||
xt-internal.h | ||
xtables.h |