#include "gdb_string.h"
#include <ctype.h>
+#ifdef USE_WIN32API
+#include <windows.h>
+#endif
\f
/* How GDB's character set support works
#undef iconv_t
#define iconv_t int
#undef iconv_open
+#define iconv_open phony_iconv_open
#undef iconv
+#define iconv phony_iconv
#undef iconv_close
+#define iconv_close phony_iconv_close
#undef ICONV_CONST
#define ICONV_CONST const
#endif
iconv_t
-iconv_open (const char *to, const char *from)
+phony_iconv_open (const char *to, const char *from)
{
/* We allow conversions from UTF-32BE, wchar_t, and the host charset.
We allow conversions to wchar_t and the host charset. */
}
int
-iconv_close (iconv_t arg)
+phony_iconv_close (iconv_t arg)
{
return 0;
}
size_t
-iconv (iconv_t utf_flag, const char **inbuf, size_t *inbytesleft,
- char **outbuf, size_t *outbytesleft)
+phony_iconv (iconv_t utf_flag, const char **inbuf, size_t *inbytesleft,
+ char **outbuf, size_t *outbytesleft)
{
if (utf_flag)
{
/* In all other cases we simply copy input bytes to the
output. */
size_t amt = *inbytesleft;
+
if (amt > *outbytesleft)
amt = *outbytesleft;
memcpy (*outbuf, *inbuf, amt);
const char *host_cset = host_charset ();
const char *target_cset = target_charset (gdbarch);
const char *target_wide_cset = target_wide_charset_name;
+
if (!strcmp (target_wide_cset, "auto"))
target_wide_cset = gdbarch_auto_wide_charset (gdbarch);
size_t orig_in = iter->bytes;
size_t out_avail = out_request * sizeof (gdb_wchar_t);
size_t num;
- gdb_wchar_t result;
-
size_t r = iconv (iter->desc,
(ICONV_CONST char **) &iter->input, &iter->bytes,
&outptr, &out_avail);
+
if (r == (size_t) -1)
{
switch (errno)
{
case EILSEQ:
- /* Invalid input sequence. Skip it, and let the caller
- know about it. */
+ /* Invalid input sequence. We still might have converted a
+ character; if so, return it. */
+ if (out_avail < out_request * sizeof (gdb_wchar_t))
+ break;
+
+ /* Otherwise skip the first invalid character, and let the
+ caller know about it. */
*out_result = wchar_iterate_invalid;
*ptr = iter->input;
*len = iter->width;
extern initialize_file_ftype _initialize_charset; /* -Wmissing-prototype */
-typedef char *char_ptr;
DEF_VEC_P (char_ptr);
static VEC (char_ptr) *charsets;
set_in_environ (iconv_env, "LANGUAGE", "C");
set_in_environ (iconv_env, "LC_ALL", "C");
- child = pex_init (0, "iconv", NULL);
+ child = pex_init (PEX_USE_PIPES, "iconv", NULL);
args[0] = "iconv";
args[1] = "-l";
/* The size of buf is chosen arbitrarily. */
char buf[1024];
char *start, *r;
- int len, keep_going;
+ int len;
r = fgets (buf, sizeof (buf), in);
if (!r)
void
_initialize_charset (void)
{
- struct cmd_list_element *new_cmd;
-
/* The first element is always "auto". */
VEC_safe_push (char_ptr, charsets, xstrdup ("auto"));
find_charset_names ();
auto_target_charset_name = auto_host_charset_name;
#elif defined (USE_WIN32API)
{
- static w32_host_default_charset[16]; /* "CP" + x<=5 digits + paranoia. */
+ static char w32_host_default_charset[16]; /* "CP" + x<=5 digits + paranoia. */
snprintf (w32_host_default_charset, sizeof w32_host_default_charset,
"CP%d", GetACP());