Date: Wed, 09 Oct 2002 22:00:54 +0100 From: Tony Finch <dot@dotat.at> To: current@freebsd.org Subject: Re: src/games bikeshed time. Message-ID: <E17zNws-0008G8-00@chiark.greenend.org.uk> In-Reply-To: <E17zJG1-00015D-00@chiark.greenend.org.uk> References: <E17zEpq-0001j7-00@chiark.greenend.org.uk> <E17zEpq-0001j7-00@chiark.greenend.org.uk> <dot@dotat.at> <200210091309.g99D9Rhb012062@grimreaper.grondar.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Mark suggested I might want to frob primes(6) so that it uses uintmax_t, which I have done (see below) but it uses rather too much C99 goodness for -STABLE. Are things like strtoumax likely to be MFCed? Tony. -- f.a.n.finch <dot@dotat.at> http://dotat.at/ BAILEY: SOUTHEASTERLY 5 TO 7. RAIN. MODERATE OR GOOD. --- factor/factor.c 9 Oct 2002 19:55:04 -0000 1.13 +++ factor/factor.c 9 Oct 2002 20:59:22 -0000 @@ -71,6 +71,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <inttypes.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -89,7 +90,7 @@ #else typedef ubig BIGNUM; -typedef u_long BN_ULONG; +typedef ubig BN_ULONG; #define BN_CTX int #define BN_CTX_new() NULL @@ -226,7 +227,7 @@ /* Divide factor out until none are left. */ do { - printf(hflag ? " 0x%lx" : " %lu", *fact); + printf(hflag ? " 0x%jx" : " %ju", *fact); BN_div_word(val, (BN_ULONG)*fact); } while (BN_mod_word(val, (BN_ULONG)*fact) == 0); @@ -321,13 +322,13 @@ static void BN_print_fp(FILE *fp, const BIGNUM *num) { - fprintf(fp, "%lx", (unsigned long)*num); + fprintf(fp, "%jx", *num); } static void BN_print_dec_fp(FILE *fp, const BIGNUM *num) { - fprintf(fp, "%lu", (unsigned long)*num); + fprintf(fp, "%ju", *num); } static int @@ -336,7 +337,7 @@ char *p; errno = 0; - **a = strtoul(str, &p, 10); + **a = strtoumax(str, &p, 10); return (errno == 0 && (*p == '\n' || *p == '\0')); } @@ -346,7 +347,7 @@ char *p; errno = 0; - **a = strtoul(str, &p, 16); + **a = strtoumax(str, &p, 16); return (errno == 0 && (*p == '\n' || *p == '\0')); } --- primes/pattern.c 9 Oct 2002 19:38:55 -0000 1.5 +++ primes/pattern.c 9 Oct 2002 20:59:22 -0000 @@ -54,6 +54,7 @@ * with 1. All non-zero elements are factors of 3, 5, 7, 11 and 13. */ +#include <inttypes.h> #include <stddef.h> #include "primes.h" --- primes/pr_tbl.c 9 Oct 2002 19:38:55 -0000 1.5 +++ primes/pr_tbl.c 9 Oct 2002 20:59:22 -0000 @@ -53,6 +53,7 @@ * and 65537^2 > 2^32-1. */ +#include <inttypes.h> #include <stddef.h> #include "primes.h" --- primes/primes.c 9 Oct 2002 20:42:40 -0000 1.21 +++ primes/primes.c 9 Oct 2002 20:59:22 -0000 @@ -68,6 +68,7 @@ #include <ctype.h> #include <err.h> #include <errno.h> +#include <inttypes.h> #include <limits.h> #include <math.h> #include <stdio.h> @@ -118,7 +119,7 @@ stop = BIG; /* - * Convert low and high args. Strtoul(3) sets errno to + * Convert low and high args. Strtou*(3) sets errno to * ERANGE if the number is too large, but, if there's * a leading minus sign it returns the negation of the * result of the conversion, which we'd rather disallow. @@ -130,14 +131,14 @@ errx(1, "negative numbers aren't permitted."); errno = 0; - start = strtoul(argv[0], &p, 0); + start = strtoumax(argv[0], &p, 0); if (errno) err(1, "%s", argv[0]); if (*p != '\0') errx(1, "%s: illegal numeric format.", argv[0]); errno = 0; - stop = strtoul(argv[1], &p, 0); + stop = strtoumax(argv[1], &p, 0); if (errno) err(1, "%s", argv[1]); if (*p != '\0') @@ -149,7 +150,7 @@ errx(1, "negative numbers aren't permitted."); errno = 0; - start = strtoul(argv[0], &p, 0); + start = strtoumax(argv[0], &p, 0); if (errno) err(1, "%s", argv[0]); if (*p != '\0') @@ -190,7 +191,7 @@ if (*p == '-') errx(1, "negative numbers aren't permitted."); errno = 0; - val = strtoul(buf, &p, 0); + val = strtoumax(buf, &p, 0); if (errno) err(1, "%s", buf); if (*p != '\n') @@ -245,7 +246,7 @@ for (p = &prime[0], factor = prime[0]; factor < stop && p <= pr_limit; factor = *(++p)) { if (factor >= start) { - printf(hflag ? "0x%lx\n" : "%lu\n", factor); + printf(hflag ? "0x%jx\n" : "%ju\n", factor); } } /* return early if we are done */ @@ -308,7 +309,7 @@ */ for (q = table; q < tab_lim; ++q, start+=2) { if (*q) { - printf(hflag ? "0x%lx\n" : "%lu\n", start); + printf(hflag ? "0x%jx\n" : "%ju\n", start); } } } --- primes/primes.h 9 Oct 2002 19:38:55 -0000 1.2 +++ primes/primes.h 9 Oct 2002 20:59:22 -0000 @@ -46,8 +46,8 @@ */ /* ubig is the type that holds a large unsigned value */ -typedef unsigned long ubig; /* must be >=32 bit unsigned value */ -#define BIG ULONG_MAX /* largest value will sieve */ +typedef uintmax_t ubig; /* must be >=32 bit unsigned value */ +#define BIG (~(ubig)0) /* largest value will sieve */ /* bytes in sieve table (must be > 3*5*7*11) */ #define TABSIZE 256*1024 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E17zNws-0008G8-00>