]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mbsalign: fix for non-widechar
authorKarel Zak <kzak@redhat.com>
Fri, 3 Jun 2016 10:18:21 +0000 (12:18 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Jun 2016 10:18:21 +0000 (12:18 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/mbsalign.c

index f9babba11119a22b6e2ef76f84500ee7c03cacac..d316521f363f9341c69805fbc70bbb84c07c2cf3 100644 (file)
@@ -30,7 +30,6 @@
 #include "strutils.h"
 #include "widechar.h"
 
-#ifdef HAVE_WIDECHAR
 /* Replace non printable chars.
    Note \t and \n etc. are non printable.
    Return 1 if replacement made, 0 otherwise.  */
  */
 size_t mbs_safe_nwidth(const char *buf, size_t bufsz, size_t *sz)
 {
-       mbstate_t st;
        const char *p = buf, *last = buf;
        size_t width = 0, bytes = 0;
 
+#ifdef HAVE_WIDECHAR
+       mbstate_t st;
        memset(&st, 0, sizeof(st));
-
+#endif
        if (p && *p && bufsz)
                last = p + (bufsz - 1);
 
@@ -114,16 +114,17 @@ size_t mbs_safe_width(const char *s)
  */
 char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf)
 {
-       mbstate_t st;
        const char *p = s;
        char *r;
        size_t sz = s ? strlen(s) : 0;
 
+#ifdef HAVE_WIDECHAR
+       mbstate_t st;
+       memset(&st, 0, sizeof(st));
+#endif
        if (!sz || !buf)
                return NULL;
 
-       memset(&st, 0, sizeof(st));
-
        r = buf;
        *width = 0;
 
@@ -153,7 +154,7 @@ char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf)
                                        r += 4;
                                        *width += 4;
                                } else {
-                                       width++;
+                                       (*width)++;
                                        *r++ = *p;
                                }
                        } else if (!iswprint(wc)) {
@@ -178,13 +179,12 @@ char *mbs_safe_encode_to_buffer(const char *s, size_t *width, char *buf)
                        *width += 4;
                } else {
                        *r++ = *p++;
-                       *width++;
+                       (*width)++;
                }
 #endif
        }
 
        *r = '\0';
-
        return buf;
 }
 
@@ -211,6 +211,8 @@ char *mbs_safe_encode(const char *s, size_t *width)
        return mbs_safe_encode_to_buffer(s, width, buf);
 }
 
+#ifdef HAVE_WIDECHAR
+
 static bool
 wc_ensure_printable (wchar_t *wchars)
 {
@@ -275,7 +277,7 @@ rpl_wcswidth (const wchar_t *s, size_t n)
 
   return ret;
 }
-#endif
+#endif /* HAVE_WIDECHAR */
 
 /* Truncate multi-byte string to @width and returns number of
  * bytes of the new string @str, and in @width returns number