X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/5c8c80051cbc9a51e43e68a907b302554f905b96..897cec3b3cb65e3e1fa957369f64c2b106708d5c:/fortune/strfile/strfile.c?ds=inline diff --git a/fortune/strfile/strfile.c b/fortune/strfile/strfile.c index deb43b55..94bd8308 100644 --- a/fortune/strfile/strfile.c +++ b/fortune/strfile/strfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: strfile.c,v 1.18 2000/01/13 16:20:27 jsm Exp $ */ +/* $NetBSD: strfile.c,v 1.21 2001/07/22 13:34:00 wiz Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -47,7 +47,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.18 2000/01/13 16:20:27 jsm Exp $"); +__RCSID("$NetBSD: strfile.c,v 1.21 2001/07/22 13:34:00 wiz Exp $"); #endif #endif /* not lint */ #endif /* __NetBSD__ */ @@ -70,8 +70,23 @@ __RCSID("$NetBSD: strfile.c,v 1.18 2000/01/13 16:20:27 jsm Exp $"); # define MAXPATHLEN 1024 # endif /* MAXPATHLEN */ +u_int32_t +h2nl(u_int32_t h) +{ + unsigned char c[4]; + u_int32_t rv; + + c[0] = (h >> 24) & 0xff; + c[1] = (h >> 16) & 0xff; + c[2] = (h >> 8) & 0xff; + c[3] = (h >> 0) & 0xff; + memcpy(&rv, c, sizeof rv); + + return (rv); +} + /* - * This program takes a file composed of strings seperated by + * This program takes a file composed of strings separated by * lines starting with two consecutive delimiting character (default * character is '%') and creates another file which consists of a table * describing the file (structure from "strfile.h"), a table of seek @@ -101,9 +116,9 @@ __RCSID("$NetBSD: strfile.c,v 1.18 2000/01/13 16:20:27 jsm Exp $"); # define ALLOC(ptr,sz) do { \ if (ptr == NULL) \ - ptr = malloc((unsigned int) (CHUNKSIZE * sizeof *ptr)); \ + ptr = malloc(CHUNKSIZE * sizeof *ptr); \ else if (((sz) + 1) % CHUNKSIZE == 0) \ - ptr = realloc((void *) ptr, ((unsigned int) ((sz) + CHUNKSIZE) * sizeof *ptr)); \ + ptr = realloc(ptr, ((sz) + CHUNKSIZE) * sizeof *ptr); \ if (ptr == NULL) \ die("out of space"); \ } while (0) @@ -246,18 +261,18 @@ main(ac, av) puts("There was 1 string"); else printf("There were %d strings\n", (int)(Num_pts - 1)); - printf("Longest string: %lu byte%s\n", Tbl.str_longlen, + printf("Longest string: %lu byte%s\n", (unsigned long)Tbl.str_longlen, Tbl.str_longlen == 1 ? "" : "s"); - printf("Shortest string: %lu byte%s\n", Tbl.str_shortlen, + printf("Shortest string: %lu byte%s\n", (unsigned long)Tbl.str_shortlen, Tbl.str_shortlen == 1 ? "" : "s"); } (void) fseek(outf, (off_t) 0, SEEK_SET); - 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); + Tbl.str_version = h2nl(Tbl.str_version); + Tbl.str_numstr = h2nl(Num_pts - 1); + Tbl.str_longlen = h2nl(Tbl.str_longlen); + Tbl.str_shortlen = h2nl(Tbl.str_shortlen); + Tbl.str_flags = h2nl(Tbl.str_flags); (void) fwrite((char *) &Tbl, sizeof Tbl, 1, outf); if (STORING_PTRS) { for (p = Seekpts, cnt = Num_pts; cnt--; ++p)