comparison bootmatch/comp_readbin.c @ 9:bfcc8180cf3c

bootmatch compiler written
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Jun 2023 02:55:29 +0000
parents
children
comparison
equal deleted inserted replaced
8:304ac8119c8a 9:bfcc8180cf3c
1 /*
2 * Bootmatch compiler: here we read the binary file.
3 */
4
5 #include <sys/types.h>
6 #include <sys/file.h>
7 #include <sys/stat.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include "comp_defs.h"
12
13 extern u_char boot_image[BOOT_BLOCK_SIZE];
14
15 void
16 read_bin_file(filename)
17 char *filename;
18 {
19 int fd;
20 struct stat st;
21
22 fd = open(filename, O_RDONLY);
23 if (fd < 0) {
24 perror(filename);
25 exit(1);
26 }
27 fstat(fd, &st);
28 if (!S_ISREG(st.st_mode)) {
29 fprintf(stderr, "error: %s is not a regular file\n", filename);
30 exit(1);
31 }
32 if (st.st_size != BOOT_BLOCK_SIZE) {
33 fprintf(stderr, "error: %s has wrong length\n", filename);
34 exit(1);
35 }
36 read(fd, boot_image, BOOT_BLOCK_SIZE);
37 close(fd);
38 }