diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
commit | 8bb05ac73a5b448b339ce0bc8d396c82c459b47f (patch) | |
tree | 1fdda006866bca20d41cb206767ea5241e36852f /lib/mbsalign.c | |
parent | Adding debian version 2.39.3-11. (diff) | |
download | util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.tar.xz util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.zip |
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/mbsalign.c')
-rw-r--r-- | lib/mbsalign.c | 21 |
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. */ |