/// (size_t)-1 is returned. Possible errors include invalid,
/// partial, or non-printable multibyte character in str.
+#define tuklib_mbstr_width_mem TUKLIB_SYMBOL(tuklib_mbstr_width_mem)
+extern size_t tuklib_mbstr_width_mem(const char *str, size_t len);
+///<
+/// \brief Get the number of columns needed for the multibyte buffer
+///
+/// This is like tuklib_mbstr_width() except that this takes the buffer
+/// length in bytes as the second argument. This allows using the function
+/// for buffers that aren't terminated with '\0'.
+///
+/// \param str String whose width is to be calculated.
+/// \param len Number of bytes to read from str.
+///
+/// \return On success, the number of columns needed to display the
+/// string e.g. in a terminal emulator is returned. On error,
+/// (size_t)-1 is returned. Possible errors include invalid,
+/// partial, or non-printable multibyte character in str.
+
#define tuklib_mbstr_fw TUKLIB_SYMBOL(tuklib_mbstr_fw)
extern int tuklib_mbstr_fw(const char *str, int columns_min);
///<
if (bytes != NULL)
*bytes = len;
+ return tuklib_mbstr_width_mem(str, len);
+}
+
+
+extern size_t
+tuklib_mbstr_width_mem(const char *str, size_t len)
+{
#ifndef HAVE_MBRTOWC
// In single-byte mode, the width of the string is the same
// as its length.
+ (void)str;
return len;
#else