From b8d22034f1b393a48ce7af9e15d910bf0e29df0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Tue, 9 Mar 2010 08:21:35 +0000 Subject: [PATCH] fdisk: correctly truncate and align translated partition names MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * fdisk/Makefile.am: Depend on the mbsalign module. * fdisk/fdisk.c: Align using mbsalign rather than printf. [kzak@redhat.com: - use size_t for width to fix gcc warning] Reported-by: Makoto Kato Signed-off-by: Pádraig Brady Signed-off-by: Karel Zak --- fdisk/Makefile.am | 2 +- fdisk/fdisk.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am index 50f1dbe8..862fa016 100644 --- a/fdisk/Makefile.am +++ b/fdisk/Makefile.am @@ -3,7 +3,7 @@ include $(top_srcdir)/config/include-Makefile.am EXTRA_DIST = README.fdisk README.cfdisk sfdisk.examples partitiontype.c fdisk_common = i386_sys_types.c common.h gpt.c gpt.h \ - ../lib/blkdev.c ../lib/wholedisk.c + ../lib/blkdev.c ../lib/wholedisk.c ../lib/mbsalign.c if LINUX fdisk_common += ../lib/linux_version.c diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 09efd1cc..2a6d419f 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -25,6 +25,7 @@ #include "nls.h" #include "blkdev.h" #include "common.h" +#include "mbsalign.h" #include "fdisk.h" #include "wholedisk.h" @@ -568,9 +569,19 @@ void list_types(struct systypes *sys) i = done = 0; do { - printf("%c%2x %-15.15s", i ? ' ' : '\n', - sys[next].type, _(sys[next].name)); - next = last[i++] + done; + #define NAME_WIDTH 15 + char name[NAME_WIDTH * MB_LEN_MAX]; + size_t width = NAME_WIDTH; + + printf("%c%2x ", i ? ' ' : '\n', sys[next].type); + size_t ret = mbsalign(_(sys[next].name), name, sizeof(name), + &width, MBS_ALIGN_LEFT, 0); + if (ret == (size_t)-1 || ret >= sizeof(name)) + printf("%-15.15s", _(sys[next].name)); + else + fputs(name, stdout); + + next = last[i++] + done; if (i > 3 || next >= last[i]) { i = 0; next = ++done; -- 2.39.5