kernels/linux-2.4.0/fs/fat/dir.c
/*
 * Convert Unicode 16 to UTF8, translated Unicode, or ASCII.
 * If uni_xlate is enabled and we can't get a 1:1 conversion, use a
 * colon as an escape character since it is normally invalid on the vfat
 * filesystem. The following four characters are the hexadecimal digits
 * of Unicode value. This lets us do a full dump and restore of Unicode
 * filenames. We could get into some trouble with long Unicode names,
 * but ignore that right now.
 * Ahem... Stack smashing in ring 0 isn't fun. Fixed.
 */
Convert Unicode 16 to UTF8, translated Unicode, or ASCII.
If uni_xlate is enabled and we can't get a 1:1 conversion, use a
colon as an escape character since it is normally invalid on the vfat
filesystem. The following four characters are the hexadecimal digits
of Unicode value. This lets us do a full dump and restore of Unicode
filenames. We could get into some trouble with long Unicode names,
but ignore that right now.
Ahem... Stack smashing in ring 0 isn't fun. Fixed.
Convert Unicode 16 to UTF8 translated Unicode or ASCII . If uni_xlate is enabled and we can ' t get a 1 : 1 conversion use a colon as an escape character since it is normally invalid on the vfat filesystem . The following four characters are the hexadecimal digits of Unicode value . This lets us do a full dump and restore of Unicode filenames . We could get into some trouble with long Unicode names but ignore that right now . Ahem ... Stack smashing in ring 0 isn ' t fun . Fixed .
static int
uni16_to_x8(unsigned char *ascii, wchar_t *uni, int uni_xlate,
	    struct nls_table *nls)
{
	wchar_t *ip, ec;
	unsigned char *op, nc;
	int charlen;
	int k;
	ip = uni;
	op = ascii;
	while (*ip) {
		ec = *ip++;
		if ( (charlen = nls->uni2char(ec, op, 3)) > 0) {
			op += charlen;
		} else {
			if (uni_xlate == 1) {
				*op = ':';
				for (k = 4; k > 0; k--) {
					nc = ec & 0xF;
					op[k] = nc > 9	? nc + ('a' - 10)
							: nc + '0';
					ec >>= 4;
				}
				op += 5;
			} else {
				*op++ = '?';
			}
		}
		if (op>ascii+256) {
			op = ascii + 256;
			break;
		}
	}
	*op = 0;
	return (op - ascii);
}
static int uni16_to_x8 ( unsigned char * ascii , wchar_t * uni , int uni_xlate , struct nls_table * nls ) { wchar_t * ip , ec ; unsigned char * op , nc ; int charlen ; int k ; ip = uni ; op = ascii ; while ( * ip ) { ec = * ip ++ ; if ( ( charlen = nls -> uni2char ( ec , op , 3 ) ) > 0 ) { op += charlen ; } else { if ( uni_xlate == 1 ) { * op = ' ' ; for ( k = 4 ; k > 0 ; k -- ) { nc = ec & 0xF ; op [ k ] = nc > 9 ? nc + ( ' ' - 10 ) : nc + ' ' ; ec >>= 4 ; } op += 5 ; } else { * op ++ = ' ' ; } } if ( op > ascii + 256 ) { op = ascii + 256 ; break ; } } * op = 0 ; return ( op - ascii ) ; }
Convert Unicode 16 to UTF8, translated Unicode, or ASCII.
Convert Unicode 16 to UTF8 translated Unicode or ASCII .
/* We have some slack there, so it's OK */