Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/fortune/strfile Simplify, errors to stderr.
details: https://anonhg.NetBSD.org/src/rev/ca900779741d
branches: trunk
changeset: 1009679:ca900779741d
user: christos <christos%NetBSD.org@localhost>
date: Thu Apr 30 12:32:26 2020 +0000
description:
Simplify, errors to stderr.
diffstat:
games/fortune/strfile/strfile.c | 35 ++++++++++++++++++-----------------
1 files changed, 18 insertions(+), 17 deletions(-)
diffs (89 lines):
diff -r 9896f3d750c1 -r ca900779741d games/fortune/strfile/strfile.c
--- a/games/fortune/strfile/strfile.c Thu Apr 30 12:32:16 2020 +0000
+++ b/games/fortune/strfile/strfile.c Thu Apr 30 12:32:26 2020 +0000
@@ -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 @@
#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 @@
#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 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 @@
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());
Home |
Main Index |
Thread Index |
Old Index