summaryrefslogtreecommitdiffstats
path: root/games/fortune/unstr/unstr.c
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2005-02-17 18:06:37 +0000
committerru <ru@FreeBSD.org>2005-02-17 18:06:37 +0000
commit9dda858476944a403f25411651bdfe12a3db08a7 (patch)
tree973270d0bb2aff71d70fbb433a49fb800b26c3ad /games/fortune/unstr/unstr.c
parent89684378a492c804e9a0b98a1cf60ba5a5c6bdd9 (diff)
downloadFreeBSD-src-9dda858476944a403f25411651bdfe12a3db08a7.zip
FreeBSD-src-9dda858476944a403f25411651bdfe12a3db08a7.tar.gz
Make the on-disk format of .dat files produced by strfile(8)
architecture independent. Besides the fixed-width types in the header, the offsets are now stored as 64-bit off_t (also in big endian format). Tested on: i386, amd64, sparc64, ia64
Diffstat (limited to 'games/fortune/unstr/unstr.c')
-rw-r--r--games/fortune/unstr/unstr.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/games/fortune/unstr/unstr.c b/games/fortune/unstr/unstr.c
index 44c7a9f..9246a8e 100644
--- a/games/fortune/unstr/unstr.c
+++ b/games/fortune/unstr/unstr.c
@@ -62,7 +62,7 @@ __FBSDID("$FreeBSD$");
*/
# include <sys/param.h>
-# include <arpa/inet.h>
+# include <sys/endian.h>
# include <stdio.h>
# include <ctype.h>
# include <stdlib.h>
@@ -75,12 +75,10 @@ char *Infile, /* name of input file */
FILE *Inf, *Dataf;
-void getargs(), order_unstr();
+void getargs(char *[]), order_unstr(STRFILE *);
/* ARGSUSED */
-int main(ac, av)
-int ac;
-char **av;
+int main(int ac, char **av)
{
static STRFILE tbl; /* description table */
@@ -94,11 +92,11 @@ char **av;
exit(1);
}
(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);
+ tbl.str_version = be32toh(tbl.str_version);
+ tbl.str_numstr = be32toh(tbl.str_numstr);
+ tbl.str_longlen = be32toh(tbl.str_longlen);
+ tbl.str_shortlen = be32toh(tbl.str_shortlen);
+ tbl.str_flags = be32toh(tbl.str_flags);
if (!(tbl.str_flags & (STR_ORDERED | STR_RANDOM))) {
fprintf(stderr, "nothing to do -- table in file order\n");
exit(1);
@@ -125,14 +123,14 @@ char *av[];
void order_unstr(tbl)
STRFILE *tbl;
{
- int i;
+ uint32_t i;
char *sp;
- long pos;
- char buf[BUFSIZ];
+ off_t pos;
+ char buf[BUFSIZ];
for (i = 0; i < tbl->str_numstr; i++) {
- (void) fread((char *) &pos, 1, sizeof pos, Dataf);
- (void) fseek(Inf, ntohl(pos), 0);
+ (void) fread(&pos, 1, sizeof pos, Dataf);
+ (void) fseeko(Inf, be64toh(pos), 0);
if (i != 0)
(void) printf("%c\n", Delimch);
for (;;) {
OpenPOWER on IntegriCloud