gdb
[deliverable/binutils-gdb.git] / gdb / charset.c
index 9c1e7f48e70476090b774ba899f8407b6059f811..90d5717b57377c35e7d85f72fb93f6ab95435d6a 100644 (file)
@@ -33,6 +33,9 @@
 #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.  */
@@ -119,14 +125,14 @@ iconv_open (const char *to, const char *from)
 }
 
 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)
     {
@@ -164,6 +170,7 @@ iconv (iconv_t utf_flag, const char **inbuf, size_t *inbytesleft,
       /* 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);
@@ -309,6 +316,7 @@ validate (struct gdbarch *gdbarch)
   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);
 
@@ -631,18 +639,22 @@ wchar_iterate (struct wchar_iterator *iter,
       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;
@@ -699,7 +711,6 @@ wchar_iterate (struct wchar_iterator *iter,
 
 extern initialize_file_ftype _initialize_charset; /* -Wmissing-prototype */
 
-typedef char *char_ptr;
 DEF_VEC_P (char_ptr);
 
 static VEC (char_ptr) *charsets;
@@ -791,7 +802,7 @@ find_charset_names (void)
   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";
@@ -812,7 +823,7 @@ find_charset_names (void)
          /* 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)
@@ -907,8 +918,6 @@ default_auto_wide_charset (void)
 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 ();
@@ -932,7 +941,7 @@ _initialize_charset (void)
   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());
This page took 0.026382 seconds and 4 git commands to generate.