summaryrefslogtreecommitdiffstats
path: root/lib/mbsalign.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
commit1272be04be0cb803eec87f602edb2e3e6f111aea (patch)
treebce17f6478cdd9f3c4ec3d751135dc42786d6a56 /lib/mbsalign.c
parentReleasing progress-linux version 2.39.3-11~progress7.99u1. (diff)
downloadutil-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.tar.xz
util-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.zip
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--lib/mbsalign.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/mbsalign.c b/lib/mbsalign.c
index 7b8f5a6..b4ab7be 100644
--- a/lib/mbsalign.c
+++ b/lib/mbsalign.c
@@ -310,12 +310,33 @@ char *mbs_invalid_encode_to_buffer(const char *s, size_t *width, char *buf)
return buf;
}
+/*
+ * Guess size
+ */
size_t mbs_safe_encode_size(size_t bytes)
{
return (bytes * 4) + 1;
}
/*
+ * Count size of the original string in bytes (count \x?? as one byte)
+ */
+size_t mbs_safe_decode_size(const char *p)
+{
+ size_t bytes = 0;
+
+ while (p && *p) {
+ if (*p == '\\' && *(p + 1) == 'x' &&
+ isxdigit(*(p + 2)) && isxdigit(*(p + 3)))
+ p += 4;
+ else
+ p++;
+ bytes++;
+ }
+ return bytes;
+}
+
+/*
* Returns allocated string where all control and non-printable chars are
* replaced with \x?? hex sequence.
*/