Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/fortune/unstr Simplify, little KNF
details: https://anonhg.NetBSD.org/src/rev/83a7dbfd3e2f
branches: trunk
changeset: 1009681:83a7dbfd3e2f
user: christos <christos%NetBSD.org@localhost>
date: Thu Apr 30 12:40:11 2020 +0000
description:
Simplify, little KNF
diffstat:
games/fortune/unstr/unstr.c | 44 ++++++++++++++++++++++----------------------
1 files changed, 22 insertions(+), 22 deletions(-)
diffs (88 lines):
diff -r 79b95fb60935 -r 83a7dbfd3e2f games/fortune/unstr/unstr.c
--- a/games/fortune/unstr/unstr.c Thu Apr 30 12:35:01 2020 +0000
+++ b/games/fortune/unstr/unstr.c Thu Apr 30 12:40:11 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $ */
+/* $NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: unstr.c,v 1.15 2020/04/29 21:00:42 nia Exp $");
+__RCSID("$NetBSD: unstr.c,v 1.16 2020/04/30 12:40:11 christos Exp $");
#endif
#endif /* not lint */
@@ -59,19 +59,19 @@
* Ken Arnold Aug 13, 1978
*/
-# include <sys/types.h>
-# include <sys/param.h>
-# include <sys/endian.h>
-# include <ctype.h>
-# include <err.h>
-# include <stdio.h>
-# include <stdlib.h>
-# include <string.h>
-# include "strfile.h"
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "strfile.h"
-# ifndef MAXPATHLEN
-# define MAXPATHLEN 1024
-# endif /* MAXPATHLEN */
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif /* MAXPATHLEN */
char *Infile, /* name of input file */
Datafile[MAXPATHLEN], /* name of data file */
@@ -91,9 +91,9 @@
getargs(av);
if ((Inf = fopen(Infile, "r")) == NULL)
- err(1, "fopen %s", Infile);
+ err(EXIT_FAILURE, "fopen %s", Infile);
if ((Dataf = fopen(Datafile, "r")) == NULL)
- err(1, "fopen %s", Datafile);
+ err(EXIT_FAILURE, "fopen %s", Datafile);
(void) fread((char *) &tbl, sizeof tbl, 1, Dataf);
BE32TOH(tbl.str_version);
BE32TOH(tbl.str_numstr);
@@ -108,19 +108,19 @@
order_unstr(&tbl);
(void) fclose(Inf);
(void) fclose(Dataf);
- exit(0);
+ return EXIT_SUCCESS;
}
void
getargs(char *av[])
{
- if (!*++av || (strlen(*av) + sizeof(".dat")) > sizeof(Datafile)) {
- (void) fprintf(stderr, "usage: unstr datafile\n");
- exit(1);
+ if (!*++av ||
+ (size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) >
+ sizeof(Datafile)) {
+ (void) fprintf(stderr, "Usage: %s datafile\n", getprogname());
+ exit(EXIT_FAILURE);
}
Infile = *av;
- (void) strcpy(Datafile, Infile);
- (void) strcat(Datafile, ".dat");
}
void
Home |
Main Index |
Thread Index |
Old Index