File: bug-iconv6.c

package info (click to toggle)
glibc 2.24-11%2Bdeb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 225,316 kB
  • sloc: ansic: 996,116; asm: 261,826; sh: 10,483; makefile: 9,849; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (52 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (45)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <iconv.h>
#include <locale.h>

static const char testbuf[] = {
	0xEF, 0xBE, 0x9F, 0xD0, 0xB4, 0xEF, 0xBE, 0x9F, 0x29, 0xEF, 0xBE, 0x8E,
	0xEF, 0xBE, 0x9F, 0xEF, 0xBD, 0xB6, 0xEF, 0xBD, 0xB0, 0xEF, 0xBE, 0x9D
};

static int
do_test (void)
{
  setlocale (LC_ALL, "de_DE.UTF-8");
  iconv_t ic = iconv_open ("ISO-2022-JP//TRANSLIT", "UTF-8");
  if (ic == (iconv_t) -1)
    {
      puts ("iconv_open failed");
      return 1;
    }
  size_t outremain = sizeof testbuf;
  char outbuf[outremain];
  char *inp = (char *) testbuf;
  char *outp = outbuf;
  size_t inremain = sizeof testbuf;

  int ret = iconv (ic, &inp, &inremain, &outp, &outremain);

  int result = 0;
  if (ret == (size_t) -1)
    {
      if (errno == E2BIG)
	puts ("buffer too small reported.  OK");
      else
	{
	  printf ("iconv failed with %d (%m)\n", errno);
	  result = 0;
	}
    }
  else
    {
      printf ("iconv returned %d\n", ret);
      result = 1;
    }

  return result;
}

#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"