This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / d_strtouq.U
1 ?RCS: $Id$
2 ?RCS:
3 ?RCS: Copyright (c) 2000 Jarkko Hietaniemi
4 ?RCS:
5 ?RCS: You may distribute under the terms of either the GNU General Public
6 ?RCS: License or the Artistic License, as specified in the README file.
7 ?RCS:
8 ?MAKE:d_strtouq: Inlibc cat Compile run
9 ?MAKE:  -pick add $@ %<
10 ?S:d_strtouq:
11 ?S:     This variable conditionally defines the HAS_STRTOUQ symbol, which
12 ?S:     indicates to the C program that the strtouq() routine is available.
13 ?S:.
14 ?C:HAS_STRTOUQ:
15 ?C:     This symbol, if defined, indicates that the strtouq routine is
16 ?C:     available to convert strings to unsigned long longs (quads).
17 ?C:.
18 ?H:#$d_strtouq HAS_STRTOUQ              /**/
19 ?H:.
20 ?F:!try
21 : see if strtouq exists
22 set strtouq d_strtouq
23 eval $inlibc
24
25 case "$d_strtouq" in
26 "$define")
27         $cat <<EOM
28 Checking whether your strtouq() works okay...
29 EOM
30         $cat >try.c <<'EOCP'
31 #include <errno.h>
32 #include <stdio.h>
33 extern unsigned long long int strtouq(char *s, char **, int);
34 static int bad = 0;
35 void check(char *s, unsigned long long eull, int een) {
36         unsigned long long gull;
37         errno = 0;
38         gull = strtouq(s, 0, 10);
39         if (!((gull == eull) && (errno == een)))
40                 bad++;
41 }
42 int main() {
43         check(" 1",                                        1LL, 0);
44         check(" 0",                                        0LL, 0);
45         check("18446744073709551615",  18446744073709551615ULL, 0);
46         check("18446744073709551616",  18446744073709551615ULL, ERANGE);
47 #if 0 /* strtouq() for /^-/ strings is undefined. */
48         check("-1",                    18446744073709551615ULL, 0);
49         check("-18446744073709551614",                     2LL, 0);
50         check("-18446744073709551615",                     1LL, 0);
51         check("-18446744073709551616", 18446744073709551615ULL, ERANGE);
52         check("-18446744073709551617", 18446744073709551615ULL, ERANGE);
53 #endif
54         if (!bad)
55                 printf("ok\n");
56         return 0;
57 }
58 EOCP
59         set try
60         if eval $compile; then
61                 case "`$run ./try`" in
62                 ok) echo "Your strtouq() seems to be working okay." ;;
63                 *) cat <<EOM >&4
64 Your strtouq() doesn't seem to be working okay.
65 EOM
66                    d_strtouq="$undef"
67                    ;;
68                 esac
69         else
70                 echo "(I can't seem to compile the test program--assuming it doesn't)"
71                 d_strtouq="$undef"
72         fi
73         ;;
74 esac
75