Module Name:    src
Committed By:   christos
Date:           Fri Feb  9 16:18:12 UTC 2024

Modified Files:
        src/sys/arch/hp300/stand/mkboot: mkboot.c

Log Message:
fix usage string, improve error handling.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/hp300/stand/mkboot/mkboot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/hp300/stand/mkboot/mkboot.c
diff -u src/sys/arch/hp300/stand/mkboot/mkboot.c:1.12 src/sys/arch/hp300/stand/mkboot/mkboot.c:1.13
--- src/sys/arch/hp300/stand/mkboot/mkboot.c:1.12	Thu Feb  8 13:10:34 2024
+++ src/sys/arch/hp300/stand/mkboot/mkboot.c	Fri Feb  9 11:18:12 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkboot.c,v 1.12 2024/02/08 18:10:34 christos Exp $	*/
+/*	$NetBSD: mkboot.c,v 1.13 2024/02/09 16:18:12 christos Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -47,7 +47,7 @@ __COPYRIGHT(
 #ifdef notdef
 static char sccsid[] = "@(#)mkboot.c	7.2 (Berkeley) 12/16/90";
 #endif
-__RCSID("$NetBSD: mkboot.c,v 1.12 2024/02/08 18:10:34 christos Exp $");
+__RCSID("$NetBSD: mkboot.c,v 1.13 2024/02/09 16:18:12 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -215,7 +215,7 @@ main(int argc, char **argv)
 	write(to, &lifv, LIF_VOLSIZE);
 	lseek(to, LIF_DIRSTART, SEEK_SET);
 	write(to, lifd, LIF_DIRSIZE);
-	exit(0);
+	return EXIT_SUCCESS;
 }
 
 int
@@ -223,21 +223,18 @@ putfile(char *from, int to)
 {
 	int fd;
 	struct stat statb;
-	int nr;
+	ssize_t nr;
 	void *bp;
 
-	if ((fd = open(from, 0)) < 0) {
-		printf("error: unable to open file %s\n", from);
-		exit(1);
-	}
+	if ((fd = open(from, 0)) < 0)
+		err(EXIT_FAILURE, "Unable to open file `%s'", from);
 	fstat(fd, &statb);
 	ld.address = htobe32(loadpoint);
 	ld.count = htobe32(statb.st_size);
-	bp = malloc(statb.st_size);
-	if ((nr = read(fd, bp, statb.st_size)) < 0) {
-		printf("error: reading from file %s\n", from);
-		exit(1);
-	}
+	if ((bp = malloc(statb.st_size)) == NULL)
+		err(EXIT_FAILURE, "Can't allocate buffer");
+	if (read(fd, bp, statb.st_size) < 0)
+		err(EXIT_FAILURE, "Error reading from file `%s'", from);
 	(void)close(fd);
 	write(to, &ld, sizeof(ld));
 	write(to, bp, statb.st_size);
@@ -249,8 +246,9 @@ void
 usage(void)
 {
 
-	fprintf(stderr, "Usage:	%s -l <loadpoint [-t <timestamp>] prog1 [ prog2 ] outfile\n", getprogname());
-	exit(1);
+	fprintf(stderr, "Usage:	%s -l <loadpoint> [-t <timestamp>] prog1 "
+	    "[ prog2 ] outfile\n", getprogname());
+	exit(EXIT_FAILURE);
 }
 
 char *

Reply via email to