1*16d86563SAlexander Pyhalov /*
2*16d86563SAlexander Pyhalov  * CDDL HEADER START
3*16d86563SAlexander Pyhalov  *
4*16d86563SAlexander Pyhalov  * The contents of this file are subject to the terms of the
5*16d86563SAlexander Pyhalov  * Common Development and Distribution License (the "License").
6*16d86563SAlexander Pyhalov  * You may not use this file except in compliance with the License.
7*16d86563SAlexander Pyhalov  *
8*16d86563SAlexander Pyhalov  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9*16d86563SAlexander Pyhalov  * or http://www.opensolaris.org/os/licensing.
10*16d86563SAlexander Pyhalov  * See the License for the specific language governing permissions
11*16d86563SAlexander Pyhalov  * and limitations under the License.
12*16d86563SAlexander Pyhalov  *
13*16d86563SAlexander Pyhalov  * When distributing Covered Code, include this CDDL HEADER in each
14*16d86563SAlexander Pyhalov  * file and include the License file at src/OPENSOLARIS.LICENSE.
15*16d86563SAlexander Pyhalov  * If applicable, add the following below this CDDL HEADER, with the
16*16d86563SAlexander Pyhalov  * fields enclosed by brackets "[]" replaced with your own identifying
17*16d86563SAlexander Pyhalov  * information: Portions Copyright [yyyy] [name of copyright owner]
18*16d86563SAlexander Pyhalov  *
19*16d86563SAlexander Pyhalov  * CDDL HEADER END
20*16d86563SAlexander Pyhalov  */
21*16d86563SAlexander Pyhalov /*
22*16d86563SAlexander Pyhalov  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23*16d86563SAlexander Pyhalov  * Use is subject to license terms.
24*16d86563SAlexander Pyhalov  */
25*16d86563SAlexander Pyhalov 
26*16d86563SAlexander Pyhalov #ifndef DEBUG_C
27*16d86563SAlexander Pyhalov #define DEBUG_C
28*16d86563SAlexander Pyhalov 
29*16d86563SAlexander Pyhalov #ifdef DEBUG
30*16d86563SAlexander Pyhalov #include <sys/fcntl.h>
31*16d86563SAlexander Pyhalov #include <sys/stat.h>
main(int argc,char ** argv)32*16d86563SAlexander Pyhalov int main(int argc, char ** argv) {
33*16d86563SAlexander Pyhalov 	char *inbuf, *outbuf, *in_tmp, *out_tmp;
34*16d86563SAlexander Pyhalov 	size_t inbytesleft, outbytesleft;
35*16d86563SAlexander Pyhalov 	int fd;
36*16d86563SAlexander Pyhalov 	int i;
37*16d86563SAlexander Pyhalov 	struct stat s;
38*16d86563SAlexander Pyhalov 	struct _icv_state *st;
39*16d86563SAlexander Pyhalov 	if (argc < 2) {
40*16d86563SAlexander Pyhalov 		fprintf(stderr, "Usage: %s input\n", argv[0]);
41*16d86563SAlexander Pyhalov 		exit(-1);
42*16d86563SAlexander Pyhalov 	}
43*16d86563SAlexander Pyhalov 	if ((fd = open(argv[1], O_RDONLY)) == -1) {
44*16d86563SAlexander Pyhalov 		perror("open");
45*16d86563SAlexander Pyhalov 		exit(-2);
46*16d86563SAlexander Pyhalov 	}
47*16d86563SAlexander Pyhalov 	if (fstat(fd, &s) == -1) {
48*16d86563SAlexander Pyhalov 		perror("stat");
49*16d86563SAlexander Pyhalov 		exit(-3);
50*16d86563SAlexander Pyhalov 	}
51*16d86563SAlexander Pyhalov 	inbytesleft = outbytesleft = s.st_size;
52*16d86563SAlexander Pyhalov 	in_tmp = inbuf = (char *)malloc(inbytesleft);
53*16d86563SAlexander Pyhalov 	out_tmp = outbuf = (char *)malloc(outbytesleft);
54*16d86563SAlexander Pyhalov 	if (!inbuf || !outbuf) {
55*16d86563SAlexander Pyhalov 		perror("malloc");
56*16d86563SAlexander Pyhalov 		exit(-1);
57*16d86563SAlexander Pyhalov 	}
58*16d86563SAlexander Pyhalov 	if (read(fd, inbuf, inbytesleft) != inbytesleft) {
59*16d86563SAlexander Pyhalov 		perror("read");
60*16d86563SAlexander Pyhalov 		exit(-4);
61*16d86563SAlexander Pyhalov 	}
62*16d86563SAlexander Pyhalov 	st = (struct _icv_state *)_icv_open();
63*16d86563SAlexander Pyhalov 	if (st == (struct _icv_state *) -1) {
64*16d86563SAlexander Pyhalov 		perror("_icv_open");
65*16d86563SAlexander Pyhalov 		exit(-1);
66*16d86563SAlexander Pyhalov 	}
67*16d86563SAlexander Pyhalov 	if (_icv_iconv(st, &inbuf, &inbytesleft, \
68*16d86563SAlexander Pyhalov 			&outbuf, &outbytesleft) == -1) {
69*16d86563SAlexander Pyhalov 		perror("icv_iconv");
70*16d86563SAlexander Pyhalov 		fprintf(stderr, "\ninbytesleft = %d\n", inbytesleft);
71*16d86563SAlexander Pyhalov 		exit(-2);
72*16d86563SAlexander Pyhalov 	}
73*16d86563SAlexander Pyhalov 	/* Output tbl[] contents. */
74*16d86563SAlexander Pyhalov 	for (i=0; i < s.st_size; i++)
75*16d86563SAlexander Pyhalov 		i == s.st_size-1 ?
76*16d86563SAlexander Pyhalov 			printf("/* 0x%02X */  {  0x%02X, %d  }\n", i, (unsigned char) *(out_tmp+i), sizeof(*(out_tmp+i))) :
77*16d86563SAlexander Pyhalov 			printf("/* 0x%02X */  {  0x%02X, %d  },\n", i, (unsigned char) *(out_tmp+i), sizeof(*(out_tmp+i)));
78*16d86563SAlexander Pyhalov 	free(in_tmp);
79*16d86563SAlexander Pyhalov 	free(out_tmp);
80*16d86563SAlexander Pyhalov 	close(fd);
81*16d86563SAlexander Pyhalov 	_icv_close(st);
82*16d86563SAlexander Pyhalov }
83*16d86563SAlexander Pyhalov #endif	/* DEBUG */
84*16d86563SAlexander Pyhalov #endif	/* DEBUG_C */