]> sourceware.org Git - glibc.git/blame - iconv/gconv.c
Update.
[glibc.git] / iconv / gconv.c
CommitLineData
6973fc01
UD
1/* Convert characters in input buffer using conversion descriptor to
2 output buffer.
e573146a 3 Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
6973fc01
UD
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
8619129f 22#include <assert.h>
6973fc01 23#include <gconv.h>
8619129f 24#include <sys/param.h>
b3fc5f84 25#include <dlfcn.h>
6973fc01
UD
26
27int
0d9f6793 28internal_function
d64b6ad0
UD
29__gconv (__gconv_t cd, const unsigned char **inbuf,
30 const unsigned char *inbufend, unsigned char **outbuf,
31 unsigned char *outbufend, size_t *converted)
6973fc01 32{
d64b6ad0 33 size_t last_step = cd->__nsteps - 1;
6973fc01
UD
34 int result;
35
d64b6ad0
UD
36 if (cd == (__gconv_t) -1L)
37 return __GCONV_ILLEGAL_DESCRIPTOR;
e34b0f29 38
8619129f
UD
39 assert (converted != NULL);
40 *converted = 0;
6973fc01 41
c63598bf 42 cd->__data[last_step].__outbuf = outbuf != NULL ? *outbuf : NULL;
4a422921
UD
43 cd->__data[last_step].__outbufend = outbufend;
44
8619129f
UD
45 if (inbuf == NULL || *inbuf == NULL)
46 /* We just flush. */
94e365c6 47 result = DL_CALL_FCT (cd->__steps->__fct,
d64b6ad0
UD
48 (cd->__steps, cd->__data, NULL, NULL,
49 converted, 1));
8619129f
UD
50 else
51 {
e573146a 52 const unsigned char *last_start;
6973fc01 53
8619129f 54 assert (outbuf != NULL && *outbuf != NULL);
6973fc01 55
8619129f
UD
56 do
57 {
8619129f 58 last_start = *inbuf;
94e365c6 59 result = DL_CALL_FCT (cd->__steps->__fct,
d64b6ad0 60 (cd->__steps, cd->__data, inbuf, inbufend,
5ad49c07 61 converted, 0));
8619129f 62 }
d64b6ad0
UD
63 while (result == __GCONV_EMPTY_INPUT && last_start != *inbuf
64 && *inbuf + cd->__steps->__min_needed_from <= inbufend);
4bca4c17 65 }
6973fc01 66
8619129f 67 if (outbuf != NULL && *outbuf != NULL)
d64b6ad0 68 *outbuf = cd->__data[last_step].__outbuf;
8619129f 69
6973fc01
UD
70 return result;
71}
This page took 0.090069 seconds and 5 git commands to generate.