title: iconv encoding conversion problem
body: <p>I am having trouble converting strings from utf8 to gb2312. My convert function is below </p>
  
  <pre><code>void convert(const char *from_charset,const char *to_charset, char *inptr, char *outptr)
  {
      size_t inleft = strlen(inptr);
      size_t outleft = inleft;
      iconv_t cd;     /* conversion descriptor */
  
      if ((cd = iconv_open(to_charset, from_charset)) == (iconv_t)(-1)) 
      {
              fprintf(stderr, "Cannot open converter from %s to %s\n", from_charset, to_charset);
              exit(8);
      }
  
      /* return code of iconv() */
      int rc = iconv(cd, &amp;inptr, &amp;inleft, &amp;outptr, &amp;outleft);
      if (rc == -1) 
      {
              fprintf(stderr, "Error in converting characters\n");
  
              if(errno == E2BIG)
                      printf("errno == E2BIG\n");
              if(errno == EILSEQ)
                      printf("errno == EILSEQ\n");
              if(errno == EINVAL)
                      printf("errno == EINVAL\n");
  
              iconv_close(cd);
              exit(8);
      }
      iconv_close(cd);
  }
  </code></pre>
  
  <p>This is an example of how I used it:</p>
  
  <pre><code>int len = 1000;
  char *result = new char[len];
  convert("UTF-8", "GB2312", some_string, result);
  </code></pre>
  
  <p>edit: I most of the time get a E2BIG error.</p>