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