1 /*
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 <_ansi.h>
27 #include <sys/types.h>
28 #include <errno.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include "local.h"
32 #include "conv.h"
33
34 static int null_conversion_dummy_data;
35
36
37 static void *
null_conversion_open(const char * to,const char * from)38 null_conversion_open (
39 const char *to,
40 const char *from)
41 {
42 (void) to;
43 (void) from;
44 return (void *)&null_conversion_dummy_data;
45 }
46
47
48 static size_t
null_conversion_close(void * data)49 null_conversion_close (
50 void *data)
51 {
52 (void) data;
53 return 0;
54 }
55
56
57 static size_t
null_conversion_convert(void * data,const unsigned char ** inbuf,size_t * inbytesleft,unsigned char ** outbuf,size_t * outbytesleft,int flags)58 null_conversion_convert (
59 void *data,
60 const unsigned char **inbuf,
61 size_t *inbytesleft,
62 unsigned char **outbuf,
63 size_t *outbytesleft,
64 int flags)
65 {
66 size_t result;
67 size_t len;
68
69 (void) data;
70 if (*inbytesleft < *outbytesleft)
71 {
72 result = 0;
73 len = *inbytesleft;
74 }
75 else
76 {
77 result = (size_t)-1;
78 len = *outbytesleft;
79 _REENT_ERRNO (rptr) = E2BIG;
80 }
81
82 if ((flags & 1) == 0)
83 memcpy (*outbuf, *inbuf, len);
84
85 *inbuf += len;
86 *outbuf += len;
87 *inbytesleft -= len;
88 *outbytesleft -= len;
89
90 return result;
91 }
92
93
94 static int
null_conversion_get_mb_cur_max(void * data,int direction)95 null_conversion_get_mb_cur_max (void *data,
96 int direction)
97 {
98 (void) data;
99 (void) direction;
100 return ICONV_MB_LEN_MAX;
101 }
102
103
104 static void
null_conversion_get_state(void * data,mbstate_t * state,int direction)105 null_conversion_get_state (void *data,
106 mbstate_t *state,
107 int direction)
108 {
109 (void) data;
110 (void) state;
111 (void) direction;
112 return;
113 }
114
115
116 static int
null_conversion_set_state(void * data,mbstate_t * state,int direction)117 null_conversion_set_state (void *data,
118 mbstate_t *state,
119 int direction)
120 {
121 (void) data;
122 (void) state;
123 (void) direction;
124 return 0;
125 }
126
127 static int
null_conversion_is_stateful(void * data,int direction)128 null_conversion_is_stateful (void *data,
129 int direction)
130 {
131 (void) data;
132 (void) direction;
133 return 0;
134 }
135
136 /* Null conversion definition object */
137 const iconv_conversion_handlers_t
138 _iconv_null_conversion_handlers =
139 {
140 null_conversion_open,
141 null_conversion_close,
142 null_conversion_convert,
143 null_conversion_get_state,
144 null_conversion_set_state,
145 null_conversion_get_mb_cur_max,
146 null_conversion_is_stateful
147 };
148
149