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