xIUA provides some functions that are specifically designed for globalized code. One of these functions is int32_t xiua_strncpyEx(char *target, char *source, int32_t length);
This function operates much like strncpy except that it will only copy whole characters. It also always adds a null to the end of the target buffer. It will copy for the length of the source string or a whole number of characters for as many as can fit including the final null. This is especially useful since xIUA supports multiple data types and the application may not know it the null is 1, 2 or 4 bytes. Adding a null to the end of the buffer may also break the final character if it is a multi-byte character.
To make the function easier to use it returns the actual length of the data in bytes excluding the ending null. This data length can be used not only as the length of data to process but also as a value to be used to increment the source pointer or index to get the next segment of data from the source buffer.
To save on processing time xiua_strncpyEx only adds one null to the end of the data. It does not clear the remainder of the target buffer like strncpy does. If you need the remainder of the buffer cleared use memset to clear it first.
xiu4_strncpyEx is the UTF-32 version of the function. The lengths are converted by xiua_strncpyEx if the data is in UTF-32 format before calling xiu4_strncpyEx. To save code this function also operates as a strcpy by specifying a negative length.