err(1, to_file);
err(1, "%s", to_file);
putfile(from_file, to)	char *from_file;	int to;{	struct exec ex;	register int n, total;	char buf[2048];	int from, check_sum = 0;	struct lif_load load;	if ((from = open(from_file, O_RDONLY)) < 0)		err(1, from_file);	n = read(from, &ex, sizeof(ex));	if (n != sizeof(ex))		err(1, "%s: reading file header", from_file);	entry = ex.a_entry;	if (N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC)		entry += sizeof(ex);	else if (IS_ELF(*(Elf32_Ehdr *)&ex)) {		Elf32_Ehdr elf_header;		Elf32_Phdr *elf_segments;		int i,header_count, memory_needed, elf_load_image_segment;		(void) lseek(from, 0, SEEK_SET);		n = read(from, &elf_header, sizeof (elf_header));		if (n != sizeof (elf_header))			err(1, "%s: reading ELF header", from_file);		header_count = ntohs(elf_header.e_phnum);		memory_needed = header_count * sizeof (Elf32_Phdr);		elf_segments = (Elf32_Phdr *)malloc(memory_needed);		if (elf_segments == NULL)			err(1, "malloc");		(void) lseek(from, ntohl(elf_header.e_phoff), SEEK_SET);		n = read(from, elf_segments, memory_needed);		if (n != memory_needed)			err(1, "%s: reading ELF segments", from_file);		elf_load_image_segment = -1;		for (i = 0; i < header_count; i++) {			if (elf_segments[i].p_filesz &&			    ntohl(elf_segments[i].p_flags) & PF_X) {				if (elf_load_image_segment != -1)					errx(1, "%s: more than one ELF program segment", from_file);				elf_load_image_segment = i;			}			if (elf_load_image_segment == -1)				errx(1, "%s: no suitable ELF program segment", from_file);		}		entry = ntohl(elf_header.e_entry) +			ntohl(elf_segments[elf_load_image_segment].p_offset) -			ntohl(elf_segments[elf_load_image_segment].p_vaddr);	} else if (*(u_char *)&ex == 0x1f && ((u_char *)&ex)[1] == 0x8b) {		entry = 0;	} else		errx(1, "%s: bad magic number\n", from_file);	entry += sizeof(load);	lseek(to, sizeof(load), SEEK_CUR);	total = 0;	n = sizeof(buf) - sizeof(load);	/* copy the whole file */	for (lseek(from, 0, 0); ; n = sizeof(buf)) {		bzero(buf, sizeof(buf));		if ((n = read(from, buf, n)) < 0)			err(1, from_file);		else if (n == 0)			break;		if (write(to, buf, n) != n)			err(1, to_file);		total += n;		check_sum = cksum(check_sum, (int *)buf, n);	}	/* load header */	load.address = htobe32(loadpoint + sizeof(load));	load.count = htobe32(4 + total);	check_sum = cksum(check_sum, (int *)&load, sizeof(load));	if (verbose)		warnx("wrote %d bytes of file \'%s\'", total, from_file);	total += sizeof(load);	/* insert the header */	lseek(to, -total, SEEK_CUR);	if (write(to, &load, sizeof(load)) != sizeof(load))		err(1, to_file);	lseek(to, total - sizeof(load), SEEK_CUR);	bzero(buf, sizeof(buf));	/* pad to int */	n = sizeof(int) - total % sizeof(int);	if (total % sizeof(int)) {		if (write(to, buf, n) != n)			err(1, to_file);		else			total += n;	}	/* pad to the blocksize */	n = sizeof(buf) - total % sizeof(buf);	if (n < sizeof(int)) {		n += sizeof(buf);		total += sizeof(buf);	} else		total += n;	/* TODO should pad here to the 65k boundary for tape boot */	if (verbose)		warnx("checksum is 0x%08x", -check_sum);	check_sum = htobe32(-check_sum);	if (write(to, &check_sum, sizeof(int)) != sizeof(int))		err(1, to_file);	n -= sizeof(int);	if (write(to, buf, n) != n)		err(1, to_file);	if (close(from) < 0 )		err(1, from_file);	return total;}