1205821Sedwin/*
213840Swosch * Copyright (C) 1999-2001 Free Software Foundation, Inc.
313840Swosch * This file is part of the GNU LIBICONV Library.
413840Swosch *
513840Swosch * The GNU LIBICONV Library is free software; you can redistribute it
613840Swosch * and/or modify it under the terms of the GNU Library General Public
713840Swosch * License as published by the Free Software Foundation; either version 2
813840Swosch * of the License, or (at your option) any later version.
913840Swosch *
1013840Swosch * The GNU LIBICONV Library is distributed in the hope that it will be
1113840Swosch * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
1213840Swosch * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1313840Swosch * Library General Public License for more details.
1413840Swosch *
1513840Swosch * You should have received a copy of the GNU Library General Public
1613840Swosch * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
1713840Swosch * If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
1813840Swosch * Fifth Floor, Boston, MA 02110-1301, USA.
1913840Swosch */
2013840Swosch
2113840Swosch/*
2213840Swosch * UCS-2LE = UCS-2 little endian
2313840Swosch */
2413840Swosch
2513840Swoschstatic int
2613840Swoschucs2le_mbtowc (conv_t conv, ucs4_t *pwc, const unsigned char *s, int n)
2713840Swosch{
2813840Swosch  if (n >= 2) {
2913840Swosch    if (s[1] >= 0xd8 && s[1] < 0xe0) {
3013840Swosch      return RET_ILSEQ;
3115714Sache    } else {
3213840Swosch      *pwc = s[0] + (s[1] << 8);
3313840Swosch      return 2;
3487235Smarkm    }
3513840Swosch  }
3687628Sdwmalone  return RET_TOOFEW(0);
3713840Swosch}
3887628Sdwmalone
3987235Smarkmstatic int
4087628Sdwmaloneucs2le_wctomb (conv_t conv, unsigned char *r, ucs4_t wc, int n)
4113840Swosch{
4287628Sdwmalone  if (wc < 0x10000 && !(wc >= 0xd800 && wc < 0xe000)) {
4387628Sdwmalone    if (n >= 2) {
4487628Sdwmalone      r[0] = (unsigned char) wc;
4513840Swosch      r[1] = (unsigned char) (wc >> 8);
4687235Smarkm      return 2;
4787235Smarkm    } else
4813840Swosch      return RET_TOOSMALL;
4913840Swosch  }
5013840Swosch  return RET_ILUNI;
5174583Sache}
5215714Sache