Module Name:    src
Committed By:   christos
Date:           Thu Apr 30 12:32:26 UTC 2020

Modified Files:
        src/games/fortune/strfile: strfile.c

Log Message:
Simplify, errors to stderr.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/games/fortune/strfile/strfile.c

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

Modified files:

Index: src/games/fortune/strfile/strfile.c
diff -u src/games/fortune/strfile/strfile.c:1.39 src/games/fortune/strfile/strfile.c:1.40
--- src/games/fortune/strfile/strfile.c:1.39	Wed Apr 29 16:45:05 2020
+++ src/games/fortune/strfile/strfile.c	Thu Apr 30 08:32:26 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $	*/
+/*	$NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)strfile.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: strfile.c,v 1.39 2020/04/29 20:45:05 nia Exp $");
+__RCSID("$NetBSD: strfile.c,v 1.40 2020/04/30 12:32:26 christos Exp $");
 #endif
 #endif /* not lint */
 #endif /* __NetBSD__ */
@@ -55,6 +55,7 @@ __RCSID("$NetBSD: strfile.c,v 1.39 2020/
 #include <sys/types.h>
 #include <sys/param.h>
 #include <ctype.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -131,7 +132,7 @@ static STR *Firstch;			/* first chars of
 
 static uint32_t h2nl(uint32_t h);
 static void getargs(int argc, char **argv);
-static void usage(void) __dead;
+static void usage(const char *, ...) __dead __printflike(1, 2);
 static void add_offset(FILE *fp, off_t off);
 static void do_order(void);
 static int cmp_str(const void *vp1, const void *vp2);
@@ -295,39 +296,39 @@ getargs(int argc, char **argv)
 			break;
 		case '?':
 		default:
-			usage();
+			usage(NULL);
 		}
 	argv += optind;
 
 	if (*argv) {
 		Infile = *argv;
 		if (*++argv) {
-			len = strlen(*argv);
+			len = strlcpy(Outfile, *argv, sizeof(Outfile));
 			if (len >= sizeof(Outfile)) {
-				puts("Bad output filename");
-				usage();
+				usage("Too long output filename");
 			}
-			(void) memcpy(Outfile, *argv, len + 1);
 		}
 	}
 	if (!Infile) {
-		puts("No input file name");
-		usage();
+		usage("No input file name");
 	}
 	if (*Outfile == '\0') {
-		len = strlen(Infile) + sizeof(".dat");
-		if (len > sizeof(Outfile)) {
-			puts("Bad input filename");
-			usage();
+		len = snprintf(Outfile, sizeof(Outfile), "%s.dat", Infile);
+		if (len >= sizeof(Outfile)) {
+			usage("Too long input filename");
 		}
-		(void) strcpy(Outfile, Infile);
-		(void) strcat(Outfile, ".dat");
 	}
 }
 
 static void
-usage(void)
+usage(const char *fmt, ...)
 {
+	if (fmt) {
+		va_list ap;
+		va_start(ap, fmt);
+		vwarnx(fmt, ap);
+		va_end(ap);
+	}
 	(void) fprintf(stderr,
 	    "Usage: %s [-iorsx] [-c char] sourcefile [datafile]\n",
 	    getprogname());

Reply via email to