From: Theodore Ts'o Date: Tue, 30 May 2017 00:04:56 +0000 (-0400) Subject: badblocks: support languages which use multi-column wide characters X-Git-Tag: v1.43.5~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c574883dda4a44eeb4586fd7784373de3d8c030;p=thirdparty%2Fe2fsprogs.git badblocks: support languages which use multi-column wide characters CJK characters take up two columns for each character; teach badblocks to take this into account. Addresses-Debian-Bug: #860926 Signed-off-by: Theodore Ts'o Reported-by: "Mingye Wang (Arthur2e5)" --- diff --git a/misc/badblocks.c b/misc/badblocks.c index 0c4019a8c..e45939187 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -50,6 +50,9 @@ extern int optind; #include #include #include +#ifdef HAVE_MBSTOWCS +#include +#endif #include #include @@ -216,6 +219,9 @@ static void print_status(void) { struct timeval time_end; char diff_buf[32], line_buf[128]; +#ifdef HAVE_MBSTOWCS + wchar_t wline_buf[128]; +#endif int len; gettimeofday(&time_end, 0); @@ -229,7 +235,10 @@ static void print_status(void) num_write_errors, num_corruption_errors); #ifdef HAVE_MBSTOWCS - len = mbstowcs(NULL, line_buf, sizeof(line_buf)); + mbstowcs(wline_buf, line_buf, sizeof(line_buf)); + len = wcswidth(wline_buf, sizeof(line_buf)); + if (len < 0) + len = strlen(line_buf); /* Should never happen... */ #endif fputs(line_buf, stderr); memset(line_buf, '\b', len);