From: Alain Spineux Date: Fri, 4 Feb 2022 15:10:01 +0000 (+0100) Subject: edit_uint64_with_suffix() add option to remove the space before the suffix X-Git-Tag: Beta-15.0.0~599 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d537ada549c42bf6ba93cfc8da57a9b0ccb0e044;p=thirdparty%2Fbacula.git edit_uint64_with_suffix() add option to remove the space before the suffix - default is with_space=true that don't change the old behavior - the goal is to have used=7.205GB free=32.37GB unused=612.3MB <= with_space=false instead of used=7.205 GB free=32.37 GB unused=612.3 MB <= with_space=true --- diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index 6a79fcda9..d355c7579 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -105,8 +105,10 @@ char *edit_uint64_with_commas(uint64_t val, char *buf) * factor. The buf array inherits a 27 byte minimim length * requirement from edit_unit64_with_commas(), although the output * string is limited to eight characters. + * When with_space is true (default) a space is inserted between + * the value and the suffix */ -char *edit_uint64_with_suffix(uint64_t val, char *buf) +char *edit_uint64_with_suffix(uint64_t val, char *buf, bool with_space) { int commas = 0; char *c, mbuf[50]; @@ -128,7 +130,7 @@ char *edit_uint64_with_suffix(uint64_t val, char *buf) if (commas >= suffixes) commas = suffixes - 1; - bsnprintf(buf, 27, "%s %s", mbuf, suffix[commas]); + bsnprintf(buf, 27, with_space?"%s %s":"%s%s", mbuf, suffix[commas]); return buf; } diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index f6ae74462..e6bee961f 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -231,7 +231,7 @@ uint64_t str_to_uint64(char *str); int64_t str_to_int64(char *str); #define str_to_int32(str) ((int32_t)str_to_int64(str)) char * edit_uint64_with_commas (uint64_t val, char *buf); -char * edit_uint64_with_suffix (uint64_t val, char *buf); +char * edit_uint64_with_suffix (uint64_t val, char *buf, bool with_space=true); char * add_commas (char *val, char *buf); char * edit_uint64 (uint64_t val, char *buf); char * edit_int64 (int64_t val, char *buf);