Files
glibc/iconv/gconv.c
T

73 lines
2.3 KiB
C
Raw Normal View History

1997-11-18 02:50:07 +00:00
/* Convert characters in input buffer using conversion descriptor to
output buffer.
Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
1997-11-18 02:50:07 +00:00
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
1998-04-20 18:41:05 +00:00
#include <assert.h>
2000-11-20 09:16:41 +00:00
#include <gconv_int.h>
1998-04-20 18:41:05 +00:00
#include <sys/param.h>
1999-06-28 15:52:36 +00:00
#include <dlfcn.h>
2000-02-23 22:15:49 +00:00
#include <stddef.h>
1997-11-18 02:50:07 +00:00
int
1998-04-04 07:25:25 +00:00
internal_function
1999-06-16 22:55:47 +00:00
__gconv (__gconv_t cd, const unsigned char **inbuf,
const unsigned char *inbufend, unsigned char **outbuf,
2000-06-10 22:54:47 +00:00
unsigned char *outbufend, size_t *irreversible)
1997-11-18 02:50:07 +00:00
{
1999-06-16 22:55:47 +00:00
size_t last_step = cd->__nsteps - 1;
1997-11-18 02:50:07 +00:00
int result;
1999-06-16 22:55:47 +00:00
if (cd == (__gconv_t) -1L)
return __GCONV_ILLEGAL_DESCRIPTOR;
1997-11-24 02:08:40 +00:00
2000-06-10 22:54:47 +00:00
assert (irreversible != NULL);
*irreversible = 0;
1997-11-18 02:50:07 +00:00
1999-12-21 08:10:06 +00:00
cd->__data[last_step].__outbuf = outbuf != NULL ? *outbuf : NULL;
1999-11-25 21:45:54 +00:00
cd->__data[last_step].__outbufend = outbufend;
1998-04-20 18:41:05 +00:00
if (inbuf == NULL || *inbuf == NULL)
/* We just flush. */
1999-07-07 18:39:33 +00:00
result = DL_CALL_FCT (cd->__steps->__fct,
2000-06-16 00:39:38 +00:00
(cd->__steps, cd->__data, NULL, NULL, NULL,
irreversible, 1, 0));
1998-04-20 18:41:05 +00:00
else
1998-04-07 09:21:28 +00:00
{
1999-03-16 06:01:43 +00:00
const unsigned char *last_start;
1998-04-20 18:41:05 +00:00
assert (outbuf != NULL && *outbuf != NULL);
do
{
last_start = *inbuf;
1999-07-07 18:39:33 +00:00
result = DL_CALL_FCT (cd->__steps->__fct,
2000-06-12 19:47:50 +00:00
(cd->__steps, cd->__data, inbuf, inbufend,
2000-06-16 00:39:38 +00:00
NULL, irreversible, 0, 0));
1998-04-20 18:41:05 +00:00
}
1999-06-16 22:55:47 +00:00
while (result == __GCONV_EMPTY_INPUT && last_start != *inbuf
&& *inbuf + cd->__steps->__min_needed_from <= inbufend);
1998-04-07 09:21:28 +00:00
}
1997-11-18 02:50:07 +00:00
1998-04-20 18:41:05 +00:00
if (outbuf != NULL && *outbuf != NULL)
1999-06-16 22:55:47 +00:00
*outbuf = cd->__data[last_step].__outbuf;
1998-04-20 18:41:05 +00:00
1997-11-18 02:50:07 +00:00
return result;
}