summaryrefslogtreecommitdiffstats
path: root/fortune
diff options
context:
space:
mode:
authorsimonb <simonb@NetBSD.org>1999-08-21 07:02:46 +0000
committersimonb <simonb@NetBSD.org>1999-08-21 07:02:46 +0000
commit9f5f92a0f3b2deed923c1d9c5613fe2dc55e605f (patch)
treed48210e3e87ce7617ea961b9d8cc43db484bccfe /fortune
parente6838d71c5f48786e0e7ce3a0ff47d9b1f71abcf (diff)
downloadbsdgames-darwin-9f5f92a0f3b2deed923c1d9c5613fe2dc55e605f.tar.gz
bsdgames-darwin-9f5f92a0f3b2deed923c1d9c5613fe2dc55e605f.tar.zst
bsdgames-darwin-9f5f92a0f3b2deed923c1d9c5613fe2dc55e605f.zip
Use new endian-specific conversion macros - 64-bit off_t's are now
the stored the same regardess of the byte order of the generating host. Note in the strfile(8) man page that all fields are big-endian, not in network byte order.
Diffstat (limited to 'fortune')
-rw-r--r--fortune/fortune/fortune.c18
-rw-r--r--fortune/strfile/strfile.84
-rw-r--r--fortune/strfile/strfile.c18
-rw-r--r--fortune/strfile/strfile.h15
-rw-r--r--fortune/unstr/unstr.c16
5 files changed, 37 insertions, 34 deletions
diff --git a/fortune/fortune/fortune.c b/fortune/fortune/fortune.c
index 20de41ae..1ed64301 100644
--- a/fortune/fortune/fortune.c
+++ b/fortune/fortune/fortune.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fortune.c,v 1.14 1998/09/13 15:27:28 hubertf Exp $ */
+/* $NetBSD: fortune.c,v 1.15 1999/08/21 07:02:46 simonb Exp $ */
/*-
* Copyright (c) 1986, 1993
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1986, 1993\n\
#if 0
static char sccsid[] = "@(#)fortune.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: fortune.c,v 1.14 1998/09/13 15:27:28 hubertf Exp $");
+__RCSID("$NetBSD: fortune.c,v 1.15 1999/08/21 07:02:46 simonb Exp $");
#endif
#endif /* not lint */
@@ -984,8 +984,8 @@ get_fort()
(void) lseek(fp->datfd,
(off_t) (sizeof fp->tbl + fp->pos * sizeof Seekpts[0]), 0);
read(fp->datfd, Seekpts, sizeof Seekpts);
- Seekpts[0] = ntohl(Seekpts[0]);
- Seekpts[1] = ntohl(Seekpts[1]);
+ BE64TOH(Seekpts[0]);
+ BE64TOH(Seekpts[1]);
}
/*
@@ -1128,11 +1128,11 @@ get_tbl(fp)
if (read(fd, (char *) &fp->tbl, sizeof fp->tbl) != sizeof fp->tbl) {
errx(1, "Database `%s' corrupted", fp->path);
}
- /* fp->tbl.str_version = ntohl(fp->tbl.str_version); */
- fp->tbl.str_numstr = ntohl(fp->tbl.str_numstr);
- fp->tbl.str_longlen = ntohl(fp->tbl.str_longlen);
- fp->tbl.str_shortlen = ntohl(fp->tbl.str_shortlen);
- fp->tbl.str_flags = ntohl(fp->tbl.str_flags);
+ /* BE32TOH(fp->tbl.str_version); */
+ BE32TOH(fp->tbl.str_numstr);
+ BE32TOH(fp->tbl.str_longlen);
+ BE32TOH(fp->tbl.str_shortlen);
+ BE32TOH(fp->tbl.str_flags);
(void) close(fd);
}
else {
diff --git a/fortune/strfile/strfile.8 b/fortune/strfile/strfile.8
index 3f9554e9..96512e3c 100644
--- a/fortune/strfile/strfile.8
+++ b/fortune/strfile/strfile.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: strfile.8,v 1.5 1999/03/22 18:49:11 garbled Exp $
+.\" $NetBSD: strfile.8,v 1.6 1999/08/21 07:02:46 simonb Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -115,7 +115,7 @@ unsigned long str_flags; /* bit field for flags */
char str_delim; /* delimiting character */
.Ed
.Pp
-All fields are written in network byte order.
+All fields are written in big-endian byte order.
.Pp
The purpose of
.Nm unstr
diff --git a/fortune/strfile/strfile.c b/fortune/strfile/strfile.c
index f4ba208e..a27c2711 100644
--- a/fortune/strfile/strfile.c
+++ b/fortune/strfile/strfile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: strfile.c,v 1.8 1998/09/13 15:27:28 hubertf Exp $ */
+/* $NetBSD: strfile.c,v 1.9 1999/08/21 07:02:46 simonb Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)strfile.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: strfile.c,v 1.8 1998/09/13 15:27:28 hubertf Exp $");
+__RCSID("$NetBSD: strfile.c,v 1.9 1999/08/21 07:02:46 simonb Exp $");
#endif
#endif /* not lint */
@@ -244,15 +244,15 @@ main(ac, av)
}
(void) fseek(outf, (off_t) 0, 0);
- Tbl.str_version = htonl(Tbl.str_version);
- Tbl.str_numstr = htonl(Num_pts - 1);
- Tbl.str_longlen = htonl(Tbl.str_longlen);
- Tbl.str_shortlen = htonl(Tbl.str_shortlen);
- Tbl.str_flags = htonl(Tbl.str_flags);
+ HTOBE32(Tbl.str_version);
+ Tbl.str_numstr = htobe32(Num_pts - 1);
+ HTOBE32(Tbl.str_longlen);
+ HTOBE32(Tbl.str_shortlen);
+ HTOBE32(Tbl.str_flags);
(void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf);
if (STORING_PTRS) {
for (p = Seekpts, cnt = Num_pts; cnt--; ++p)
- *p = htonl(*p);
+ HTOBE64(*p);
(void) fwrite((char *) Seekpts, sizeof *Seekpts, (int) Num_pts, outf);
}
(void) fclose(outf);
@@ -334,7 +334,7 @@ add_offset(fp, off)
off_t net;
if (!STORING_PTRS) {
- net = htonl(off);
+ net = htobe64(off);
fwrite(&net, 1, sizeof net, fp);
} else {
ALLOC(Seekpts, Num_pts + 1);
diff --git a/fortune/strfile/strfile.h b/fortune/strfile/strfile.h
index 48efc747..326ccd0d 100644
--- a/fortune/strfile/strfile.h
+++ b/fortune/strfile/strfile.h
@@ -1,4 +1,4 @@
-/* $NetBSD: strfile.h,v 1.3 1995/03/23 08:28:49 cgd Exp $ */
+/* $NetBSD: strfile.h,v 1.4 1999/08/21 07:02:46 simonb Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -38,19 +38,22 @@
* @(#)strfile.h 8.1 (Berkeley) 5/31/93
*/
+#include <sys/types.h>
+#include <sys/endian.h>
+
#define STR_ENDSTRING(line,tbl) \
((line)[0] == (tbl).str_delim && (line)[1] == '\n')
typedef struct { /* information table */
#define VERSION 1
- unsigned long str_version; /* version number */
- unsigned long str_numstr; /* # of strings in the file */
- unsigned long str_longlen; /* length of longest string */
- unsigned long str_shortlen; /* length of shortest string */
+ u_int32_t str_version; /* version number */
+ u_int32_t str_numstr; /* # of strings in the file */
+ u_int32_t str_longlen; /* length of longest string */
+ u_int32_t str_shortlen; /* length of shortest string */
#define STR_RANDOM 0x1 /* randomized pointers */
#define STR_ORDERED 0x2 /* ordered pointers */
#define STR_ROTATED 0x4 /* rot-13'd text */
- unsigned long str_flags; /* bit field for flags */
+ u_int32_t str_flags; /* bit field for flags */
unsigned char stuff[4]; /* long aligned space */
#define str_delim stuff[0] /* delimiting character */
} STRFILE;
diff --git a/fortune/unstr/unstr.c b/fortune/unstr/unstr.c
index 19df3464..8d52fc35 100644
--- a/fortune/unstr/unstr.c
+++ b/fortune/unstr/unstr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: unstr.c,v 1.4 1997/10/11 07:59:09 lukem Exp $ */
+/* $NetBSD: unstr.c,v 1.5 1999/08/21 07:02:46 simonb Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
#if 0
static char sccsid[] = "@(#)unstr.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: unstr.c,v 1.4 1997/10/11 07:59:09 lukem Exp $");
+__RCSID("$NetBSD: unstr.c,v 1.5 1999/08/21 07:02:46 simonb Exp $");
#endif
#endif /* not lint */
@@ -100,11 +100,11 @@ main(ac, av)
if ((Dataf = fopen(Datafile, "r")) == NULL)
err(1, "fopen %s", Datafile);
(void) fread((char *) &tbl, sizeof tbl, 1, Dataf);
- tbl.str_version = ntohl(tbl.str_version);
- tbl.str_numstr = ntohl(tbl.str_numstr);
- tbl.str_longlen = ntohl(tbl.str_longlen);
- tbl.str_shortlen = ntohl(tbl.str_shortlen);
- tbl.str_flags = ntohl(tbl.str_flags);
+ BE32TOH(tbl.str_version);
+ BE32TOH(tbl.str_numstr);
+ BE32TOH(tbl.str_longlen);
+ BE32TOH(tbl.str_shortlen);
+ BE32TOH(tbl.str_flags);
if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) {
fprintf(stderr, "nothing to do -- table in file order\n");
exit(1);
@@ -140,7 +140,7 @@ order_unstr(tbl)
for (i = 0; i < tbl->str_numstr; i++) {
(void) fread((char *) &pos, 1, sizeof pos, Dataf);
- (void) fseek(Inf, ntohl(pos), 0);
+ (void) fseek(Inf, be64toh(pos), 0);
if (i != 0)
(void) printf("%c\n", Delimch);
for (;;) {