diff --git a/NEWS b/NEWS index d8417d3c..a487278a 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ procps-ng-NEXT * free: Add committed line option merge #25 * free: Fix -h --si combined options issue #133, #223 * free: Fix first column justification issue #229, #204, #206, Debian #1001689 + * free: Better spacing for Chinese language issue #213 * library: renamed to libproc-2 and reset to 0:0:0 * library: add support for accessing smaps_rollup issue #112, #201 * library: add support for accessing autogroups diff --git a/free.c b/free.c index 4e989af4..94943e88 100644 --- a/free.c +++ b/free.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "config.h" #include "c.h" @@ -185,13 +186,18 @@ static void print_head_col(const char *str) { int len; int spaces = 9; + wchar_t wstr[BUFSIZ]; - len = mbstowcs(NULL, str, 0); + len = mbstowcs(wstr, str, BUFSIZ); if (len < 0) spaces = 9; - else if (len < HC_WIDTH) - spaces = HC_WIDTH - len; - else + else if (len < HC_WIDTH) { + int width; + if ( (width = wcswidth(wstr, 99)) > 0) + spaces = HC_WIDTH - width; + else + spaces = HC_WIDTH - len; + } else spaces = 0; printf("%s%.*s", str, spaces, " ");