]> git.ipfire.org Git - thirdparty/glibc.git/blame - iconv/gconv.c
Handle DT_UNKNOWN in gconv-modules.d
[thirdparty/glibc.git] / iconv / gconv.c
CommitLineData
6973fc01
UD
1/* Convert characters in input buffer using conversion descriptor to
2 output buffer.
2b778ceb 3 Copyright (C) 1997-2021 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
41bdb6e2
AJ
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
6973fc01
UD
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
41bdb6e2 15 Lesser General Public License for more details.
6973fc01 16
41bdb6e2 17 You should have received a copy of the GNU Lesser General Public
59ba27a6 18 License along with the GNU C Library; if not, see
5a82c748 19 <https://www.gnu.org/licenses/>. */
6973fc01 20
8619129f 21#include <assert.h>
b3fc5f84 22#include <dlfcn.h>
b2b28911 23#include <stddef.h>
915a6c51
UD
24#include <sys/param.h>
25
26#include <gconv_int.h>
27#include <sysdep.h>
28
6973fc01
UD
29
30int
d64b6ad0
UD
31__gconv (__gconv_t cd, const unsigned char **inbuf,
32 const unsigned char *inbufend, unsigned char **outbuf,
38677ace 33 unsigned char *outbufend, size_t *irreversible)
6973fc01 34{
eacde9d0 35 size_t last_step;
6973fc01
UD
36 int result;
37
d64b6ad0
UD
38 if (cd == (__gconv_t) -1L)
39 return __GCONV_ILLEGAL_DESCRIPTOR;
e34b0f29 40
eacde9d0
UD
41 last_step = cd->__nsteps - 1;
42
38677ace
UD
43 assert (irreversible != NULL);
44 *irreversible = 0;
6973fc01 45
c63598bf 46 cd->__data[last_step].__outbuf = outbuf != NULL ? *outbuf : NULL;
4a422921
UD
47 cd->__data[last_step].__outbufend = outbufend;
48
915a6c51
UD
49 __gconv_fct fct = cd->__steps->__fct;
50#ifdef PTR_DEMANGLE
51 if (cd->__steps->__shlib_handle != NULL)
52 PTR_DEMANGLE (fct);
53#endif
54
8619129f 55 if (inbuf == NULL || *inbuf == NULL)
55ea8790
UD
56 {
57 /* We just flush. */
58 result = DL_CALL_FCT (fct,
59 (cd->__steps, cd->__data, NULL, NULL, NULL,
60 irreversible,
61 cd->__data[last_step].__outbuf == NULL ? 2 : 1,
62 0));
63
64 /* If the flush was successful clear the rest of the state. */
65 if (result == __GCONV_OK)
66 for (size_t cnt = 0; cnt <= last_step; ++cnt)
67 cd->__data[cnt].__invocation_counter = 0;
68 }
8619129f
UD
69 else
70 {
e573146a 71 const unsigned char *last_start;
6973fc01 72
8619129f 73 assert (outbuf != NULL && *outbuf != NULL);
6973fc01 74
8619129f
UD
75 do
76 {
8619129f 77 last_start = *inbuf;
915a6c51 78 result = DL_CALL_FCT (fct,
55985355 79 (cd->__steps, cd->__data, inbuf, inbufend,
f1d5c60d 80 NULL, irreversible, 0, 0));
8619129f 81 }
d64b6ad0
UD
82 while (result == __GCONV_EMPTY_INPUT && last_start != *inbuf
83 && *inbuf + cd->__steps->__min_needed_from <= inbufend);
4bca4c17 84 }
6973fc01 85
8619129f 86 if (outbuf != NULL && *outbuf != NULL)
d64b6ad0 87 *outbuf = cd->__data[last_step].__outbuf;
8619129f 88
6973fc01
UD
89 return result;
90}