OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [iconv/] [ces/] [ucs-2-internal.c] - Blame information for rev 868

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
2
 * Copyright (c) 2003-2004, Artem B. Bityuckiy
3
 * Copyright (c) 1999,2000, Konstantin Chuguev. All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
 * SUCH DAMAGE.
25
 */
26
#include "cesbi.h"
27
 
28
#if defined (ICONV_TO_UCS_CES_UCS_2_INTERNAL) \
29
 || defined (ICONV_FROM_UCS_CES_UCS_2_INTERNAL)
30
 
31
#include <_ansi.h>
32
#include <reent.h>
33
#include <stdlib.h>
34
#include <string.h>
35
#include <sys/types.h>
36
#include "../lib/local.h"
37
#include "../lib/ucsconv.h"
38
#include "../lib/endian.h"
39
 
40
/*
41
 * Internal 2-byte representation of UCS-2 codes without restrictions and
42
 * without BOM support.
43
 */
44
 
45
#if defined (ICONV_FROM_UCS_CES_UCS_2_INTERNAL)
46
static size_t
47
_DEFUN(ucs_2_internal_convert_from_ucs, (data, in, outbuf, outbytesleft),
48
                                        _VOID_PTR data         _AND
49
                                        register ucs4_t in     _AND
50
                                        unsigned char **outbuf _AND
51
                                        size_t *outbytesleft)
52
{
53
  if (in > 0x0000FFFF)
54
    return (size_t)ICONV_CES_INVALID_CHARACTER;
55
 
56
  if (*outbytesleft < sizeof (ucs2_t))
57
    return (size_t)ICONV_CES_NOSPACE;
58
 
59
  *((ucs2_t *)(*outbuf)) = (ucs2_t)in;
60
  *outbuf += sizeof (ucs2_t);
61
  *outbytesleft -= sizeof (ucs2_t);
62
 
63
  return sizeof (ucs2_t);
64
}
65
#endif /* ICONV_FROM_UCS_CES_UCS_2_INTERNAL */
66
 
67
#if defined (ICONV_TO_UCS_CES_UCS_2_INTERNAL)
68
static ucs4_t
69
_DEFUN(ucs_2_internal_convert_to_ucs, (data, inbuf, inbytesleft),
70
                                      _VOID_PTR data               _AND
71
                                      _CONST unsigned char **inbuf _AND
72
                                      size_t *inbytesleft)
73
{
74
  register ucs4_t res;
75
 
76
  if (*inbytesleft < sizeof (ucs2_t))
77
    return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
78
 
79
  res = (ucs4_t)*((ucs2_t *)(*inbuf));
80
 
81
  if (res > 0x0000FFFF)
82
    return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
83
 
84
  *inbuf += sizeof (ucs2_t);
85
  *inbytesleft -= sizeof (ucs2_t);
86
 
87
  return res;
88
}
89
#endif /* ICONV_TO_UCS_CES_UCS_2_INTERNAL */
90
 
91
static int
92
_DEFUN(ucs_2_internal_get_mb_cur_max, (data),
93
                                      _VOID_PTR data)
94
{
95
  return 2;
96
}
97
 
98
#if defined (ICONV_TO_UCS_CES_UCS_2_INTERNAL)
99
_CONST iconv_to_ucs_ces_handlers_t
100
_iconv_to_ucs_ces_handlers_ucs_2_internal =
101
{
102
  NULL,
103
  NULL,
104
  ucs_2_internal_get_mb_cur_max,
105
  NULL,
106
  NULL,
107
  NULL,
108
  ucs_2_internal_convert_to_ucs
109
};
110
#endif
111
 
112
#if defined (ICONV_FROM_UCS_CES_UCS_2_INTERNAL)
113
_CONST iconv_from_ucs_ces_handlers_t
114
_iconv_from_ucs_ces_handlers_ucs_2_internal =
115
{
116
  NULL,
117
  NULL,
118
  ucs_2_internal_get_mb_cur_max,
119
  NULL,
120
  NULL,
121
  NULL,
122
  ucs_2_internal_convert_from_ucs
123
};
124
#endif
125
 
126
#endif /* ICONV_TO_UCS_CES_UCS_2_INTERNAL || ICONV_FROM_UCS_CES_UCS_2_INTERNAL */
127
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.