xref: /openbsd/sys/dev/microcode/udl/build.c (revision 404b540a)
1 /*	$OpenBSD: build.c,v 1.5 2009/08/26 12:32:27 mglocker Exp $ */
2 
3 /*
4  * Copyright (c) 2009 Marcus Glocker <mglocker@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #include <sys/types.h>
20 
21 #include <err.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 
25 #include "udl_huffman.h"
26 
27 #define FILENAME "udl_huffman"
28 
29 int
30 main(void)
31 {
32 	int fd, i;
33 	uint32_t bit_count;
34 	uint32_t bit_pattern;
35 
36 	fd = open(FILENAME, O_WRONLY | O_CREAT | O_TRUNC, 0644);
37 	if (fd == -1)
38 		err(1, "%s", FILENAME);
39 
40 	for (i = 0; i < UDL_HUFFMAN_RECORDS; i++) {
41 		bit_count = udl_huffman[i].bit_count;
42 		bit_pattern = htobe32(udl_huffman[i].bit_pattern);
43 		if (write(fd, &bit_count, sizeof(bit_count)) == -1)
44 			err(1, "write");
45 		if (write(fd, &bit_pattern, sizeof(bit_pattern)) == -1)
46 			err(1, "write");
47 	}
48 
49 	close(fd);
50 
51 	return (0);
52 }
53