view bootmatch/comp_readbin.c @ 20:aa2fd60a44fb

new shell scripts c11x-gen-fc-{ffs-img,script}
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 10 Jun 2023 23:53:15 +0000
parents bfcc8180cf3c
children
line wrap: on
line source

/*
 * Bootmatch compiler: here we read the binary file.
 */

#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "comp_defs.h"

extern u_char boot_image[BOOT_BLOCK_SIZE];

void
read_bin_file(filename)
	char *filename;
{
	int fd;
	struct stat st;

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		perror(filename);
		exit(1);
	}
	fstat(fd, &st);
	if (!S_ISREG(st.st_mode)) {
		fprintf(stderr, "error: %s is not a regular file\n", filename);
		exit(1);
	}
	if (st.st_size != BOOT_BLOCK_SIZE) {
		fprintf(stderr, "error: %s has wrong length\n", filename);
		exit(1);
	}
	read(fd, boot_image, BOOT_BLOCK_SIZE);
	close(fd);
}