citrus_iconv_none.c revision 252583
1219019Sgabor/* $FreeBSD: head/lib/libiconv_modules/iconv_none/citrus_iconv_none.c 252583 2013-07-03 18:27:45Z peter $ */ 2219019Sgabor/* $NetBSD: citrus_iconv_none.c,v 1.2 2003/07/01 09:42:16 tshiozak Exp $ */ 3219019Sgabor 4219019Sgabor/*- 5219019Sgabor * Copyright (c)2003 Citrus Project, 6219019Sgabor * All rights reserved. 7219019Sgabor * 8219019Sgabor * Redistribution and use in source and binary forms, with or without 9219019Sgabor * modification, are permitted provided that the following conditions 10219019Sgabor * are met: 11219019Sgabor * 1. Redistributions of source code must retain the above copyright 12219019Sgabor * notice, this list of conditions and the following disclaimer. 13219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 14219019Sgabor * notice, this list of conditions and the following disclaimer in the 15219019Sgabor * documentation and/or other materials provided with the distribution. 16219019Sgabor * 17219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27219019Sgabor * SUCH DAMAGE. 28219019Sgabor */ 29219019Sgabor 30219019Sgabor#include <sys/cdefs.h> 31219019Sgabor#include <sys/queue.h> 32219019Sgabor 33219019Sgabor#include <assert.h> 34219019Sgabor#include <errno.h> 35219019Sgabor#include <stdbool.h> 36219019Sgabor#include <stdlib.h> 37219019Sgabor#include <string.h> 38219019Sgabor 39219019Sgabor#include "citrus_types.h" 40219019Sgabor#include "citrus_module.h" 41219019Sgabor#include "citrus_hash.h" 42219019Sgabor#include "citrus_iconv.h" 43219019Sgabor#include "citrus_iconv_none.h" 44219019Sgabor 45219019Sgabor/* ---------------------------------------------------------------------- */ 46219019Sgabor 47219019Sgabor_CITRUS_ICONV_DECLS(iconv_none); 48219019Sgabor_CITRUS_ICONV_DEF_OPS(iconv_none); 49219019Sgabor 50219019Sgabor 51219019Sgabor/* ---------------------------------------------------------------------- */ 52219019Sgabor 53219019Sgaborint 54219019Sgabor_citrus_iconv_none_iconv_getops(struct _citrus_iconv_ops *ops) 55219019Sgabor{ 56219019Sgabor 57219019Sgabor memcpy(ops, &_citrus_iconv_none_iconv_ops, 58219019Sgabor sizeof(_citrus_iconv_none_iconv_ops)); 59219019Sgabor 60219019Sgabor return (0); 61219019Sgabor} 62219019Sgabor 63219019Sgaborstatic int 64219019Sgabor/*ARGSUSED*/ 65219019Sgabor_citrus_iconv_none_iconv_init_shared( 66219019Sgabor struct _citrus_iconv_shared * __restrict ci, 67219019Sgabor const char * __restrict in __unused, const char * __restrict out __unused) 68219019Sgabor{ 69219019Sgabor 70219019Sgabor ci->ci_closure = NULL; 71219019Sgabor return (0); 72219019Sgabor} 73219019Sgabor 74219019Sgaborstatic void 75219019Sgabor/*ARGSUSED*/ 76219019Sgabor_citrus_iconv_none_iconv_uninit_shared(struct _citrus_iconv_shared *ci __unused) 77219019Sgabor{ 78219019Sgabor 79219019Sgabor} 80219019Sgabor 81219019Sgaborstatic int 82219019Sgabor/*ARGSUSED*/ 83219019Sgabor_citrus_iconv_none_iconv_init_context(struct _citrus_iconv *cv) 84219019Sgabor{ 85219019Sgabor 86219019Sgabor cv->cv_closure = NULL; 87219019Sgabor return (0); 88219019Sgabor} 89219019Sgabor 90219019Sgaborstatic void 91219019Sgabor/*ARGSUSED*/ 92219019Sgabor_citrus_iconv_none_iconv_uninit_context(struct _citrus_iconv *cv __unused) 93219019Sgabor{ 94219019Sgabor 95219019Sgabor} 96219019Sgabor 97219019Sgaborstatic int 98219019Sgabor/*ARGSUSED*/ 99219019Sgabor_citrus_iconv_none_iconv_convert(struct _citrus_iconv * __restrict ci __unused, 100252583Speter const char * __restrict * __restrict in, size_t * __restrict inbytes, 101219019Sgabor char * __restrict * __restrict out, size_t * __restrict outbytes, 102219019Sgabor uint32_t flags __unused, size_t * __restrict invalids) 103219019Sgabor{ 104219019Sgabor size_t len; 105219019Sgabor int e2big; 106219019Sgabor 107219019Sgabor if ((in == NULL) || (out == NULL) || (inbytes == NULL)) 108219019Sgabor return (0); 109219019Sgabor if ((*in == NULL) || (*out == NULL) || (*inbytes == 0) || (*outbytes == 0)) 110219019Sgabor return (0); 111219019Sgabor len = *inbytes; 112219019Sgabor e2big = 0; 113219019Sgabor if (*outbytes<len) { 114219019Sgabor e2big = 1; 115219019Sgabor len = *outbytes; 116219019Sgabor } 117219019Sgabor memcpy(*out, *in, len); 118219019Sgabor in += len; 119219019Sgabor *inbytes -= len; 120219019Sgabor out += len; 121219019Sgabor *outbytes -= len; 122219019Sgabor *invalids = 0; 123219019Sgabor if (e2big) 124219019Sgabor return (E2BIG); 125219019Sgabor 126219019Sgabor return (0); 127219019Sgabor} 128