/*
* Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
* Original Code as defined in and that are subject to the Apple Public
* Source License Version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License."
*
* @APPLE_LICENSE_HEADER_END@
*/
/* CSTYLED */
/*
* @(#)charsets.c *
* (c) 2004 Apple Computer, Inc. All Rights Reserved
*
*
* charsets.c -- Routines converting between UTF-8, 16-bit
* little-endian Unicode, and various Windows
* code pages.
*
* MODIFICATION HISTORY:
* 28-Nov-2004 Guy Harris New today
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <iconv.h>
#include <langinfo.h>
#include <strings.h>
#include <libintl.h>
#include <sys/isa_defs.h>
#include "charsets.h"
/*
* On Solaris, we will need to do some rewriting to use our iconv
* routines for the conversions. For now, we're effectively
* stubbing out code, leaving the details of what happens on
* Darwin in case it's useful as a guide later.
*/
static unsigned
xtoi(char u)
{
if (isdigit(u))
return (u - '0');
else if (islower(u))
return (10 + u - 'a');
else if (isupper(u))
return (10 + u - 'A');
return (16);
}
/*
* Removes the "%" escape sequences from a URL component.
* See IETF RFC 2396.
*/
char *
{
char c, *s;
return (component);
for (s = component; (c = *s) != 0; s++) {
if (c != '%')
continue;
continue; /* ignore invalid escapes */
/*
* This was strcpy(s + 1, s + 3);
* But nowadays leftward overlapping copies are
* officially undefined in C. Ours seems to
* work or not depending upon alignment.
*/
}
return (component);
}
/* BEGIN CSTYLED */
#ifdef NOTPORTED
static CFStringEncoding
get_windows_encoding_equivalent( void )
{
/* important! use root ID so you can read the config file! */
switch ( index )
{
if (region) /* anything nonzero is not US */
else /* US region */
break;
break;
break;
break;
break;
break;
break;
break;
case kCFStringEncodingMacThai:
break;
break;
break;
break;
break;
break;
break;
break;
break;
default:
break;
}
return encoding;
}
#endif /* NOTPORTED */
/*
* XXX - NLS, or CF? We should probably use the same routine for all
* conversions.
*/
char *
{
#ifdef NOTPORTED
CFStringRef s;
char *result;
if (s == NULL) {
/* kCFStringEncodingMacRoman should always succeed */
if (s == NULL) {
smb_error("CFStringCreateWithCString for Windows code page failed on \"%s\" with kCFStringEncodingMacRoman - skipping",
-1, windows_string);
return NULL;
}
}
kCFStringEncodingUTF8) + 1;
CFRelease(s);
return NULL;
}
smb_error("CFStringGetCString for UTF-8 failed on \"%s\" - skipping",
-1, windows_string);
CFRelease(s);
return NULL;
}
CFRelease(s);
return result;
#else /* NOTPORTED */
return (strdup((char*)windows_string));
#endif /* NOTPORTED */
}
/*
* XXX - NLS, or CF? We should probably use the same routine for all
* conversions.
*/
char *
{
#ifdef NOTPORTED
CFStringRef s;
char *result;
if (s == NULL) {
return NULL;
}
get_windows_encoding_equivalent()) + 1;
CFRelease(s);
return NULL;
}
smb_error("CFStringGetCString for Windows code page failed on \"%s\" - skipping",
-1, utf8_string);
CFRelease(s);
return NULL;
}
CFRelease(s);
return result;
#else /* NOTPORTED */
return (strdup((char*)utf8_string));
#endif /* NOTPORTED */
}
/* END CSTYLED */
/*
* We replaced these routines for Solaris:
* convert_leunicode_to_utf8
* convert_unicode_to_utf8
* convert_utf8_to_leunicode
* with new code in: utf_str.c
*/