]> err.no Git - util-linux/commitdiff
fdisk: correctly truncate and align translated partition names
authorPádraig Brady <P@draigBrady.com>
Tue, 9 Mar 2010 08:21:35 +0000 (08:21 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Mar 2010 14:29:01 +0000 (15:29 +0100)
* 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>
fdisk/Makefile.am
fdisk/fdisk.c

index 50f1dbe852fd9329c572b84a2ecd1f4235c1dd3e..862fa01620ef25ca6b3971a4cf918c91e751f90b 100644 (file)
@@ -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
index 09efd1cc28ec7a9ddcfaa125803c817e2daaf909..2a6d419f379ddeef46531077117a83f05c985766 100644 (file)
@@ -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;