Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libc / iconv / ces / table-pcs.c
blob45cfe62670ec8f902c2bc269695e9721e6124ceb
1 /*
2 * Copyright (c) 2003-2004, Artem B. Bityuckiy
3 * modification, are permitted provided that the following conditions
4 * are met:
5 * 1. Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * 2. Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
12 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
13 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
14 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
16 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
17 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
20 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
21 * SUCH DAMAGE.
25 * This CES converter is just an simple extension of table CES converter.
26 * This CES converter is used for 16 bit CCSes which include 7bit
27 * Portable Characters Set (PCS) (equivalent to ASCII) (example: BIG5).
30 #include "cesbi.h"
32 #if defined (ICONV_TO_UCS_CES_TABLE_PCS) \
33 || defined (ICONV_FROM_UCS_CES_TABLE_PCS)
35 #include <_ansi.h>
36 #include <reent.h>
37 #include <sys/types.h>
38 #include "../lib/local.h"
39 #include "../lib/ucsconv.h"
41 #if defined (ICONV_FROM_UCS_CES_TABLE_PCS)
42 static size_t
43 table_pcs_convert_from_ucs (void *data,
44 ucs4_t in,
45 unsigned char **outbuf,
46 size_t *outbytesleft)
48 if (*outbytesleft < 1)
49 return (size_t)ICONV_CES_NOSPACE;
51 if (in < 0x80)
53 **outbuf = (unsigned char)in;
54 *outbuf += 1;
55 *outbytesleft -= 1;
56 return 1;
59 return _iconv_from_ucs_ces_handlers_table.convert_from_ucs (
60 data,
61 in,
62 outbuf,
63 outbytesleft);
66 static void *
67 table_pcs_from_ucs_init (struct _reent *rptr,
68 const char *encoding)
70 return _iconv_from_ucs_ces_handlers_table.init (rptr, encoding);
73 static size_t
74 table_pcs_from_ucs_close (struct _reent *rptr,
75 void *data)
77 return _iconv_from_ucs_ces_handlers_table.close (rptr, data);
80 static int
81 table_pcs_from_ucs_get_mb_cur_max (void *data)
83 return _iconv_from_ucs_ces_handlers_table.get_mb_cur_max (data);
86 #endif /* ICONV_FROM_UCS_CES_TABLE_PCS */
88 #if defined (ICONV_TO_UCS_CES_TABLE_PCS)
89 static ucs4_t
90 table_pcs_convert_to_ucs (void *data,
91 const unsigned char **inbuf,
92 size_t *inbytesleft)
94 if (*inbytesleft < 1)
95 return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
97 if (**inbuf < 0x80)
99 *inbytesleft -= 1;
100 *inbuf += 1;
101 return (ucs4_t)(*(*inbuf - 1));
104 return _iconv_to_ucs_ces_handlers_table.convert_to_ucs (
105 data,
106 inbuf,
107 inbytesleft);
110 static void *
111 table_pcs_to_ucs_init (struct _reent *rptr,
112 const char *encoding)
114 return _iconv_to_ucs_ces_handlers_table.init (rptr, encoding);
117 static size_t
118 table_pcs_to_ucs_close (struct _reent *rptr,
119 void *data)
121 return _iconv_to_ucs_ces_handlers_table.close (rptr, data);
124 static int
125 table_pcs_to_ucs_get_mb_cur_max (void *data)
127 return _iconv_to_ucs_ces_handlers_table.get_mb_cur_max (data);
130 #endif /* ICONV_TO_UCS_CES_TABLE_PCS */
132 #if defined (ICONV_FROM_UCS_CES_TABLE_PCS)
133 const iconv_from_ucs_ces_handlers_t
134 _iconv_from_ucs_ces_handlers_table_pcs =
136 table_pcs_from_ucs_init,
137 table_pcs_from_ucs_close,
138 table_pcs_from_ucs_get_mb_cur_max,
139 NULL,
140 NULL,
141 NULL,
142 table_pcs_convert_from_ucs
144 #endif
146 #if defined (ICONV_TO_UCS_CES_TABLE_PCS)
147 const iconv_to_ucs_ces_handlers_t
148 _iconv_to_ucs_ces_handlers_table_pcs =
150 table_pcs_to_ucs_init,
151 table_pcs_to_ucs_close,
152 table_pcs_to_ucs_get_mb_cur_max,
153 NULL,
154 NULL,
155 NULL,
156 table_pcs_convert_to_ucs
158 #endif
160 #endif /* ICONV_TO_UCS_CES_TABLE_PCS || ICONV_FROM_UCS_CES_TABLE_PCS */