File: ucs4.c

package info (click to toggle)
libunicode 0.4.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,472 kB
  • ctags: 510
  • sloc: ansic: 13,451; sh: 7,506; perl: 450; makefile: 98; cpp: 9
file content (61 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (3)
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
53
54
55
56
57
58
59
60
61
/* ucs4.c - test the UCS-4 encoder/decoder.
   
   Copyright (C) 199 Tom Tromey

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.  */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#include <unicode.h>

/* Return 1 on error, 0 on success.  */
static int
check (unicode_iconv_t context, char c)
{
  char input[100];
  char *inp = input;
  char output[100];
  size_t inbytes, outbytes;
  char *outp = output;

  inbytes = 1;
  input[0] = 'A';
  outbytes = sizeof (output);
  unicode_iconv (context,
		 (const char **) &inp, &inbytes,
		 &outp, &outbytes);

  if (inbytes != 0 || outp - output != 4)
    return 1;
  if (output[0] || output[1] || output[2] || ! output[3])
    return 1;

  return 0;
}

int main ()
{
  unicode_iconv_t context;

  unicode_init ();

  context = unicode_iconv_open ("UCS-4", "ASCII");
  return check (context, 'A');
}