FAT | RFS | XFS | ZFS

utf16_utf8()

PROTOTYPE

#include <posix.h>

size_t utf16_utf8(const uint16_t *utf16, size_t utf16_len, uint8_t *utf8, size_t max_utf8_len);

DESCRIPTION

utf16_utf8() converts the UTF16 formatted string utf16, whose length is utf16_len, to the UTF8 format. utf8 points to an output buffer whose size is max_utf8_len.

If successful, utf16_utf8() returns the length of the converted string. Otherwise, it sets errno and returns -1.

ERROR CODES

EFAULT utf8 or utf16 equals NULL.
EINVAL max_utf8_len is zero or an invalid UTF16 char was found.
ENAMETOOLONG The output buffer is too small.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Convert from UTF16 encoding into UTF8 encoding.                   */
  /*-------------------------------------------------------------------*/
  len = utf16_utf8(long_name, long_len, (uint8_t *)name, LONG_FILENAME);