From fa659fea9b0b71bf62de9dfec61160196c828da1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 12 May 2000 14:28:48 +0000 Subject: Added unicode_to_dos_char() function to address converting single UNICODE characters to one or more DOS codepage characters. Jeremy. (This used to be commit eefbfb5e16fcf40f335edc840a49f837f6b64111) --- source3/lib/util_unistr.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/lib/util_unistr.c') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 4a66adc0fd..c28ef44934 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -779,6 +779,28 @@ char *unicode_to_dos(char *dst, const smb_ucs2_t *src, size_t dst_len) return unicode_to_multibyte(dst, src, dst_len, ucs2_to_doscp); } +/******************************************************************* + Convert a single UNICODE character to DOS codepage. Returns the + number of bytes in the DOS codepage character. +********************************************************************/ + +size_t unicode_to_dos_char(char *dst, const smb_ucs2_t src) +{ + smb_ucs2_t val = ucs2_to_doscp[src]; + if(val < 256) { + *dst = (char)val; + return (size_t)1; + } + /* + * A 2 byte value is always written as + * high/low into the buffer stream. + */ + + dst[0] = (char)((val >> 8) & 0xff); + dst[1] = (char)(val & 0xff); + return (size_t)2; +} + /******************************************************************* Convert a DOS string to UNICODE format. Note that the 'dst' is in native byte order, not little endian. Always zero terminates. -- cgit