+
+/* Duplicate a null-terminated UTF-16LE string. */
+utf16lechar *
+utf16le_dup(const utf16lechar *ustr)
+{
+ const utf16lechar *p = ustr;
+ while (*p++)
+ ;
+ return memdup(ustr, (const u8 *)p - (const u8 *)ustr);
+}
+
+/* Return the length, in bytes, of a UTF-null terminated UTF-16 string,
+ * excluding the null terminator. */
+size_t
+utf16le_len_bytes(const utf16lechar *s)
+{
+ const utf16lechar *p = s;
+ while (*p)
+ p++;
+ return (p - s) * sizeof(utf16lechar);
+}
+
+/* Return the length, in UTF-16 coding units, of a UTF-null terminated UTF-16
+ * string, excluding the null terminator. */
+size_t
+utf16le_len_chars(const utf16lechar *s)
+{
+ return utf16le_len_bytes(s) / sizeof(utf16lechar);
+}