Drop no longer needed multibyte stuff from glibc.
This commit is contained in:
parent
b4435552a7
commit
bb79d18614
@ -1,33 +0,0 @@
|
||||
/* Return number of characters in multibyte representation for current
|
||||
character set.
|
||||
Copyright (C) 1996, 1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <langinfo.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include "localeinfo.h"
|
||||
|
||||
|
||||
size_t
|
||||
weak_function
|
||||
__ctype_get_mb_cur_max (void)
|
||||
{
|
||||
return _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MB_CUR_MAX);
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/* Copyright (C) 1991, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <gconv.h>
|
||||
#include <wcsmbs/wcsmbsload.h>
|
||||
|
||||
|
||||
/* Internal state. */
|
||||
static mbstate_t state;
|
||||
|
||||
/* Return the length of the multibyte character (if there is one)
|
||||
at S which is no longer than N characters.
|
||||
The ISO C standard says that the `mblen' function must not change
|
||||
the state of the `mbtowc' function. */
|
||||
int
|
||||
mblen (const char *s, size_t n)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* If S is NULL the function has to return null or not null
|
||||
depending on the encoding having a state depending encoding or
|
||||
not. */
|
||||
if (s == NULL)
|
||||
{
|
||||
/* Make sure we use the correct value. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* Reset the state. */
|
||||
memset (&state, '\0', sizeof state);
|
||||
|
||||
result = __wcsmbs_gconv_fcts.towc->__stateful;
|
||||
}
|
||||
else if (*s == '\0')
|
||||
/* According to the ISO C 89 standard this is the expected behaviour. */
|
||||
result = 0;
|
||||
else
|
||||
{
|
||||
memset (&state, '\0', sizeof state);
|
||||
|
||||
result = __mbrtowc (NULL, s, n, &state);
|
||||
|
||||
/* The `mbrtowc' functions tell us more than we need. Fold the -1
|
||||
and -2 result into -1. */
|
||||
if (result < 0)
|
||||
result = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/* Copyright (C) 1991, 92, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <gconv.h>
|
||||
#include <wcsmbs/wcsmbsload.h>
|
||||
|
||||
|
||||
/* Common state for all non-restartable conversion functions. */
|
||||
mbstate_t __no_r_state;
|
||||
|
||||
/* Convert the multibyte character at S, which is no longer
|
||||
than N characters, to its `wchar_t' representation, placing
|
||||
this n *PWC and returning its length.
|
||||
|
||||
Attention: this function should NEVER be intentionally used.
|
||||
The interface is completely stupid. The state is shared between
|
||||
all conversion functions. You should use instead the restartable
|
||||
version `mbrtowc'. */
|
||||
int
|
||||
mbtowc (wchar_t *pwc, const char *s, size_t n)
|
||||
{
|
||||
int result;
|
||||
|
||||
/* If S is NULL the function has to return null or not null
|
||||
depending on the encoding having a state depending encoding or
|
||||
not. */
|
||||
if (s == NULL)
|
||||
{
|
||||
/* Make sure we use the correct value. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* This is an extension in the Unix standard which does not directly
|
||||
violate ISO C. */
|
||||
memset (&__no_r_state, '\0', sizeof __no_r_state);
|
||||
|
||||
result = __wcsmbs_gconv_fcts.towc->__stateful;
|
||||
}
|
||||
else if (*s == '\0')
|
||||
{
|
||||
if (pwc != NULL)
|
||||
*pwc = L'\0';
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = __mbrtowc (pwc, s, n, &__no_r_state);
|
||||
|
||||
/* The `mbrtowc' functions tell us more than we need. Fold the -1
|
||||
and -2 result into -1. */
|
||||
if (result < 0)
|
||||
result = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/* Copyright (C) 1991, 92, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <gconv.h>
|
||||
#include <wcsmbs/wcsmbsload.h>
|
||||
|
||||
|
||||
extern mbstate_t __no_r_state; /* Defined in mbtowc.c. */
|
||||
|
||||
/* Convert WCHAR into its multibyte character representation,
|
||||
putting this in S and returning its length.
|
||||
|
||||
Attention: this function should NEVER be intentionally used.
|
||||
The interface is completely stupid. The state is shared between
|
||||
all conversion functions. You should use instead the restartable
|
||||
version `wcrtomb'. */
|
||||
int
|
||||
wctomb (char *s, wchar_t wchar)
|
||||
{
|
||||
/* If S is NULL the function has to return null or not null
|
||||
depending on the encoding having a state depending encoding or
|
||||
not. */
|
||||
if (s == NULL)
|
||||
{
|
||||
/* Make sure we use the correct value. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* This is an extension in the Unix standard which does not directly
|
||||
violate ISO C. */
|
||||
memset (&__no_r_state, '\0', sizeof __no_r_state);
|
||||
|
||||
return __wcsmbs_gconv_fcts.tomb->__stateful;
|
||||
}
|
||||
|
||||
return __wcrtomb (s, wchar, &__no_r_state);
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <gconv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <wcsmbsload.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
wint_t
|
||||
__btowc (c)
|
||||
int c;
|
||||
{
|
||||
wchar_t result;
|
||||
struct __gconv_step_data data;
|
||||
unsigned char inbuf[1];
|
||||
const unsigned char *inptr = inbuf;
|
||||
size_t dummy;
|
||||
int status;
|
||||
|
||||
/* If the parameter does not fit into one byte or it is the EOF value
|
||||
we can give the answer now. */
|
||||
if (c < SCHAR_MIN || c > UCHAR_MAX || c == EOF)
|
||||
return WEOF;
|
||||
|
||||
/* Tell where we want the result. */
|
||||
data.__outbuf = (unsigned char *) &result;
|
||||
data.__outbufend = data.__outbuf + sizeof (wchar_t);
|
||||
data.__invocation_counter = 0;
|
||||
data.__internal_use = 1;
|
||||
data.__flags = __GCONV_IS_LAST;
|
||||
data.__statep = &data.__state;
|
||||
data.__trans = NULL;
|
||||
|
||||
/* Make sure we start in the initial state. */
|
||||
memset (&data.__state, '\0', sizeof (mbstate_t));
|
||||
|
||||
/* Make sure we use the correct function. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* Create the input string. */
|
||||
inbuf[0] = c;
|
||||
|
||||
status = DL_CALL_FCT (__wcsmbs_gconv_fcts.towc->__fct,
|
||||
(__wcsmbs_gconv_fcts.towc, &data, &inptr, inptr + 1,
|
||||
NULL, &dummy, 0, 1));
|
||||
/* The conversion failed. */
|
||||
if (status != __GCONV_OK && status != __GCONV_FULL_OUTPUT
|
||||
&& status != __GCONV_EMPTY_INPUT)
|
||||
result = WEOF;
|
||||
|
||||
return result;
|
||||
}
|
||||
weak_alias (__btowc, btowc)
|
@ -1,36 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper, <drepper@gnu.ai.mit.edu>
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
/* The mbrlen function has an internal shift state which gets used if
|
||||
the PS parameter is NULL. */
|
||||
static mbstate_t internal;
|
||||
|
||||
|
||||
size_t
|
||||
__mbrlen (s, n, ps)
|
||||
const char *s;
|
||||
size_t n;
|
||||
mbstate_t *ps;
|
||||
{
|
||||
return __mbrtowc (NULL, s, n, ps ?: &internal);
|
||||
}
|
||||
libc_hidden_def (__mbrlen)
|
||||
weak_alias (__mbrlen, mbrlen)
|
@ -1,107 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.org>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <gconv.h>
|
||||
#include <wchar.h>
|
||||
#include <wcsmbsload.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef EILSEQ
|
||||
# define EILSEQ EINVAL
|
||||
#endif
|
||||
|
||||
/* This is the private state used if PS is NULL. */
|
||||
static mbstate_t state;
|
||||
|
||||
size_t
|
||||
__mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
|
||||
{
|
||||
wchar_t buf[1];
|
||||
struct __gconv_step_data data;
|
||||
int status;
|
||||
size_t result;
|
||||
size_t dummy;
|
||||
const unsigned char *inbuf;
|
||||
char *outbuf = (char *) (pwc ?: buf);
|
||||
|
||||
/* Set information for this step. */
|
||||
data.__invocation_counter = 0;
|
||||
data.__internal_use = 1;
|
||||
data.__flags = __GCONV_IS_LAST;
|
||||
data.__statep = ps ?: &state;
|
||||
data.__trans = NULL;
|
||||
|
||||
/* A first special case is if S is NULL. This means put PS in the
|
||||
initial state. */
|
||||
if (s == NULL)
|
||||
{
|
||||
outbuf = (char *) buf;
|
||||
s = "";
|
||||
n = 1;
|
||||
}
|
||||
|
||||
/* Tell where we want the result. */
|
||||
data.__outbuf = outbuf;
|
||||
data.__outbufend = outbuf + sizeof (wchar_t);
|
||||
|
||||
/* Make sure we use the correct function. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* Do a normal conversion. */
|
||||
inbuf = (const unsigned char *) s;
|
||||
status = DL_CALL_FCT (__wcsmbs_gconv_fcts.towc->__fct,
|
||||
(__wcsmbs_gconv_fcts.towc, &data, &inbuf, inbuf + n,
|
||||
NULL, &dummy, 0, 1));
|
||||
|
||||
/* There must not be any problems with the conversion but illegal input
|
||||
characters. The output buffer must be large enough, otherwise the
|
||||
definition of MB_CUR_MAX is not correct. All the other possible
|
||||
errors also must not happen. */
|
||||
assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT
|
||||
|| status == __GCONV_ILLEGAL_INPUT
|
||||
|| status == __GCONV_INCOMPLETE_INPUT
|
||||
|| status == __GCONV_FULL_OUTPUT);
|
||||
|
||||
if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT
|
||||
|| status == __GCONV_FULL_OUTPUT)
|
||||
{
|
||||
if (data.__outbuf != (unsigned char *) outbuf
|
||||
&& *(wchar_t *) outbuf == L'\0')
|
||||
{
|
||||
/* The converted character is the NUL character. */
|
||||
assert (__mbsinit (data.__statep));
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
result = inbuf - (const unsigned char *) s;
|
||||
}
|
||||
else if (status == __GCONV_INCOMPLETE_INPUT)
|
||||
result = (size_t) -2;
|
||||
else
|
||||
{
|
||||
result = (size_t) -1;
|
||||
__set_errno (EILSEQ);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
weak_alias (__mbrtowc, mbrtowc)
|
@ -1,37 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/* In GNU libc the conversion functions only can convert between the
|
||||
fixed wide character representation and the multibyte
|
||||
representation of the same character set. Since we use ISO 10646
|
||||
in UCS4 encoding for wide characters the best solution for
|
||||
multibyte characters is the UTF8 encoding. I.e., the only state
|
||||
information is a counter of the processed bytes so far and the
|
||||
value collected so far. Especially, we don't have different shift
|
||||
states. */
|
||||
int
|
||||
__mbsinit (ps)
|
||||
const mbstate_t *ps;
|
||||
{
|
||||
return ps == NULL || ps->__count == 0;
|
||||
}
|
||||
weak_alias (__mbsinit, mbsinit)
|
@ -1,110 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <gconv.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <wcsmbsload.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifndef EILSEQ
|
||||
# define EILSEQ EINVAL
|
||||
#endif
|
||||
|
||||
|
||||
/* This is the private state used if PS is NULL. */
|
||||
static mbstate_t state;
|
||||
|
||||
size_t
|
||||
__wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
|
||||
{
|
||||
char buf[MB_CUR_MAX];
|
||||
struct __gconv_step_data data;
|
||||
int status;
|
||||
size_t result;
|
||||
size_t dummy;
|
||||
|
||||
/* Set information for this step. */
|
||||
data.__invocation_counter = 0;
|
||||
data.__internal_use = 1;
|
||||
data.__flags = __GCONV_IS_LAST;
|
||||
data.__statep = ps ?: &state;
|
||||
data.__trans = NULL;
|
||||
|
||||
/* A first special case is if S is NULL. This means put PS in the
|
||||
initial state. */
|
||||
if (s == NULL)
|
||||
{
|
||||
s = buf;
|
||||
wc = L'\0';
|
||||
}
|
||||
|
||||
/* Tell where we want to have the result. */
|
||||
data.__outbuf = s;
|
||||
data.__outbufend = s + MB_CUR_MAX;
|
||||
|
||||
/* Make sure we use the correct function. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* If WC is the NUL character we write into the output buffer the byte
|
||||
sequence necessary for PS to get into the initial state, followed
|
||||
by a NUL byte. */
|
||||
if (wc == L'\0')
|
||||
{
|
||||
status = DL_CALL_FCT (__wcsmbs_gconv_fcts.tomb->__fct,
|
||||
(__wcsmbs_gconv_fcts.tomb, &data, NULL, NULL,
|
||||
NULL, &dummy, 1, 1));
|
||||
|
||||
if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT)
|
||||
*data.__outbuf++ = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Do a normal conversion. */
|
||||
const unsigned char *inbuf = (const unsigned char *) &wc;
|
||||
|
||||
status = DL_CALL_FCT (__wcsmbs_gconv_fcts.tomb->__fct,
|
||||
(__wcsmbs_gconv_fcts.tomb, &data, &inbuf,
|
||||
inbuf + sizeof (wchar_t), NULL, &dummy, 0, 1));
|
||||
}
|
||||
|
||||
/* There must not be any problems with the conversion but illegal input
|
||||
characters. The output buffer must be large enough, otherwise the
|
||||
definition of MB_CUR_MAX is not correct. All the other possible
|
||||
errors also must not happen. */
|
||||
assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT
|
||||
|| status == __GCONV_ILLEGAL_INPUT
|
||||
|| status == __GCONV_INCOMPLETE_INPUT
|
||||
|| status == __GCONV_FULL_OUTPUT);
|
||||
|
||||
if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT
|
||||
|| status == __GCONV_FULL_OUTPUT)
|
||||
result = data.__outbuf - (unsigned char *) s;
|
||||
else
|
||||
{
|
||||
result = (size_t) -1;
|
||||
__set_errno (EILSEQ);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
weak_alias (__wcrtomb, wcrtomb)
|
@ -1,39 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include "wcwidth.h"
|
||||
|
||||
/* Determine number of column positions required for first N wide
|
||||
characters (or fewer if S ends before this) in S. */
|
||||
int
|
||||
wcswidth (const wchar_t *s, size_t n)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
while (n-- > 0 && *s != L'\0')
|
||||
{
|
||||
int now = internal_wcwidth (*s);
|
||||
if (now == -1)
|
||||
return -1;
|
||||
result += now;
|
||||
++s;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <gconv.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wchar.h>
|
||||
#include <wcsmbsload.h>
|
||||
|
||||
|
||||
int
|
||||
wctob (c)
|
||||
wint_t c;
|
||||
{
|
||||
char buf[MB_LEN_MAX];
|
||||
struct __gconv_step_data data;
|
||||
wchar_t inbuf[1];
|
||||
wchar_t *inptr = inbuf;
|
||||
size_t dummy;
|
||||
int status;
|
||||
|
||||
if (c == WEOF)
|
||||
return EOF;
|
||||
|
||||
/* Tell where we want the result. */
|
||||
data.__outbuf = buf;
|
||||
data.__outbufend = buf + MB_LEN_MAX;
|
||||
data.__invocation_counter = 0;
|
||||
data.__internal_use = 1;
|
||||
data.__flags = __GCONV_IS_LAST;
|
||||
data.__statep = &data.__state;
|
||||
data.__trans = NULL;
|
||||
|
||||
/* Make sure we start in the initial state. */
|
||||
memset (&data.__state, '\0', sizeof (mbstate_t));
|
||||
|
||||
/* Make sure we use the correct function. */
|
||||
update_conversion_ptrs ();
|
||||
|
||||
/* Create the input string. */
|
||||
inbuf[0] = c;
|
||||
|
||||
status = DL_CALL_FCT (__wcsmbs_gconv_fcts.tomb->__fct,
|
||||
(__wcsmbs_gconv_fcts.tomb, &data,
|
||||
(const unsigned char **) &inptr,
|
||||
(const unsigned char *) &inbuf[1],
|
||||
NULL, &dummy, 0, 1));
|
||||
|
||||
/* The conversion failed or the output is too long. */
|
||||
if ((status != __GCONV_OK && status != __GCONV_FULL_OUTPUT
|
||||
&& status != __GCONV_EMPTY_INPUT)
|
||||
|| data.__outbuf != (unsigned char *) (buf + 1))
|
||||
return EOF;
|
||||
|
||||
return (unsigned char) buf[0];
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/* Copyright (C) 1996, 1997, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include "wcwidth.h"
|
||||
|
||||
/* Determine number of column positions required for CH. */
|
||||
int
|
||||
wcwidth (wchar_t ch)
|
||||
{
|
||||
return internal_wcwidth (ch);
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/* Internal header containing implementation of wcwidth() function.
|
||||
Copyright (C) 1996,1997,1999,2000,2001,2002 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
#include "../wctype/wchar-lookup.h"
|
||||
#include "../locale/localeinfo.h"
|
||||
|
||||
/* Table containing width information. */
|
||||
extern const char *__ctype32_width attribute_hidden;
|
||||
|
||||
static __inline int
|
||||
internal_wcwidth (wchar_t wc)
|
||||
{
|
||||
unsigned char res;
|
||||
|
||||
/* The tables have been prepared in such a way that
|
||||
1. wc == L'\0' yields res = 0,
|
||||
2. !iswprint (wc) implies res = '\xff'. */
|
||||
res = wcwidth_table_lookup (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_WIDTH), wc);
|
||||
|
||||
return res == (unsigned char) '\xff' ? -1 : (int) res;
|
||||
}
|
Loading…
Reference in New Issue
Block a user