/* Note that some windows versions actually send multiword UTF-16 characters instead of straight UCS-2. The linux nls routines however aren't able to deal with those characters properly. In the event that we get some of those characters, they won't be translated properly.  */
int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen, const struct nls_table *codepage, bool mapchar)
/* Note that some windows versions actually send multiword UTF-16 characters instead of straight UCS-2. The linux nls routines however aren't able to deal with those characters properly. In the event that we get some of those characters, they won't be translated properly.  */
int cifs_from_ucs2(char *to, const __le16 *from, int tolen, int fromlen, const struct nls_table *codepage, bool mapchar)
{
	int i, charlen, safelen;
	int outlen = 0;
	int nullsize = nls_nullsize(codepage);
	int fromwords = fromlen / 2;
	char tmp[NLS_MAX_CHARSET_SIZE];
	safelen = tolen - (NLS_MAX_CHARSET_SIZE + nullsize);
	for (i = 0; i < fromwords && from[i]; i++) {
		if (outlen >= safelen) {
			charlen = cifs_mapchar(tmp, from[i], codepage, mapchar);
			if ((outlen + charlen) > (tolen - nullsize))
				break;
		}
		charlen = cifs_mapchar(&to[outlen], from[i], codepage, mapchar);
		outlen += charlen;
	}
	for (i = 0; i < nullsize; i++)
		to[outlen++] = 0;
	return outlen;
}