diff options
author | Pádraig Brady | 2010-03-09 09:21:35 +0100 |
---|---|---|
committer | Karel Zak | 2010-03-16 15:29:01 +0100 |
commit | b8d22034f1b393a48ce7af9e15d910bf0e29df0b (patch) | |
tree | 9cce7f888f5f7e48dd6c879b2554d152db1b0904 /fdisk/fdisk.c | |
parent | lib: add #ifndef around min() max() macros (diff) | |
download | kernel-qcow2-util-linux-b8d22034f1b393a48ce7af9e15d910bf0e29df0b.tar.gz kernel-qcow2-util-linux-b8d22034f1b393a48ce7af9e15d910bf0e29df0b.tar.xz kernel-qcow2-util-linux-b8d22034f1b393a48ce7af9e15d910bf0e29df0b.zip |
fdisk: correctly truncate and align translated partition names
* 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 <m_kato@ga2.so-net.ne.jp>
Signed-off-by: Pádraig Brady <P@draigBrady.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisk/fdisk.c')
-rw-r--r-- | fdisk/fdisk.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 09efd1cc2..2a6d419f3 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; |