summaryrefslogtreecommitdiffstats
path: root/lib/mbsalign.c
diff options
context:
space:
mode:
authorKarel Zak2016-06-03 12:18:21 +0200
committerKarel Zak2016-06-03 12:18:21 +0200
commit4a423fb963d4cd87e9e5c75c77e1ac5d1ea2417f (patch)
tree3fbb71437489526ee885df821c91065b9ec7e707 /lib/mbsalign.c
parentbuild-sys: fix comments in ul.m4 (diff)
downloadkernel-qcow2-util-linux-4a423fb963d4cd87e9e5c75c77e1ac5d1ea2417f.tar.gz
kernel-qcow2-util-linux-4a423fb963d4cd87e9e5c75c77e1ac5d1ea2417f.tar.xz
kernel-qcow2-util-linux-4a423fb963d4cd87e9e5c75c77e1ac5d1ea2417f.zip
lib/mbsalign: fix for non-widechar
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/mbsalign.c')
-rw-r--r--lib/mbsalign.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index f9babba11..d316521f3 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -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. */
@@ -44,12 +43,13 @@
*/
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