[Midnightbsd-cvs] src [11903] trunk/games/fortune/unstr: sync with freebsd.
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Tue Jul 17 21:05:45 EDT 2018
Revision: 11903
http://svnweb.midnightbsd.org/src/?rev=11903
Author: laffer1
Date: 2018-07-17 21:05:45 -0400 (Tue, 17 Jul 2018)
Log Message:
-----------
sync with freebsd.
Modified Paths:
--------------
trunk/games/fortune/unstr/Makefile
trunk/games/fortune/unstr/unstr.c
Modified: trunk/games/fortune/unstr/Makefile
===================================================================
--- trunk/games/fortune/unstr/Makefile 2018-07-18 01:05:25 UTC (rev 11902)
+++ trunk/games/fortune/unstr/Makefile 2018-07-18 01:05:45 UTC (rev 11903)
@@ -1,10 +1,9 @@
+# $MidnightBSD$
# @(#)Makefile 8.1 (Berkeley) 5/31/93
-# $FreeBSD: src/games/fortune/unstr/Makefile,v 1.7 2005/02/23 20:59:03 ru Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/games/fortune/unstr/Makefile 276486 2014-12-31 23:25:37Z ngie $
PROG= unstr
-NO_MAN=
-WARNS?= 6
+MAN=
CFLAGS+= -I${.CURDIR}/../strfile
.include <bsd.prog.mk>
Modified: trunk/games/fortune/unstr/unstr.c
===================================================================
--- trunk/games/fortune/unstr/unstr.c 2018-07-18 01:05:25 UTC (rev 11902)
+++ trunk/games/fortune/unstr/unstr.c 2018-07-18 01:05:45 UTC (rev 11903)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -13,11 +14,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -46,8 +43,7 @@
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/games/fortune/unstr/unstr.c,v 1.11 2005/02/23 20:59:03 ru Exp $");
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/games/fortune/unstr/unstr.c 301178 2016-06-01 22:39:15Z truckman $");
/*
* This program un-does what "strfile" makes, thereby obtaining the
@@ -62,40 +58,48 @@
* Ken Arnold Aug 13, 1978
*/
-# include <sys/param.h>
-# include <sys/endian.h>
-# include <stdio.h>
-# include <ctype.h>
-# include <err.h>
-# include <stdlib.h>
-# include <string.h>
-# include "strfile.h"
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
-static char *Infile, /* name of input file */
- Datafile[MAXPATHLEN], /* name of data file */
- Delimch; /* delimiter character */
+#include "strfile.h"
+static char *Infile, /* name of input file */
+ Datafile[MAXPATHLEN], /* name of data file */
+ Delimch; /* delimiter character */
+
static FILE *Inf, *Dataf;
static void order_unstr(STRFILE *);
/* ARGSUSED */
-int main(int ac, char **av)
+int
+main(int argc, char *argv[])
{
- static STRFILE tbl; /* description table */
+ static STRFILE tbl; /* description table */
- if (ac != 2) {
- (void)fprintf(stderr, "usage: unstr datafile\n");
+ if (argc != 2) {
+ fprintf(stderr, "usage: unstr datafile\n");
exit(1);
}
- Infile = av[1];
- (void) strcpy(Datafile, Infile);
- (void) strcat(Datafile, ".dat");
+ Infile = argv[1];
+ if ((size_t)snprintf(Datafile, sizeof(Datafile), "%s.dat", Infile) >=
+ sizeof(Datafile))
+ errx(1, "%s name too long", Infile);
if ((Inf = fopen(Infile, "r")) == NULL)
err(1, "%s", Infile);
if ((Dataf = fopen(Datafile, "r")) == NULL)
err(1, "%s", Datafile);
- (void) fread((char *) &tbl, sizeof tbl, 1, Dataf);
+ if (fread((char *)&tbl, sizeof(tbl), 1, Dataf) != 1) {
+ if (feof(Dataf))
+ errx(1, "%s read EOF", Datafile);
+ else
+ err(1, "%s read", Datafile);
+ }
tbl.str_version = be32toh(tbl.str_version);
tbl.str_numstr = be32toh(tbl.str_numstr);
tbl.str_longlen = be32toh(tbl.str_longlen);
@@ -105,25 +109,26 @@
errx(1, "nothing to do -- table in file order");
Delimch = tbl.str_delim;
order_unstr(&tbl);
- (void) fclose(Inf);
- (void) fclose(Dataf);
+ fclose(Inf);
+ fclose(Dataf);
exit(0);
}
-static void order_unstr(STRFILE *tbl)
+static void
+order_unstr(STRFILE *tbl)
{
uint32_t i;
- char *sp;
- off_t pos;
- char buf[BUFSIZ];
+ char *sp;
+ off_t pos;
+ char buf[BUFSIZ];
for (i = 0; i < tbl->str_numstr; i++) {
- (void) fread(&pos, 1, sizeof pos, Dataf);
- (void) fseeko(Inf, be64toh(pos), 0);
+ fread(&pos, 1, sizeof(pos), Dataf);
+ fseeko(Inf, be64toh(pos), SEEK_SET);
if (i != 0)
- (void) printf("%c\n", Delimch);
+ printf("%c\n", Delimch);
for (;;) {
- sp = fgets(buf, sizeof buf, Inf);
+ sp = fgets(buf, sizeof(buf), Inf);
if (sp == NULL || STR_ENDSTRING(sp, *tbl))
break;
else
More information about the Midnightbsd-cvs
mailing list