Back to index

glibc  2.9
Functions
tst-e2big.c File Reference
#include <alloca.h>
#include <errno.h>
#include <iconv.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

void test (const char *encoding, char *inbuf, size_t inbufsize, size_t outbufsize)
void test_euc_jisx0213 (void)
void test_tscii (void)
int main (void)

Function Documentation

int main ( void  )

Definition at line 100 of file tst-e2big.c.

{
  test_euc_jisx0213 ();
  test_tscii ();
  return 0;
}

Here is the call graph for this function:

void test ( const char *  encoding,
char *  inbuf,
size_t  inbufsize,
size_t  outbufsize 
)

Definition at line 34 of file tst-e2big.c.

{
  char *outbuf = alloca (outbufsize);
  iconv_t cd;
  char *inptr;
  size_t inlen;
  char *outptr;
  size_t outlen;
  int result;
  bool empty_input;
  bool empty_output;

  cd = iconv_open ("UTF-8", encoding);
  if (cd == (iconv_t) -1)
    {
      fprintf (stderr, "cannot convert from %s\n", encoding);
      exit (1);
    }

  inptr = inbuf;
  inlen = inbufsize;
  outptr = outbuf;
  outlen = outbufsize;

  result = iconv (cd, &inptr, &inlen, &outptr, &outlen);
  if (!(result == -1 && errno == E2BIG))
    {
      fprintf (stderr, "%s: wrong iconv result: %d/%d (%m)\n",
              encoding, result, errno);
      exit (1);
    }
  empty_input = (inptr == inbuf && inlen == inbufsize);
  empty_output = (outptr == outbuf && outlen == outbufsize);

  if (!empty_input && empty_output)
    {
      fprintf (stderr, "%s: ate %td input bytes\n", encoding, inptr - inbuf);
      exit (1);
    }
  if (empty_input && !empty_output)
    {
      fprintf (stderr, "%s: produced %td output bytes\n",
              encoding, outptr - outbuf);
      exit (1);
    }

  iconv_close (cd);
}

Here is the call graph for this function:

void test_euc_jisx0213 ( void  )

Definition at line 84 of file tst-e2big.c.

{
  char inbuf[2] = { 0xa4, 0xf7 };
  test ("EUC-JISX0213", inbuf, sizeof (inbuf), 3);
}

Here is the caller graph for this function:

void test_tscii ( void  )

Definition at line 91 of file tst-e2big.c.

{
  char inbuf[1] = { 0x82 };
  test ("TSCII", inbuf, sizeof (inbuf), 3);
  test ("TSCII", inbuf, sizeof (inbuf), 6);
  test ("TSCII", inbuf, sizeof (inbuf), 9);
}

Here is the caller graph for this function: