Commit | Line | Data |
---|---|---|
6e4a03c9 JH |
1 | ?RCS: $Id: d_strtoul.U,v 3.0.1.1 1997/02/28 15:46:43 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1996, Andy Dougherty | |
4 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
0065f4af | 5 | ?RCS: |
65a32477 | 6 | ?RCS: You may redistribute only under the terms of the Artistic License, |
6e4a03c9 JH |
7 | ?RCS: as specified in the README file that comes with the distribution. |
8 | ?RCS: You may reuse parts of this distribution only within the terms of | |
65a32477 | 9 | ?RCS: that same Artistic License; a copy of which may be found at the root |
6e4a03c9 JH |
10 | ?RCS: of the source tree for dist 3.0. |
11 | ?RCS: | |
12 | ?RCS: $Log: d_strtoul.U,v $ | |
13 | ?RCS: Revision 3.0.1.1 1997/02/28 15:46:43 ram | |
14 | ?RCS: patch61: created | |
15 | ?RCS: | |
16 | ?RCS: | |
0f00356b | 17 | ?MAKE:d_strtoul: Inlibc cat longsize Compile run |
6e4a03c9 JH |
18 | ?MAKE: -pick add $@ %< |
19 | ?S:d_strtoul: | |
20 | ?S: This variable conditionally defines the HAS_STRTOUL symbol, which | |
21 | ?S: indicates to the C program that the strtoul() routine is available | |
22 | ?S: to provide conversion of strings to unsigned long. | |
23 | ?S:. | |
24 | ?C:HAS_STRTOUL (STRTOUL): | |
25 | ?C: This symbol, if defined, indicates that the strtoul routine is | |
26 | ?C: available to provide conversion of strings to unsigned long. | |
27 | ?C:. | |
28 | ?H:#$d_strtoul HAS_STRTOUL /**/ | |
29 | ?H:. | |
0065f4af | 30 | ?F:!try |
6e4a03c9 JH |
31 | : see if strtoul exists |
32 | set strtoul d_strtoul | |
33 | eval $inlibc | |
34 | ||
35 | case "$d_strtoul" in | |
36 | "$define") | |
37 | $cat <<EOM | |
38 | Checking whether your strtoul() works okay... | |
39 | EOM | |
40 | $cat >try.c <<'EOCP' | |
41 | #include <errno.h> | |
42 | #include <stdio.h> | |
d6e05143 | 43 | #include <stdlib.h> |
6e4a03c9 | 44 | static int bad = 0; |
d6e05143 | 45 | void check(const char *s, unsigned long eul, int een) { |
6e4a03c9 JH |
46 | unsigned long gul; |
47 | errno = 0; | |
48 | gul = strtoul(s, 0, 10); | |
49 | if (!((gul == eul) && (errno == een))) | |
50 | bad++; | |
51 | } | |
52 | int main() { | |
53 | check(" 1", 1L, 0); | |
54 | check(" 0", 0L, 0); | |
55 | EOCP | |
56 | case "$longsize" in | |
57 | 8) | |
58 | $cat >>try.c <<'EOCP' | |
17490216 JH |
59 | check("18446744073709551615", 18446744073709551615UL, 0); |
60 | check("18446744073709551616", 18446744073709551615UL, ERANGE); | |
357ef92f | 61 | #if 0 /* strtoul() for /^-/ strings is undefined. */ |
17490216 | 62 | check("-1", 18446744073709551615UL, 0); |
6e4a03c9 JH |
63 | check("-18446744073709551614", 2, 0); |
64 | check("-18446744073709551615", 1, 0); | |
ed194ea0 | 65 | check("-18446744073709551616", 18446744073709551615UL, ERANGE); |
17490216 | 66 | check("-18446744073709551617", 18446744073709551615UL, ERANGE); |
357ef92f | 67 | #endif |
6e4a03c9 JH |
68 | EOCP |
69 | ;; | |
70 | 4) | |
71 | $cat >>try.c <<'EOCP' | |
72 | check("4294967295", 4294967295UL, 0); | |
73 | check("4294967296", 4294967295UL, ERANGE); | |
357ef92f | 74 | #if 0 /* strtoul() for /^-/ strings is undefined. */ |
6e4a03c9 JH |
75 | check("-1", 4294967295UL, 0); |
76 | check("-4294967294", 2, 0); | |
77 | check("-4294967295", 1, 0); | |
ed194ea0 | 78 | check("-4294967296", 4294967295UL, ERANGE); |
6e4a03c9 | 79 | check("-4294967297", 4294967295UL, ERANGE); |
357ef92f | 80 | #endif |
6e4a03c9 JH |
81 | EOCP |
82 | ;; | |
83 | *) | |
84 | : Should we write these tests to be more portable by sprintf-ing | |
85 | : ~0 and then manipulating that char string as input for strtol? | |
86 | ;; | |
87 | esac | |
88 | $cat >>try.c <<'EOCP' | |
89 | if (!bad) | |
90 | printf("ok\n"); | |
91 | return 0; | |
92 | } | |
93 | EOCP | |
94 | set try | |
95 | if eval $compile; then | |
0f00356b | 96 | case "`$run ./try`" in |
6e4a03c9 JH |
97 | ok) echo "Your strtoul() seems to be working okay." ;; |
98 | *) cat <<EOM >&4 | |
99 | Your strtoul() doesn't seem to be working okay. | |
100 | EOM | |
101 | d_strtoul="$undef" | |
102 | ;; | |
103 | esac | |
ee6ec6d2 MB |
104 | else |
105 | echo "(I can't seem to compile the test program--assuming it doesn't)" | |
106 | d_strtoul="$undef" | |
6e4a03c9 JH |
107 | fi |
108 | ;; | |
109 | esac | |
110 |