?RCS: $Id: d_strtoul.U,v 3.0.1.1 1997/02/28 15:46:43 ram Exp $ ?RCS: ?RCS: Copyright (c) 1996, Andy Dougherty ?RCS: Copyright (c) 1991-1993, Raphael Manfredi ?RCS: ?RCS: You may redistribute only under the terms of the Artistic License, ?RCS: as specified in the README file that comes with the distribution. ?RCS: You may reuse parts of this distribution only within the terms of ?RCS: that same Artistic License; a copy of which may be found at the root ?RCS: of the source tree for dist 3.0. ?RCS: ?RCS: $Log: d_strtoul.U,v $ ?RCS: Revision 3.0.1.1 1997/02/28 15:46:43 ram ?RCS: patch61: created ?RCS: ?RCS: ?MAKE:d_strtoul: Inlibc cat longsize Compile run ?MAKE: -pick add $@ %< ?S:d_strtoul: ?S: This variable conditionally defines the HAS_STRTOUL symbol, which ?S: indicates to the C program that the strtoul() routine is available ?S: to provide conversion of strings to unsigned long. ?S:. ?C:HAS_STRTOUL (STRTOUL): ?C: This symbol, if defined, indicates that the strtoul routine is ?C: available to provide conversion of strings to unsigned long. ?C:. ?H:#$d_strtoul HAS_STRTOUL /**/ ?H:. ?F:!try : see if strtoul exists set strtoul d_strtoul eval $inlibc case "$d_strtoul" in "$define") $cat <try.c <<'EOCP' #include #include #include static int bad = 0; void check(const char *s, unsigned long eul, int een) { unsigned long gul; errno = 0; gul = strtoul(s, 0, 10); if (!((gul == eul) && (errno == een))) bad++; } int main() { check(" 1", 1L, 0); check(" 0", 0L, 0); EOCP case "$longsize" in 8) $cat >>try.c <<'EOCP' check("18446744073709551615", 18446744073709551615UL, 0); check("18446744073709551616", 18446744073709551615UL, ERANGE); #if 0 /* strtoul() for /^-/ strings is undefined. */ check("-1", 18446744073709551615UL, 0); check("-18446744073709551614", 2, 0); check("-18446744073709551615", 1, 0); check("-18446744073709551616", 18446744073709551615UL, ERANGE); check("-18446744073709551617", 18446744073709551615UL, ERANGE); #endif EOCP ;; 4) $cat >>try.c <<'EOCP' check("4294967295", 4294967295UL, 0); check("4294967296", 4294967295UL, ERANGE); #if 0 /* strtoul() for /^-/ strings is undefined. */ check("-1", 4294967295UL, 0); check("-4294967294", 2, 0); check("-4294967295", 1, 0); check("-4294967296", 4294967295UL, ERANGE); check("-4294967297", 4294967295UL, ERANGE); #endif EOCP ;; *) : Should we write these tests to be more portable by sprintf-ing : ~0 and then manipulating that char string as input for strtol? ;; esac $cat >>try.c <<'EOCP' if (!bad) printf("ok\n"); return 0; } EOCP set try if eval $compile; then case "`$run ./try`" in ok) echo "Your strtoul() seems to be working okay." ;; *) cat <&4 Your strtoul() doesn't seem to be working okay. EOM d_strtoul="$undef" ;; esac else echo "(I can't seem to compile the test program--assuming it doesn't)" d_strtoul="$undef" fi ;; esac