/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
*
* Copyright 2008 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*/
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2008 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in the file LICENSE in the
* top-level directory of the distribution or, alternatively, at
*/
/* Portions Copyright (C) 1999, 2000 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT
* THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
*/
/*
* UTF-8 Conversion Routines
*
* These routines convert between Wide Character and UTF-8,
* or between MultiByte and UTF-8 encodings.
*
* Both single character and string versions of the functions are provided.
* All functions return -1 if the character or string cannot be converted.
*/
#include <assert.h>
#include "k5-platform.h"
#include "k5-utf8.h"
#include "supp-int.h"
static ssize_t
const char *utf8str,
int little_endian)
{
/* If input ptr is NULL or empty... */
*ucs2str = 0;
return 0;
}
/* Examine next UTF-8 character. */
/* Get UTF-8 sequence length from 1st byte */
return -1;
/* First byte minus length tag */
for (i = 1; i < utflen; i++) {
/* Subsequent bytes must start with 10 */
return -1;
}
#ifdef K5_BE
#ifndef SWAP16
#endif
if (little_endian)
else
#endif
}
}
/* Add null terminator if there's room in the buffer. */
}
return ucs2len;
}
int
{
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}
int
{
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}
int
unsigned char **ucs2les,
{
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
if (ucs2leslen != NULL) {
}
return 0;
}
int
unsigned char **ucs2les,
{
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
if (ucs2leslen != NULL) {
}
return 0;
}
/*-----------------------------------------------------------------------------
Convert a wide char string to a UTF-8 string.
No more than 'count' bytes will be written to the output buffer.
Return the # of bytes written to the output buffer, excl null terminator.
ucs2len is -1 if the UCS-2 string is NUL terminated, otherwise it is the
length of the UCS-2 string in characters
*/
static ssize_t
{
int len = 0;
int n;
char *p = utf8str;
{
/* Get UTF-8 size of next wide char */
#ifdef K5_BE
if (little_endian)
#endif
if (n < 1)
return -1;
return -1; /* overflow */
len += n;
}
return len;
}
/* Do the actual conversion. */
n = 1; /* In case of empty ucs2str */
#ifdef K5_BE
if (little_endian)
#endif
n = krb5int_ucs2_to_utf8(ch, p);
if (n < 1)
break;
p += n;
count -= n; /* Space left in output buffer */
}
/* If not enough room for last character, pad remainder with null
so that return value = original count, indicating buffer full. */
if (n == 0) {
while (count--)
*p++ = 0;
}
/* Add a null terminator if there's room. */
else if (count)
*p = 0;
if (n == -1) /* Conversion encountered invalid wide char. */
return -1;
/* Return the number of bytes written to output buffer, excl null. */
return (p - utf8str);
}
int
char **utf8s,
{
if (len < 0) {
return EINVAL;
}
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}
int
char **utf8s,
{
if (len < 0)
return EINVAL;
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}
int
char **utf8s,
{
return ERANGE;
if (len < 0)
return EINVAL;
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}
int
char **utf8s,
{
if (ucs2leslen > SSIZE_MAX)
return ERANGE;
if (len < 0)
return EINVAL;
return ENOMEM;
}
if (len < 0) {
return EINVAL;
}
}
return 0;
}