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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*16d86563SAlexander Pyhalov  */
24*16d86563SAlexander Pyhalov 
25*16d86563SAlexander Pyhalov #include <stdio.h>
26*16d86563SAlexander Pyhalov #include <stdlib.h>
27*16d86563SAlexander Pyhalov #include <errno.h>
28*16d86563SAlexander Pyhalov #include <sys/fcntl.h>
29*16d86563SAlexander Pyhalov #include <sys/stat.h>
30*16d86563SAlexander Pyhalov 
main(int argc,char ** argv)31*16d86563SAlexander Pyhalov int main(int argc, char ** argv) {
32*16d86563SAlexander Pyhalov 	char *inbuf;
33*16d86563SAlexander Pyhalov 	size_t inbytesleft;
34*16d86563SAlexander Pyhalov 	int fd, i;
35*16d86563SAlexander Pyhalov 	struct stat s;
36*16d86563SAlexander Pyhalov 
37*16d86563SAlexander Pyhalov 	if (argc < 2) {
38*16d86563SAlexander Pyhalov 		fprintf(stderr, "Usage: %s input\n", argv[0]);
39*16d86563SAlexander Pyhalov 		exit(-1);
40*16d86563SAlexander Pyhalov 	}
41*16d86563SAlexander Pyhalov 	if ((fd = open(argv[1], O_RDONLY)) == -1) {
42*16d86563SAlexander Pyhalov 		perror("open");
43*16d86563SAlexander Pyhalov 		exit(-2);
44*16d86563SAlexander Pyhalov 	}
45*16d86563SAlexander Pyhalov 	if (fstat(fd, &s) == -1) {
46*16d86563SAlexander Pyhalov 		perror("stat");
47*16d86563SAlexander Pyhalov 		exit(-3);
48*16d86563SAlexander Pyhalov 	}
49*16d86563SAlexander Pyhalov 	inbytesleft = s.st_size;
50*16d86563SAlexander Pyhalov 	inbuf = (char *)malloc(inbytesleft);
51*16d86563SAlexander Pyhalov 	if (read(fd, inbuf, inbytesleft) != inbytesleft) {
52*16d86563SAlexander Pyhalov 		perror("read");
53*16d86563SAlexander Pyhalov 		exit(-4);
54*16d86563SAlexander Pyhalov 	}
55*16d86563SAlexander Pyhalov 	/* Output tbl[] contents. */
56*16d86563SAlexander Pyhalov 	for (i = 0; i < s.st_size; i++)
57*16d86563SAlexander Pyhalov 		i == s.st_size-1 ?
58*16d86563SAlexander Pyhalov 			printf("/* 0x%02X */  {  0x%02X, %d  }\n",  i, \
59*16d86563SAlexander Pyhalov 			    (unsigned char) *(inbuf+i), sizeof (*(inbuf+i))) :
60*16d86563SAlexander Pyhalov 			printf("/* 0x%02X */  {  0x%02X, %d  },\n", i, \
61*16d86563SAlexander Pyhalov 			    (unsigned char) *(inbuf+i), sizeof (*(inbuf+i)));
62*16d86563SAlexander Pyhalov 	free(inbuf);
63*16d86563SAlexander Pyhalov 	close(fd);
64*16d86563SAlexander Pyhalov }
65