Blame iconvdata/bug-iconv1.c

Packit 6c4009
/* Test program by Satoru Takabayashi.  */
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <iconv.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (int argc, char **argv)
Packit 6c4009
{
Packit 6c4009
  const char in[] = "\x41\x42\x43\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa";
Packit 6c4009
                  /* valid eucJP string */
Packit 6c4009
  const char exp[] = "\x41\x42\x43\x82\xa0\x82\xa2\x82\xa4";
Packit 6c4009
  size_t outbufsize = 10;
Packit 6c4009
                  /* 10 is too small to store full result (intentional) */
Packit 6c4009
  size_t inleft, outleft;
Packit 6c4009
  char *in_p = (char *) in;
Packit 6c4009
  char out[outbufsize];
Packit 6c4009
  char *out_p = out;
Packit 6c4009
  iconv_t cd;
Packit 6c4009
  int i;
Packit 6c4009
Packit 6c4009
  inleft = strlen (in);
Packit 6c4009
  outleft = outbufsize;
Packit 6c4009
Packit 6c4009
  cd = iconv_open ("SJIS", "eucJP");
Packit 6c4009
  if (cd == (iconv_t) -1)
Packit 6c4009
    {
Packit 6c4009
      puts ("iconv_open failed");
Packit 6c4009
      exit (1);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  iconv (cd, &in_p, &inleft, &out_p, &outleft); /* this returns E2BIG */
Packit 6c4009
  for (i = 0; i < outbufsize - outleft; ++i)
Packit 6c4009
    printf (" %02x", (unsigned char) out[i]);
Packit 6c4009
  puts ("");
Packit 6c4009
  iconv_close (cd);
Packit 6c4009
Packit 6c4009
  return outbufsize - outleft != 9 || memcmp (out, exp, 9) != 0;
Packit 6c4009
}