diff options
Diffstat (limited to 'src/regress/lib/libc')
154 files changed, 13256 insertions, 369 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index 7b65e2c1c5..24749b95b4 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile | |||
@@ -1,6 +1,11 @@ | |||
1 | # $NetBSD: Makefile,v 1.6 1995/04/24 05:52:15 cgd Exp $ | 1 | # $OpenBSD: Makefile,v 1.33 2011/07/02 18:12:48 martynas Exp $ |
2 | |||
3 | SUBDIR+= _setjmp alloca atexit basename cxa-atexit db dirname fnmatch | ||
4 | SUBDIR+= fpclassify getaddrinfo getcap getopt_long glob hsearch longjmp | ||
5 | SUBDIR+= locale malloc netdb popen printf regex setjmp setjmp-signal | ||
6 | SUBDIR+= sigreturn sigsetjmp sprintf strerror strtod strtonum telldir time vis | ||
7 | SUBDIR+= orientation stdio_threading mkstemp env cephes | ||
2 | 8 | ||
3 | SUBDIR+= _setjmp db regex setjmp sigsetjmp | ||
4 | .if (${MACHINE_ARCH} != "vax") | 9 | .if (${MACHINE_ARCH} != "vax") |
5 | SUBDIR+= ieeefp | 10 | SUBDIR+= ieeefp |
6 | .endif | 11 | .endif |
@@ -9,8 +14,6 @@ SUBDIR+= ieeefp | |||
9 | SUBDIR+= arch/${MACHINE_ARCH} | 14 | SUBDIR+= arch/${MACHINE_ARCH} |
10 | .endif | 15 | .endif |
11 | 16 | ||
12 | regress: _SUBDIRUSE | ||
13 | |||
14 | install: | 17 | install: |
15 | 18 | ||
16 | .include <bsd.subdir.mk> | 19 | .include <bsd.subdir.mk> |
diff --git a/src/regress/lib/libc/_setjmp/Makefile b/src/regress/lib/libc/_setjmp/Makefile index c2b9dc1aae..5d58242523 100644 --- a/src/regress/lib/libc/_setjmp/Makefile +++ b/src/regress/lib/libc/_setjmp/Makefile | |||
@@ -1,16 +1,11 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
1 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:38:44 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:38:44 cgd Exp $ |
2 | 3 | ||
3 | PROG= _setjmptest | 4 | PROG= _setjmptest |
4 | SRCS= jmptest.c | 5 | SRCS= jmptest.c |
5 | NOMAN= noman, no way, man | ||
6 | 6 | ||
7 | CFLAGS+= -DTEST_U_SETJMP | 7 | CFLAGS+= -DTEST_U_SETJMP |
8 | 8 | ||
9 | .PATH: ${.CURDIR}/../setjmp | 9 | .PATH: ${.CURDIR}/../setjmp |
10 | 10 | ||
11 | install: | 11 | .include <bsd.regress.mk> |
12 | |||
13 | regress: ${PROG} | ||
14 | ./${PROG} | ||
15 | |||
16 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/alloca/Makefile b/src/regress/lib/libc/alloca/Makefile new file mode 100644 index 0000000000..f31417cda7 --- /dev/null +++ b/src/regress/lib/libc/alloca/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/02/12 06:49:04 mickey Exp $ | ||
2 | |||
3 | PROG= alloca | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/alloca/alloca.c b/src/regress/lib/libc/alloca/alloca.c new file mode 100644 index 0000000000..54fa90edae --- /dev/null +++ b/src/regress/lib/libc/alloca/alloca.c | |||
@@ -0,0 +1,21 @@ | |||
1 | /* $OpenBSD: alloca.c,v 1.7 2004/03/10 01:17:45 deraadt Exp $ */ | ||
2 | |||
3 | /* Written by Michael Shalayeff, 2003, Public Domain. */ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | |||
9 | int | ||
10 | main(int argc, char *argv[]) | ||
11 | { | ||
12 | char *q, *p; | ||
13 | |||
14 | p = alloca(41); | ||
15 | strlcpy(p, "hellow world", 41); | ||
16 | |||
17 | q = alloca(53); | ||
18 | strlcpy(q, "hellow world", 53); | ||
19 | |||
20 | exit(strcmp(p, q)); | ||
21 | } | ||
diff --git a/src/regress/lib/libc/arch/alpha/Makefile b/src/regress/lib/libc/arch/alpha/Makefile index b79a82b0e2..8c4dfb735c 100644 --- a/src/regress/lib/libc/arch/alpha/Makefile +++ b/src/regress/lib/libc/arch/alpha/Makefile | |||
@@ -1,10 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/02/23 01:25:11 art Exp $ | ||
1 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:31 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:31 cgd Exp $ |
2 | 3 | ||
3 | # do nothing here; none of the tests here can be run automatically | 4 | # do nothing here; none of the tests here can be run automatically |
4 | SUBDIR= | 5 | SUBDIR= |
5 | 6 | ||
6 | regress: _SUBDIRUSE | ||
7 | |||
8 | install: | 7 | install: |
9 | 8 | ||
10 | .include <bsd.subdir.mk> | 9 | .include <bsd.subdir.mk> |
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/Makefile b/src/regress/lib/libc/arch/alpha/divremtest/Makefile index bd3b12f537..1da3ac8494 100644 --- a/src/regress/lib/libc/arch/alpha/divremtest/Makefile +++ b/src/regress/lib/libc/arch/alpha/divremtest/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2001/01/29 02:05:39 niklas Exp $ | ||
1 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:34 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.1 1995/04/24 05:53:34 cgd Exp $ |
2 | 3 | ||
3 | PROG= divremtest | 4 | PROG= divremtest |
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c index fcf64c9384..3d9e8a6de2 100644 --- a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c +++ b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: divremtest.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
1 | /* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */ | 2 | /* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */ |
2 | 3 | ||
3 | /* | 4 | /* |
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c index 65ca17af4c..fcb4765b8c 100644 --- a/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c +++ b/src/regress/lib/libc/arch/alpha/divremtest/mkcases.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: mkcases.c,v 1.2 2001/01/29 02:05:39 niklas Exp $ */ | ||
1 | /* $NetBSD: mkcases.c,v 1.1 1995/04/24 05:53:36 cgd Exp $ */ | 2 | /* $NetBSD: mkcases.c,v 1.1 1995/04/24 05:53:36 cgd Exp $ */ |
2 | 3 | ||
3 | /* | 4 | /* |
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c index ef02d61d70..3b01653f32 100644 --- a/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c +++ b/src/regress/lib/libc/arch/alpha/divremtest/mktestcases.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: mktestcases.c,v 1.2 2001/01/29 02:05:40 niklas Exp $ */ | ||
1 | /* $NetBSD: mktestcases.c,v 1.1 1995/04/24 05:53:37 cgd Exp $ */ | 2 | /* $NetBSD: mktestcases.c,v 1.1 1995/04/24 05:53:37 cgd Exp $ */ |
2 | 3 | ||
3 | /* | 4 | /* |
diff --git a/src/regress/lib/libc/atexit/Makefile b/src/regress/lib/libc/atexit/Makefile new file mode 100644 index 0000000000..c14b3c7ac4 --- /dev/null +++ b/src/regress/lib/libc/atexit/Makefile | |||
@@ -0,0 +1,16 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2003/07/31 22:46:59 david Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=atexit_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | CLEANFILES+= invalid.out valid.out | ||
7 | |||
8 | run-regress-atexit_test: ${PROG} | ||
9 | ./${PROG} -valid 2>${.OBJDIR}/valid.out | ||
10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
11 | ./${PROG} -invalid-atexit 2>${.OBJDIR}/invalid.out | ||
12 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
13 | ./${PROG} -invalid-cleanup 2>${.OBJDIR}/invalid.out | ||
14 | cmp -s ${.OBJDIR}/invalid.out ${.CURDIR}/invalid.ok | ||
15 | |||
16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/atexit/atexit_test.c b/src/regress/lib/libc/atexit/atexit_test.c new file mode 100644 index 0000000000..3dd0b62c3e --- /dev/null +++ b/src/regress/lib/libc/atexit/atexit_test.c | |||
@@ -0,0 +1,140 @@ | |||
1 | /* $OpenBSD: atexit_test.c,v 1.6 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2002 Daniel Hartmeier | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | * | ||
31 | * Effort sponsored in part by the Defense Advanced Research Projects | ||
32 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
33 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. | ||
34 | * | ||
35 | */ | ||
36 | |||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <string.h> | ||
40 | #include <signal.h> | ||
41 | #include "stdlib/atexit.h" | ||
42 | |||
43 | void handle_first(void); | ||
44 | void handle_middle(void); | ||
45 | void handle_last(void); | ||
46 | void handle_invalid(void); | ||
47 | void handle_cleanup(void); | ||
48 | void handle_signal(int); | ||
49 | |||
50 | static int counter; | ||
51 | |||
52 | int | ||
53 | main(int argc, char *argv[]) | ||
54 | { | ||
55 | int i; | ||
56 | |||
57 | if (argc != 2 || (strcmp(argv[1], "-valid") && | ||
58 | strcmp(argv[1], "-invalid-atexit") && | ||
59 | strcmp(argv[1], "-invalid-cleanup"))) { | ||
60 | fprintf(stderr, "%s -valid/-invalid-atexit/-invalid-cleanup\n", | ||
61 | argv[0]); | ||
62 | return (1); | ||
63 | } | ||
64 | fprintf(stderr, "main()\n"); | ||
65 | if (atexit(handle_last)) { | ||
66 | perror("atexit(handle_last) failed"); | ||
67 | return (1); | ||
68 | } | ||
69 | for (i = 0; i < 65535; ++i) { | ||
70 | if (atexit(handle_middle)) { | ||
71 | perror("atexit(handle_middle) failed"); | ||
72 | return (1); | ||
73 | } | ||
74 | } | ||
75 | if (atexit(handle_first)) { | ||
76 | perror("atexit(handle_first) failed"); | ||
77 | return (1); | ||
78 | } | ||
79 | /* this is supposed to segfault */ | ||
80 | if (!strcmp(argv[1], "-invalid-atexit")) { | ||
81 | signal(SIGSEGV, handle_signal); | ||
82 | __atexit->fns[0].fn_ptr.std_func = handle_invalid; | ||
83 | } else if (!strcmp(argv[1], "-invalid-cleanup")) { | ||
84 | struct atexit *p = __atexit; | ||
85 | |||
86 | signal(SIGSEGV, handle_signal); | ||
87 | while (p != NULL && p->next != NULL) | ||
88 | p = p->next; | ||
89 | if (p == NULL) | ||
90 | fprintf(stderr, "p == NULL, no page found\n"); | ||
91 | p->fns[0].fn_ptr.std_func = handle_invalid; | ||
92 | } | ||
93 | __atexit_register_cleanup(handle_cleanup); | ||
94 | counter = 0; | ||
95 | fprintf(stderr, "main() returns\n"); | ||
96 | return (0); | ||
97 | } | ||
98 | |||
99 | void | ||
100 | handle_first(void) | ||
101 | { | ||
102 | fprintf(stderr, "handle_first() counter == %i\n", counter); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | handle_middle(void) | ||
107 | { | ||
108 | counter++; | ||
109 | } | ||
110 | |||
111 | void | ||
112 | handle_last(void) | ||
113 | { | ||
114 | fprintf(stderr, "handle_last() counter == %i\n", counter); | ||
115 | } | ||
116 | |||
117 | void | ||
118 | handle_cleanup(void) | ||
119 | { | ||
120 | fprintf(stderr, "handle_cleanup()\n"); | ||
121 | } | ||
122 | |||
123 | void | ||
124 | handle_invalid(void) | ||
125 | { | ||
126 | fprintf(stderr, "handle_invalid() THIS SHOULD HAVE SEGFAULTED INSTEAD!\n"); | ||
127 | } | ||
128 | |||
129 | void | ||
130 | handle_signal(int sigraised) | ||
131 | { | ||
132 | switch (sigraised) { | ||
133 | case SIGSEGV: | ||
134 | fprintf(stderr, "SIGSEGV\n"); | ||
135 | exit(0); | ||
136 | default: | ||
137 | fprintf(stderr, "unexpected signal caught\n"); | ||
138 | exit(1); | ||
139 | } | ||
140 | } | ||
diff --git a/src/regress/lib/libc/atexit/invalid.ok b/src/regress/lib/libc/atexit/invalid.ok new file mode 100644 index 0000000000..98cbf8c1de --- /dev/null +++ b/src/regress/lib/libc/atexit/invalid.ok | |||
@@ -0,0 +1,4 @@ | |||
1 | main() | ||
2 | SIGSEGV | ||
3 | handle_first() counter == 0 | ||
4 | handle_last() counter == 65535 | ||
diff --git a/src/regress/lib/libc/atexit/valid.ok b/src/regress/lib/libc/atexit/valid.ok new file mode 100644 index 0000000000..6509e827a7 --- /dev/null +++ b/src/regress/lib/libc/atexit/valid.ok | |||
@@ -0,0 +1,5 @@ | |||
1 | main() | ||
2 | main() returns | ||
3 | handle_first() counter == 0 | ||
4 | handle_last() counter == 65535 | ||
5 | handle_cleanup() | ||
diff --git a/src/regress/lib/libc/basename/Makefile b/src/regress/lib/libc/basename/Makefile new file mode 100644 index 0000000000..958b06fd11 --- /dev/null +++ b/src/regress/lib/libc/basename/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | PROG=basename_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/basename/basename_test.c b/src/regress/lib/libc/basename/basename_test.c new file mode 100644 index 0000000000..34e138c726 --- /dev/null +++ b/src/regress/lib/libc/basename/basename_test.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
3 | * | ||
4 | * Public domain. | ||
5 | */ | ||
6 | |||
7 | #include <sys/param.h> | ||
8 | |||
9 | #include <libgen.h> | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <limits.h> | ||
13 | #include <errno.h> | ||
14 | |||
15 | int | ||
16 | main(void) | ||
17 | { | ||
18 | char path[2 * MAXPATHLEN]; | ||
19 | const char *dir = "junk/"; | ||
20 | const char *fname = "file.name.ext"; | ||
21 | char *str; | ||
22 | int i; | ||
23 | |||
24 | /* Test normal functioning */ | ||
25 | strlcpy(path, "/", sizeof(path)); | ||
26 | strlcat(path, dir, sizeof(path)); | ||
27 | strlcat(path, fname, sizeof(path)); | ||
28 | str = basename(path); | ||
29 | if (strcmp(str, fname) != 0) | ||
30 | goto fail; | ||
31 | |||
32 | /* | ||
33 | * There are four states that require special handling: | ||
34 | * | ||
35 | * 1) path is NULL | ||
36 | * 2) path is the empty string | ||
37 | * 3) path is composed entirely of slashes | ||
38 | * 4) the resulting name is larger than MAXPATHLEN | ||
39 | * | ||
40 | * The first two cases require that a pointer | ||
41 | * to the string "." be returned. | ||
42 | * | ||
43 | * The third case requires that a pointer | ||
44 | * to the string "/" be returned. | ||
45 | * | ||
46 | * The final case requires that NULL be returned | ||
47 | * and errno * be set to ENAMETOOLONG. | ||
48 | */ | ||
49 | /* Case 1 */ | ||
50 | str = basename(NULL); | ||
51 | if (strcmp(str, ".") != 0) | ||
52 | goto fail; | ||
53 | |||
54 | /* Case 2 */ | ||
55 | strlcpy(path, "", sizeof(path)); | ||
56 | str = basename(path); | ||
57 | if (strcmp(str, ".") != 0) | ||
58 | goto fail; | ||
59 | |||
60 | /* Case 3 */ | ||
61 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
62 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
63 | str = basename(path); | ||
64 | if (strcmp(str, "/") != 0) | ||
65 | goto fail; | ||
66 | |||
67 | /* Case 4 */ | ||
68 | strlcpy(path, "/", sizeof(path)); | ||
69 | strlcat(path, dir, sizeof(path)); | ||
70 | for (i = 0; i <= MAXPATHLEN; i += sizeof(fname)) | ||
71 | strlcat(path, fname, sizeof(path)); | ||
72 | str = basename(path); | ||
73 | if (str != NULL || errno != ENAMETOOLONG) | ||
74 | goto fail; | ||
75 | |||
76 | return (0); | ||
77 | fail: | ||
78 | return (1); | ||
79 | } | ||
diff --git a/src/regress/lib/libc/cephes/Makefile b/src/regress/lib/libc/cephes/Makefile new file mode 100644 index 0000000000..75cc85f4a8 --- /dev/null +++ b/src/regress/lib/libc/cephes/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2011/07/02 18:11:01 martynas Exp $ | ||
2 | |||
3 | PROG = ieetst | ||
4 | SRCS = drand.c econst.c eexp.c elog.c epow.c etanh.c etodec.c ieee.c \ | ||
5 | ieetst.c mtherr.c | ||
6 | |||
7 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cephes/drand.c b/src/regress/lib/libc/cephes/drand.c new file mode 100644 index 0000000000..7f7000b4e8 --- /dev/null +++ b/src/regress/lib/libc/cephes/drand.c | |||
@@ -0,0 +1,174 @@ | |||
1 | /* $OpenBSD: drand.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* drand.c | ||
20 | * | ||
21 | * Pseudorandom number generator | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * double y, drand(); | ||
28 | * | ||
29 | * drand( &y ); | ||
30 | * | ||
31 | * | ||
32 | * | ||
33 | * DESCRIPTION: | ||
34 | * | ||
35 | * Yields a random number 1.0 <= y < 2.0. | ||
36 | * | ||
37 | * The three-generator congruential algorithm by Brian | ||
38 | * Wichmann and David Hill (BYTE magazine, March, 1987, | ||
39 | * pp 127-8) is used. The period, given by them, is | ||
40 | * 6953607871644. | ||
41 | * | ||
42 | * Versions invoked by the different arithmetic compile | ||
43 | * time options DEC, IBMPC, and MIEEE, produce | ||
44 | * approximately the same sequences, differing only in the | ||
45 | * least significant bits of the numbers. The UNK option | ||
46 | * implements the algorithm as recommended in the BYTE | ||
47 | * article. It may be used on all computers. However, | ||
48 | * the low order bits of a double precision number may | ||
49 | * not be adequately random, and may vary due to arithmetic | ||
50 | * implementation details on different computers. | ||
51 | * | ||
52 | * The other compile options generate an additional random | ||
53 | * integer that overwrites the low order bits of the double | ||
54 | * precision number. This reduces the period by a factor of | ||
55 | * two but tends to overcome the problems mentioned. | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include "mconf.h" | ||
60 | |||
61 | |||
62 | /* Three-generator random number algorithm | ||
63 | * of Brian Wichmann and David Hill | ||
64 | * BYTE magazine, March, 1987 pp 127-8 | ||
65 | * | ||
66 | * The period, given by them, is (p-1)(q-1)(r-1)/4 = 6.95e12. | ||
67 | */ | ||
68 | |||
69 | static int sx = 1; | ||
70 | static int sy = 10000; | ||
71 | static int sz = 3000; | ||
72 | |||
73 | static union { | ||
74 | double d; | ||
75 | unsigned short s[4]; | ||
76 | } unkans; | ||
77 | |||
78 | /* This function implements the three | ||
79 | * congruential generators. | ||
80 | */ | ||
81 | |||
82 | static int ranwh() | ||
83 | { | ||
84 | int r, s; | ||
85 | |||
86 | /* sx = sx * 171 mod 30269 */ | ||
87 | r = sx/177; | ||
88 | s = sx - 177 * r; | ||
89 | sx = 171 * s - 2 * r; | ||
90 | if( sx < 0 ) | ||
91 | sx += 30269; | ||
92 | |||
93 | |||
94 | /* sy = sy * 172 mod 30307 */ | ||
95 | r = sy/176; | ||
96 | s = sy - 176 * r; | ||
97 | sy = 172 * s - 35 * r; | ||
98 | if( sy < 0 ) | ||
99 | sy += 30307; | ||
100 | |||
101 | /* sz = 170 * sz mod 30323 */ | ||
102 | r = sz/178; | ||
103 | s = sz - 178 * r; | ||
104 | sz = 170 * s - 63 * r; | ||
105 | if( sz < 0 ) | ||
106 | sz += 30323; | ||
107 | /* The results are in static sx, sy, sz. */ | ||
108 | return 0; | ||
109 | } | ||
110 | |||
111 | /* drand.c | ||
112 | * | ||
113 | * Random double precision floating point number between 1 and 2. | ||
114 | * | ||
115 | * C callable: | ||
116 | * drand( &x ); | ||
117 | */ | ||
118 | |||
119 | int drand( a ) | ||
120 | double *a; | ||
121 | { | ||
122 | unsigned short r; | ||
123 | #ifdef DEC | ||
124 | unsigned short s, t; | ||
125 | #endif | ||
126 | |||
127 | /* This algorithm of Wichmann and Hill computes a floating point | ||
128 | * result: | ||
129 | */ | ||
130 | ranwh(); | ||
131 | unkans.d = sx/30269.0 + sy/30307.0 + sz/30323.0; | ||
132 | r = unkans.d; | ||
133 | unkans.d -= r; | ||
134 | unkans.d += 1.0; | ||
135 | |||
136 | /* if UNK option, do nothing further. | ||
137 | * Otherwise, make a random 16 bit integer | ||
138 | * to overwrite the least significant word | ||
139 | * of unkans. | ||
140 | */ | ||
141 | #ifdef UNK | ||
142 | /* do nothing */ | ||
143 | #else | ||
144 | ranwh(); | ||
145 | r = sx * sy + sz; | ||
146 | #endif | ||
147 | |||
148 | #ifdef DEC | ||
149 | /* To make the numbers as similar as possible | ||
150 | * in all arithmetics, the random integer has | ||
151 | * to be inserted 3 bits higher up in a DEC number. | ||
152 | * An alternative would be put it 3 bits lower down | ||
153 | * in all the other number types. | ||
154 | */ | ||
155 | s = unkans.s[2]; | ||
156 | t = s & 07; /* save these bits to put in at the bottom */ | ||
157 | s &= 0177770; | ||
158 | s |= (r >> 13) & 07; | ||
159 | unkans.s[2] = s; | ||
160 | t |= r << 3; | ||
161 | unkans.s[3] = t; | ||
162 | #endif | ||
163 | |||
164 | #ifdef IBMPC | ||
165 | unkans.s[0] = r; | ||
166 | #endif | ||
167 | |||
168 | #ifdef MIEEE | ||
169 | unkans.s[3] = r; | ||
170 | #endif | ||
171 | |||
172 | *a = unkans.d; | ||
173 | return 0; | ||
174 | } | ||
diff --git a/src/regress/lib/libc/cephes/econst.c b/src/regress/lib/libc/cephes/econst.c new file mode 100644 index 0000000000..4232059e4c --- /dev/null +++ b/src/regress/lib/libc/cephes/econst.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* $OpenBSD: econst.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* econst.c */ | ||
20 | /* e type constants used by high precision check routines */ | ||
21 | |||
22 | #include "ehead.h" | ||
23 | |||
24 | |||
25 | #if NE == 10 | ||
26 | /* 0.0 */ | ||
27 | unsigned short ezero[NE] = | ||
28 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
29 | 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,}; | ||
30 | |||
31 | /* 5.0E-1 */ | ||
32 | unsigned short ehalf[NE] = | ||
33 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
34 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,}; | ||
35 | |||
36 | /* 1.0E0 */ | ||
37 | unsigned short eone[NE] = | ||
38 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
39 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,}; | ||
40 | |||
41 | /* 2.0E0 */ | ||
42 | unsigned short etwo[NE] = | ||
43 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
44 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,}; | ||
45 | |||
46 | /* 3.2E1 */ | ||
47 | unsigned short e32[NE] = | ||
48 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
49 | 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,}; | ||
50 | |||
51 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
52 | unsigned short elog2[NE] = | ||
53 | {0x40f3, 0xf6af, 0x03f2, 0xb398, | ||
54 | 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,}; | ||
55 | |||
56 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
57 | unsigned short esqrt2[NE] = | ||
58 | {0x1d6f, 0xbe9f, 0x754a, 0x89b3, | ||
59 | 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,}; | ||
60 | |||
61 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
62 | unsigned short epi[NE] = | ||
63 | {0x2902, 0x1cd1, 0x80dc, 0x628b, | ||
64 | 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,}; | ||
65 | |||
66 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
67 | unsigned short eeul[NE] = { | ||
68 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
69 | |||
70 | #else | ||
71 | |||
72 | /* 0.0 */ | ||
73 | unsigned short ezero[NE] = { | ||
74 | 0, 0000000,0000000,0000000,0000000,0000000,}; | ||
75 | /* 5.0E-1 */ | ||
76 | unsigned short ehalf[NE] = { | ||
77 | 0, 0000000,0000000,0000000,0100000,0x3ffe,}; | ||
78 | /* 1.0E0 */ | ||
79 | unsigned short eone[NE] = { | ||
80 | 0, 0000000,0000000,0000000,0100000,0x3fff,}; | ||
81 | /* 2.0E0 */ | ||
82 | unsigned short etwo[NE] = { | ||
83 | 0, 0000000,0000000,0000000,0100000,0040000,}; | ||
84 | /* 3.2E1 */ | ||
85 | unsigned short e32[NE] = { | ||
86 | 0, 0000000,0000000,0000000,0100000,0040004,}; | ||
87 | /* 6.93147180559945309417232121458176568075500134360255E-1 */ | ||
88 | unsigned short elog2[NE] = { | ||
89 | 0xc9e4,0x79ab,0150717,0013767,0130562,0x3ffe,}; | ||
90 | /* 1.41421356237309504880168872420969807856967187537695E0 */ | ||
91 | unsigned short esqrt2[NE] = { | ||
92 | 0x597e,0x6484,0174736,0171463,0132404,0x3fff,}; | ||
93 | /* 2/sqrt(PI) = | ||
94 | * 1.12837916709551257389615890312154517168810125865800E0 */ | ||
95 | unsigned short eoneopi[NE] = { | ||
96 | 0x71d5,0x688d,0012333,0135202,0110156,0x3fff,}; | ||
97 | /* 3.14159265358979323846264338327950288419716939937511E0 */ | ||
98 | unsigned short epi[NE] = { | ||
99 | 0xc4c6,0xc234,0020550,0155242,0144417,0040000,}; | ||
100 | /* 5.7721566490153286060651209008240243104215933593992E-1 */ | ||
101 | unsigned short eeul[NE] = { | ||
102 | 0xd1be,0xc7a4,0076660,0063743,0111704,0x3ffe,}; | ||
103 | #endif | ||
104 | extern unsigned short ezero[]; | ||
105 | extern unsigned short ehalf[]; | ||
106 | extern unsigned short eone[]; | ||
107 | extern unsigned short etwo[]; | ||
108 | extern unsigned short e32[]; | ||
109 | extern unsigned short elog2[]; | ||
110 | extern unsigned short esqrt2[]; | ||
111 | extern unsigned short eoneopi[]; | ||
112 | extern unsigned short epi[]; | ||
113 | extern unsigned short eeul[]; | ||
114 | |||
diff --git a/src/regress/lib/libc/cephes/eexp.c b/src/regress/lib/libc/cephes/eexp.c new file mode 100644 index 0000000000..74f0d6adb3 --- /dev/null +++ b/src/regress/lib/libc/cephes/eexp.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* $OpenBSD: eexp.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xexp.c */ | ||
20 | /* exponential function check routine */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | |||
24 | #include "ehead.h" | ||
25 | |||
26 | void eexp( x, y ) | ||
27 | unsigned short *x, *y; | ||
28 | { | ||
29 | unsigned short num[NE], den[NE], x2[NE]; | ||
30 | long i; | ||
31 | unsigned short sign, expchk; | ||
32 | |||
33 | /* range reduction theory: x = i + f, 0<=f<1; | ||
34 | * e**x = e**i * e**f | ||
35 | * e**i = 2**(i/log 2). | ||
36 | * Let i/log2 = i1 + f1, 0<=f1<1. | ||
37 | * Then e**i = 2**i1 * 2**f1, so | ||
38 | * e**x = 2**i1 * e**(log 2 * f1) * e**f. | ||
39 | */ | ||
40 | if( ecmp(x, ezero) == 0 ) | ||
41 | { | ||
42 | emov( eone, y ); | ||
43 | return; | ||
44 | } | ||
45 | emov(x, x2); | ||
46 | expchk = x2[NE-1]; | ||
47 | sign = expchk & 0x8000; | ||
48 | x2[NE-1] &= 0x7fff; | ||
49 | |||
50 | /* Test for excessively large argument */ | ||
51 | expchk &= 0x7fff; | ||
52 | if( expchk > (EXONE + 15) ) | ||
53 | { | ||
54 | eclear( y ); | ||
55 | if( sign == 0 ) | ||
56 | einfin( y ); | ||
57 | return; | ||
58 | } | ||
59 | |||
60 | eifrac( x2, &i, num ); /* x = i + f */ | ||
61 | |||
62 | if( i != 0 ) | ||
63 | { | ||
64 | ltoe( &i, den ); /* floating point i */ | ||
65 | ediv( elog2, den, den ); /* i/log 2 */ | ||
66 | eifrac( den, &i, den ); /* i/log 2 = i1 + f1 */ | ||
67 | emul( elog2, den, den ); /* log 2 * f1 */ | ||
68 | eadd( den, num, x2 ); /* log 2 * f1 + f */ | ||
69 | } | ||
70 | |||
71 | /*x2[NE-1] -= 1;*/ | ||
72 | eldexp( x2, -1L, x2 ); /* divide by 2 */ | ||
73 | etanh( x2, x2 ); /* tanh( x/2 ) */ | ||
74 | eadd( x2, eone, num ); /* 1 + tanh */ | ||
75 | eneg( x2 ); | ||
76 | eadd( x2, eone, den ); /* 1 - tanh */ | ||
77 | ediv( den, num, y ); /* (1 + tanh)/(1 - tanh) */ | ||
78 | |||
79 | /*y[NE-1] += i;*/ | ||
80 | if( sign ) | ||
81 | { | ||
82 | ediv( y, eone, y ); | ||
83 | i = -i; | ||
84 | } | ||
85 | eldexp( y, i, y ); /* multiply by 2**i */ | ||
86 | } | ||
diff --git a/src/regress/lib/libc/cephes/ehead.h b/src/regress/lib/libc/cephes/ehead.h new file mode 100644 index 0000000000..009bcf89cc --- /dev/null +++ b/src/regress/lib/libc/cephes/ehead.h | |||
@@ -0,0 +1,59 @@ | |||
1 | /* $OpenBSD: ehead.h,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Include file for extended precision arithmetic programs. | ||
20 | */ | ||
21 | |||
22 | /* Number of 16 bit words in external x type format */ | ||
23 | #define NE 10 | ||
24 | |||
25 | /* Number of 16 bit words in internal format */ | ||
26 | #define NI (NE+3) | ||
27 | |||
28 | /* Array offset to exponent */ | ||
29 | #define E 1 | ||
30 | |||
31 | /* Array offset to high guard word */ | ||
32 | #define M 2 | ||
33 | |||
34 | /* Number of bits of precision */ | ||
35 | #define NBITS ((NI-4)*16) | ||
36 | |||
37 | /* Maximum number of decimal digits in ASCII conversion | ||
38 | * = NBITS*log10(2) | ||
39 | */ | ||
40 | #define NDEC (NBITS*8/27) | ||
41 | |||
42 | /* The exponent of 1.0 */ | ||
43 | #define EXONE (0x3fff) | ||
44 | |||
45 | void eadd(), esub(), emul(), ediv(); | ||
46 | int ecmp(), enormlz(), eshift(); | ||
47 | void eshup1(), eshup8(), eshup6(), eshdn1(), eshdn8(), eshdn6(); | ||
48 | void eabs(), eneg(), emov(), eclear(), einfin(), efloor(); | ||
49 | void eldexp(), efrexp(), eifrac(), ltoe(); | ||
50 | void esqrt(), elog(), eexp(), etanh(), epow(); | ||
51 | void asctoe(), asctoe24(), asctoe53(), asctoe64(); | ||
52 | void etoasc(), e24toasc(), e53toasc(), e64toasc(); | ||
53 | void etoe64(), etoe53(), etoe24(), e64toe(), e53toe(), e24toe(); | ||
54 | int mtherr(); | ||
55 | extern unsigned short ezero[], ehalf[], eone[], etwo[]; | ||
56 | extern unsigned short elog2[], esqrt2[]; | ||
57 | |||
58 | |||
59 | /* by Stephen L. Moshier. */ | ||
diff --git a/src/regress/lib/libc/cephes/elog.c b/src/regress/lib/libc/cephes/elog.c new file mode 100644 index 0000000000..079cc754f4 --- /dev/null +++ b/src/regress/lib/libc/cephes/elog.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* $OpenBSD: elog.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xlog.c */ | ||
20 | /* natural logarithm */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | #include "mconf.h" | ||
24 | #include "ehead.h" | ||
25 | |||
26 | |||
27 | |||
28 | void elog( x, y ) | ||
29 | unsigned short *x, *y; | ||
30 | { | ||
31 | unsigned short xx[NE], z[NE], a[NE], b[NE], t[NE], qj[NE]; | ||
32 | long ex; | ||
33 | int fex; | ||
34 | |||
35 | |||
36 | if( x[NE-1] & (unsigned short )0x8000 ) | ||
37 | { | ||
38 | eclear(y); | ||
39 | mtherr( "elog", DOMAIN ); | ||
40 | return; | ||
41 | } | ||
42 | if( ecmp( x, ezero ) == 0 ) | ||
43 | { | ||
44 | einfin( y ); | ||
45 | eneg(y); | ||
46 | mtherr( "elog", SING ); | ||
47 | return; | ||
48 | } | ||
49 | if( ecmp( x, eone ) == 0 ) | ||
50 | { | ||
51 | eclear( y ); | ||
52 | return; | ||
53 | } | ||
54 | |||
55 | /* range reduction: log x = log( 2**ex * m ) = ex * log2 + log m */ | ||
56 | efrexp( x, &fex, xx ); | ||
57 | /* | ||
58 | emov(x, xx ); | ||
59 | ex = xx[NX-1] & 0x7fff; | ||
60 | ex -= 0x3ffe; | ||
61 | xx[NX-1] = 0x3ffe; | ||
62 | */ | ||
63 | |||
64 | /* Adjust range to 1/sqrt(2), sqrt(2) */ | ||
65 | esqrt2[NE-1] -= 1; | ||
66 | if( ecmp( xx, esqrt2 ) < 0 ) | ||
67 | { | ||
68 | fex -= 1; | ||
69 | emul( xx, etwo, xx ); | ||
70 | } | ||
71 | esqrt2[NE-1] += 1; | ||
72 | |||
73 | esub( eone, xx, a ); | ||
74 | if( a[NE-1] == 0 ) | ||
75 | { | ||
76 | eclear( y ); | ||
77 | goto logdon; | ||
78 | } | ||
79 | eadd( eone, xx, b ); | ||
80 | ediv( b, a, y ); /* store (x-1)/(x+1) in y */ | ||
81 | |||
82 | emul( y, y, z ); | ||
83 | |||
84 | emov( eone, a ); | ||
85 | emov( eone, b ); | ||
86 | emov( eone, qj ); | ||
87 | do | ||
88 | { | ||
89 | eadd( etwo, qj, qj ); /* 2 * i + 1 */ | ||
90 | emul( z, a, a ); | ||
91 | ediv( qj, a, t ); | ||
92 | eadd( t, b, b ); | ||
93 | } | ||
94 | while( ((b[NE-1] & 0x7fff) - (t[NE-1] & 0x7fff)) < NBITS ); | ||
95 | |||
96 | |||
97 | emul( b, y, y ); | ||
98 | emul( y, etwo, y ); | ||
99 | |||
100 | logdon: | ||
101 | |||
102 | /* now add log of 2**ex */ | ||
103 | if( fex != 0 ) | ||
104 | { | ||
105 | ex = fex; | ||
106 | ltoe( &ex, b ); | ||
107 | emul( elog2, b, b ); | ||
108 | eadd( b, y, y ); | ||
109 | } | ||
110 | } | ||
diff --git a/src/regress/lib/libc/cephes/epow.c b/src/regress/lib/libc/cephes/epow.c new file mode 100644 index 0000000000..646268fce7 --- /dev/null +++ b/src/regress/lib/libc/cephes/epow.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* $OpenBSD: epow.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* epow.c */ | ||
20 | /* power function: z = x**y */ | ||
21 | /* by Stephen L. Moshier. */ | ||
22 | |||
23 | |||
24 | #include "ehead.h" | ||
25 | |||
26 | extern int rndprc; | ||
27 | void epowi(); | ||
28 | |||
29 | void epow( x, y, z ) | ||
30 | unsigned short *x, *y, *z; | ||
31 | { | ||
32 | unsigned short w[NE]; | ||
33 | int rndsav; | ||
34 | long li; | ||
35 | |||
36 | efloor( y, w ); | ||
37 | if( ecmp(y,w) == 0 ) | ||
38 | { | ||
39 | eifrac( y, &li, w ); | ||
40 | if( li < 0 ) | ||
41 | li = -li; | ||
42 | if( (li < 0x7fffffff) && (li != 0x80000000) ) | ||
43 | { | ||
44 | epowi( x, y, z ); | ||
45 | return; | ||
46 | } | ||
47 | } | ||
48 | /* z = exp( y * log(x) ) */ | ||
49 | rndsav = rndprc; | ||
50 | rndprc = NBITS; | ||
51 | elog( x, w ); | ||
52 | emul( y, w, w ); | ||
53 | eexp( w, z ); | ||
54 | rndprc = rndsav; | ||
55 | emul( eone, z, z ); | ||
56 | } | ||
57 | |||
58 | |||
59 | /* y is integer valued. */ | ||
60 | |||
61 | void epowi( x, y, z ) | ||
62 | unsigned short x[], y[], z[]; | ||
63 | { | ||
64 | unsigned short w[NE]; | ||
65 | long li, lx; | ||
66 | unsigned long lu; | ||
67 | int rndsav; | ||
68 | unsigned short signx; | ||
69 | /* unsigned short signy; */ | ||
70 | |||
71 | rndsav = rndprc; | ||
72 | eifrac( y, &li, w ); | ||
73 | if( li < 0 ) | ||
74 | lx = -li; | ||
75 | else | ||
76 | lx = li; | ||
77 | |||
78 | if( (lx == 0x7fffffff) || (lx == 0x80000000) ) | ||
79 | { | ||
80 | epow( x, y, z ); | ||
81 | goto done; | ||
82 | } | ||
83 | |||
84 | if( (x[NE-1] & (unsigned short )0x7fff) == 0 ) | ||
85 | { | ||
86 | if( li == 0 ) | ||
87 | { | ||
88 | emov( eone, z ); | ||
89 | return; | ||
90 | } | ||
91 | else if( li < 0 ) | ||
92 | { | ||
93 | einfin( z ); | ||
94 | return; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | eclear( z ); | ||
99 | return; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if( li == 0L ) | ||
104 | { | ||
105 | emov( eone, z ); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | emov( x, w ); | ||
110 | signx = w[NE-1] & (unsigned short )0x8000; | ||
111 | w[NE-1] &= (unsigned short )0x7fff; | ||
112 | |||
113 | /* Overflow detection */ | ||
114 | /* | ||
115 | lx = li * (w[NE-1] - 0x3fff); | ||
116 | if( lx > 16385L ) | ||
117 | { | ||
118 | einfin( z ); | ||
119 | mtherr( "epowi", OVERFLOW ); | ||
120 | goto done; | ||
121 | } | ||
122 | if( lx < -16450L ) | ||
123 | { | ||
124 | eclear( z ); | ||
125 | return; | ||
126 | } | ||
127 | */ | ||
128 | rndprc = NBITS; | ||
129 | |||
130 | if( li < 0 ) | ||
131 | { | ||
132 | lu = (unsigned int )( -li ); | ||
133 | /* signy = 0xffff;*/ | ||
134 | ediv( w, eone, w ); | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | lu = (unsigned int )li; | ||
139 | /* signy = 0;*/ | ||
140 | } | ||
141 | |||
142 | /* First bit of the power */ | ||
143 | if( lu & 1 ) | ||
144 | { | ||
145 | emov( w, z ); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | emov( eone, z ); | ||
150 | signx = 0; | ||
151 | } | ||
152 | |||
153 | |||
154 | lu >>= 1; | ||
155 | while( lu != 0L ) | ||
156 | { | ||
157 | emul( w, w, w ); /* arg to the 2-to-the-kth power */ | ||
158 | if( lu & 1L ) /* if that bit is set, then include in product */ | ||
159 | emul( w, z, z ); | ||
160 | lu >>= 1; | ||
161 | } | ||
162 | |||
163 | |||
164 | done: | ||
165 | |||
166 | if( signx ) | ||
167 | eneg( z ); /* odd power of negative number */ | ||
168 | |||
169 | /* | ||
170 | if( signy ) | ||
171 | { | ||
172 | if( ecmp( z, ezero ) != 0 ) | ||
173 | { | ||
174 | ediv( z, eone, z ); | ||
175 | } | ||
176 | else | ||
177 | { | ||
178 | einfin( z ); | ||
179 | printf( "epowi OVERFLOW\n" ); | ||
180 | } | ||
181 | } | ||
182 | */ | ||
183 | rndprc = rndsav; | ||
184 | emul( eone, z, z ); | ||
185 | } | ||
186 | |||
187 | |||
diff --git a/src/regress/lib/libc/cephes/etanh.c b/src/regress/lib/libc/cephes/etanh.c new file mode 100644 index 0000000000..4ac5ff1c21 --- /dev/null +++ b/src/regress/lib/libc/cephes/etanh.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* $OpenBSD: etanh.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* xtanh.c */ | ||
20 | /* hyperbolic tangent check routine */ | ||
21 | /* this subroutine is used by the exponential function routine */ | ||
22 | /* by Stephen L. Moshier. */ | ||
23 | |||
24 | |||
25 | |||
26 | #include "ehead.h" | ||
27 | |||
28 | |||
29 | void etanh( x, y ) | ||
30 | unsigned short *x, *y; | ||
31 | { | ||
32 | unsigned short e[NE], r[NE], j[NE], xx[NE], m2[NE]; | ||
33 | short i, n; | ||
34 | long lj; | ||
35 | |||
36 | emov( x, r ); | ||
37 | r[NE-1] &= (unsigned short )0x7fff; | ||
38 | if( ecmp(r, eone) >= 0 ) | ||
39 | { | ||
40 | /* tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) | ||
41 | * Note eexp() calls xtanh, but with an argument less than (1 + log 2)/2. | ||
42 | */ | ||
43 | eexp( r, e ); | ||
44 | ediv( e, eone, r ); | ||
45 | esub( r, e, xx ); | ||
46 | eadd( r, e, j ); | ||
47 | ediv( j, xx, y ); | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | emov( etwo, m2 ); | ||
52 | eneg( m2 ); | ||
53 | |||
54 | n = NBITS/8; /* Number of terms to do in the continued fraction */ | ||
55 | lj = 2 * n + 1; | ||
56 | ltoe( &lj, j ); | ||
57 | |||
58 | emov( j, e ); | ||
59 | emul( x, x, xx ); | ||
60 | |||
61 | /* continued fraction */ | ||
62 | for( i=0; i<n; i++) | ||
63 | { | ||
64 | ediv( e, xx, r ); | ||
65 | eadd( m2, j, j ); | ||
66 | eadd( r, j, e ); | ||
67 | } | ||
68 | |||
69 | ediv( e, x, y ); | ||
70 | } | ||
diff --git a/src/regress/lib/libc/cephes/etodec.c b/src/regress/lib/libc/cephes/etodec.c new file mode 100644 index 0000000000..a15845efb6 --- /dev/null +++ b/src/regress/lib/libc/cephes/etodec.c | |||
@@ -0,0 +1,199 @@ | |||
1 | /* $OpenBSD: etodec.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "ehead.h" | ||
20 | void emovi(), emovo(), ecleaz(), eshdn8(), emdnorm(); | ||
21 | void todec(); | ||
22 | /* | ||
23 | ; convert DEC double precision to e type | ||
24 | ; double d; | ||
25 | ; short e[NE]; | ||
26 | ; dectoe( &d, e ); | ||
27 | */ | ||
28 | void dectoe( d, e ) | ||
29 | unsigned short *d; | ||
30 | unsigned short *e; | ||
31 | { | ||
32 | unsigned short y[NI]; | ||
33 | register unsigned short r, *p; | ||
34 | |||
35 | ecleaz(y); /* start with a zero */ | ||
36 | p = y; /* point to our number */ | ||
37 | r = *d; /* get DEC exponent word */ | ||
38 | if( *d & (unsigned int )0x8000 ) | ||
39 | *p = 0xffff; /* fill in our sign */ | ||
40 | ++p; /* bump pointer to our exponent word */ | ||
41 | r &= 0x7fff; /* strip the sign bit */ | ||
42 | if( r == 0 ) /* answer = 0 if high order DEC word = 0 */ | ||
43 | goto done; | ||
44 | |||
45 | |||
46 | r >>= 7; /* shift exponent word down 7 bits */ | ||
47 | r += EXONE - 0201; /* subtract DEC exponent offset */ | ||
48 | /* add our e type exponent offset */ | ||
49 | *p++ = r; /* to form our exponent */ | ||
50 | |||
51 | r = *d++; /* now do the high order mantissa */ | ||
52 | r &= 0177; /* strip off the DEC exponent and sign bits */ | ||
53 | r |= 0200; /* the DEC understood high order mantissa bit */ | ||
54 | *p++ = r; /* put result in our high guard word */ | ||
55 | |||
56 | *p++ = *d++; /* fill in the rest of our mantissa */ | ||
57 | *p++ = *d++; | ||
58 | *p = *d; | ||
59 | |||
60 | eshdn8(y); /* shift our mantissa down 8 bits */ | ||
61 | done: | ||
62 | emovo( y, e ); | ||
63 | } | ||
64 | |||
65 | |||
66 | |||
67 | /* | ||
68 | ; convert e type to DEC double precision | ||
69 | ; double d; | ||
70 | ; short e[NE]; | ||
71 | ; etodec( e, &d ); | ||
72 | */ | ||
73 | #if 0 | ||
74 | static unsigned short decbit[NI] = {0,0,0,0,0,0,0200,0}; | ||
75 | void etodec( x, d ) | ||
76 | unsigned short *x, *d; | ||
77 | { | ||
78 | unsigned short xi[NI]; | ||
79 | register unsigned short r; | ||
80 | int i, j; | ||
81 | |||
82 | emovi( x, xi ); | ||
83 | *d = 0; | ||
84 | if( xi[0] != 0 ) | ||
85 | *d = 0100000; | ||
86 | r = xi[E]; | ||
87 | if( r < (EXONE - 128) ) | ||
88 | goto zout; | ||
89 | i = xi[M+4]; | ||
90 | if( (i & 0200) != 0 ) | ||
91 | { | ||
92 | if( (i & 0377) == 0200 ) | ||
93 | { | ||
94 | if( (i & 0400) != 0 ) | ||
95 | { | ||
96 | /* check all less significant bits */ | ||
97 | for( j=M+5; j<NI; j++ ) | ||
98 | { | ||
99 | if( xi[j] != 0 ) | ||
100 | goto yesrnd; | ||
101 | } | ||
102 | } | ||
103 | goto nornd; | ||
104 | } | ||
105 | yesrnd: | ||
106 | eaddm( decbit, xi ); | ||
107 | r -= enormlz(xi); | ||
108 | } | ||
109 | |||
110 | nornd: | ||
111 | |||
112 | r -= EXONE; | ||
113 | r += 0201; | ||
114 | if( r < 0 ) | ||
115 | { | ||
116 | zout: | ||
117 | *d++ = 0; | ||
118 | *d++ = 0; | ||
119 | *d++ = 0; | ||
120 | *d++ = 0; | ||
121 | return; | ||
122 | } | ||
123 | if( r >= 0377 ) | ||
124 | { | ||
125 | *d++ = 077777; | ||
126 | *d++ = -1; | ||
127 | *d++ = -1; | ||
128 | *d++ = -1; | ||
129 | return; | ||
130 | } | ||
131 | r &= 0377; | ||
132 | r <<= 7; | ||
133 | eshup8( xi ); | ||
134 | xi[M] &= 0177; | ||
135 | r |= xi[M]; | ||
136 | *d++ |= r; | ||
137 | *d++ = xi[M+1]; | ||
138 | *d++ = xi[M+2]; | ||
139 | *d++ = xi[M+3]; | ||
140 | } | ||
141 | #else | ||
142 | |||
143 | extern int rndprc; | ||
144 | |||
145 | void etodec( x, d ) | ||
146 | unsigned short *x, *d; | ||
147 | { | ||
148 | unsigned short xi[NI]; | ||
149 | long exp; | ||
150 | int rndsav; | ||
151 | |||
152 | emovi( x, xi ); | ||
153 | exp = (long )xi[E] - (EXONE - 0201); /* adjust exponent for offsets */ | ||
154 | /* round off to nearest or even */ | ||
155 | rndsav = rndprc; | ||
156 | rndprc = 56; | ||
157 | emdnorm( xi, 0, 0, exp, 64 ); | ||
158 | rndprc = rndsav; | ||
159 | todec( xi, d ); | ||
160 | } | ||
161 | |||
162 | void todec( x, y ) | ||
163 | unsigned short *x, *y; | ||
164 | { | ||
165 | unsigned short i; | ||
166 | unsigned short *p; | ||
167 | |||
168 | p = x; | ||
169 | *y = 0; | ||
170 | if( *p++ ) | ||
171 | *y = 0100000; | ||
172 | i = *p++; | ||
173 | if( i == 0 ) | ||
174 | { | ||
175 | *y++ = 0; | ||
176 | *y++ = 0; | ||
177 | *y++ = 0; | ||
178 | *y++ = 0; | ||
179 | return; | ||
180 | } | ||
181 | if( i > 0377 ) | ||
182 | { | ||
183 | *y++ |= 077777; | ||
184 | *y++ = 0xffff; | ||
185 | *y++ = 0xffff; | ||
186 | *y++ = 0xffff; | ||
187 | return; | ||
188 | } | ||
189 | i &= 0377; | ||
190 | i <<= 7; | ||
191 | eshup8( x ); | ||
192 | x[M] &= 0177; | ||
193 | i |= x[M]; | ||
194 | *y++ |= i; | ||
195 | *y++ = x[M+1]; | ||
196 | *y++ = x[M+2]; | ||
197 | *y++ = x[M+3]; | ||
198 | } | ||
199 | #endif | ||
diff --git a/src/regress/lib/libc/cephes/ieee.c b/src/regress/lib/libc/cephes/ieee.c new file mode 100644 index 0000000000..e2b8aa7b99 --- /dev/null +++ b/src/regress/lib/libc/cephes/ieee.c | |||
@@ -0,0 +1,4153 @@ | |||
1 | /* $OpenBSD: ieee.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* ieee.c | ||
20 | * | ||
21 | * Extended precision IEEE binary floating point arithmetic routines | ||
22 | * | ||
23 | * Numbers are stored in C language as arrays of 16-bit unsigned | ||
24 | * short integers. The arguments of the routines are pointers to | ||
25 | * the arrays. | ||
26 | * | ||
27 | * | ||
28 | * External e type data structure, simulates Intel 8087 chip | ||
29 | * temporary real format but possibly with a larger significand: | ||
30 | * | ||
31 | * NE-1 significand words (least significant word first, | ||
32 | * most significant bit is normally set) | ||
33 | * exponent (value = EXONE for 1.0, | ||
34 | * top bit is the sign) | ||
35 | * | ||
36 | * | ||
37 | * Internal data structure of a number (a "word" is 16 bits): | ||
38 | * | ||
39 | * ei[0] sign word (0 for positive, 0xffff for negative) | ||
40 | * ei[1] biased exponent (value = EXONE for the number 1.0) | ||
41 | * ei[2] high guard word (always zero after normalization) | ||
42 | * ei[3] | ||
43 | * to ei[NI-2] significand (NI-4 significand words, | ||
44 | * most significant word first, | ||
45 | * most significant bit is set) | ||
46 | * ei[NI-1] low guard word (0x8000 bit is rounding place) | ||
47 | * | ||
48 | * | ||
49 | * | ||
50 | * Routines for external format numbers | ||
51 | * | ||
52 | * asctoe( string, e ) ASCII string to extended double e type | ||
53 | * asctoe64( string, &d ) ASCII string to long double | ||
54 | * asctoe53( string, &d ) ASCII string to double | ||
55 | * asctoe24( string, &f ) ASCII string to single | ||
56 | * asctoeg( string, e, prec ) ASCII string to specified precision | ||
57 | * e24toe( &f, e ) IEEE single precision to e type | ||
58 | * e53toe( &d, e ) IEEE double precision to e type | ||
59 | * e64toe( &d, e ) IEEE long double precision to e type | ||
60 | * eabs(e) absolute value | ||
61 | * eadd( a, b, c ) c = b + a | ||
62 | * eclear(e) e = 0 | ||
63 | * ecmp (a, b) Returns 1 if a > b, 0 if a == b, | ||
64 | * -1 if a < b, -2 if either a or b is a NaN. | ||
65 | * ediv( a, b, c ) c = b / a | ||
66 | * efloor( a, b ) truncate to integer, toward -infinity | ||
67 | * efrexp( a, exp, s ) extract exponent and significand | ||
68 | * eifrac( e, &l, frac ) e to long integer and e type fraction | ||
69 | * euifrac( e, &l, frac ) e to unsigned long integer and e type fraction | ||
70 | * einfin( e ) set e to infinity, leaving its sign alone | ||
71 | * eldexp( a, n, b ) multiply by 2**n | ||
72 | * emov( a, b ) b = a | ||
73 | * emul( a, b, c ) c = b * a | ||
74 | * eneg(e) e = -e | ||
75 | * eround( a, b ) b = nearest integer value to a | ||
76 | * esub( a, b, c ) c = b - a | ||
77 | * e24toasc( &f, str, n ) single to ASCII string, n digits after decimal | ||
78 | * e53toasc( &d, str, n ) double to ASCII string, n digits after decimal | ||
79 | * e64toasc( &d, str, n ) long double to ASCII string | ||
80 | * etoasc( e, str, n ) e to ASCII string, n digits after decimal | ||
81 | * etoe24( e, &f ) convert e type to IEEE single precision | ||
82 | * etoe53( e, &d ) convert e type to IEEE double precision | ||
83 | * etoe64( e, &d ) convert e type to IEEE long double precision | ||
84 | * ltoe( &l, e ) long (32 bit) integer to e type | ||
85 | * ultoe( &l, e ) unsigned long (32 bit) integer to e type | ||
86 | * eisneg( e ) 1 if sign bit of e != 0, else 0 | ||
87 | * eisinf( e ) 1 if e has maximum exponent (non-IEEE) | ||
88 | * or is infinite (IEEE) | ||
89 | * eisnan( e ) 1 if e is a NaN | ||
90 | * esqrt( a, b ) b = square root of a | ||
91 | * | ||
92 | * | ||
93 | * Routines for internal format numbers | ||
94 | * | ||
95 | * eaddm( ai, bi ) add significands, bi = bi + ai | ||
96 | * ecleaz(ei) ei = 0 | ||
97 | * ecleazs(ei) set ei = 0 but leave its sign alone | ||
98 | * ecmpm( ai, bi ) compare significands, return 1, 0, or -1 | ||
99 | * edivm( ai, bi ) divide significands, bi = bi / ai | ||
100 | * emdnorm(ai,l,s,exp) normalize and round off | ||
101 | * emovi( a, ai ) convert external a to internal ai | ||
102 | * emovo( ai, a ) convert internal ai to external a | ||
103 | * emovz( ai, bi ) bi = ai, low guard word of bi = 0 | ||
104 | * emulm( ai, bi ) multiply significands, bi = bi * ai | ||
105 | * enormlz(ei) left-justify the significand | ||
106 | * eshdn1( ai ) shift significand and guards down 1 bit | ||
107 | * eshdn8( ai ) shift down 8 bits | ||
108 | * eshdn6( ai ) shift down 16 bits | ||
109 | * eshift( ai, n ) shift ai n bits up (or down if n < 0) | ||
110 | * eshup1( ai ) shift significand and guards up 1 bit | ||
111 | * eshup8( ai ) shift up 8 bits | ||
112 | * eshup6( ai ) shift up 16 bits | ||
113 | * esubm( ai, bi ) subtract significands, bi = bi - ai | ||
114 | * | ||
115 | * | ||
116 | * The result is always normalized and rounded to NI-4 word precision | ||
117 | * after each arithmetic operation. | ||
118 | * | ||
119 | * Exception flags are NOT fully supported. | ||
120 | * | ||
121 | * Define INFINITY in mconf.h for support of infinity; otherwise a | ||
122 | * saturation arithmetic is implemented. | ||
123 | * | ||
124 | * Define NANS for support of Not-a-Number items; otherwise the | ||
125 | * arithmetic will never produce a NaN output, and might be confused | ||
126 | * by a NaN input. | ||
127 | * If NaN's are supported, the output of ecmp(a,b) is -2 if | ||
128 | * either a or b is a NaN. This means asking if(ecmp(a,b) < 0) | ||
129 | * may not be legitimate. Use if(ecmp(a,b) == -1) for less-than | ||
130 | * if in doubt. | ||
131 | * Signaling NaN's are NOT supported; they are treated the same | ||
132 | * as quiet NaN's. | ||
133 | * | ||
134 | * Denormals are always supported here where appropriate (e.g., not | ||
135 | * for conversion to DEC numbers). | ||
136 | */ | ||
137 | |||
138 | /* | ||
139 | * Revision history: | ||
140 | * | ||
141 | * 5 Jan 84 PDP-11 assembly language version | ||
142 | * 2 Mar 86 fixed bug in asctoq() | ||
143 | * 6 Dec 86 C language version | ||
144 | * 30 Aug 88 100 digit version, improved rounding | ||
145 | * 15 May 92 80-bit long double support | ||
146 | * | ||
147 | * Author: S. L. Moshier. | ||
148 | */ | ||
149 | |||
150 | #include <stdio.h> | ||
151 | #include "mconf.h" | ||
152 | #include "ehead.h" | ||
153 | |||
154 | /* Change UNK into something else. */ | ||
155 | #ifdef UNK | ||
156 | #undef UNK | ||
157 | #if BIGENDIAN | ||
158 | #define MIEEE 1 | ||
159 | #else | ||
160 | #define IBMPC 1 | ||
161 | #endif | ||
162 | #endif | ||
163 | |||
164 | /* NaN's require infinity support. */ | ||
165 | #ifdef NANS | ||
166 | #ifndef INFINITY | ||
167 | #define INFINITY | ||
168 | #endif | ||
169 | #endif | ||
170 | |||
171 | /* This handles 64-bit long ints. */ | ||
172 | #define LONGBITS (8 * sizeof(long)) | ||
173 | |||
174 | /* Control register for rounding precision. | ||
175 | * This can be set to 80 (if NE=6), 64, 56, 53, or 24 bits. | ||
176 | */ | ||
177 | int rndprc = NBITS; | ||
178 | extern int rndprc; | ||
179 | |||
180 | void eaddm(), esubm(), emdnorm(), asctoeg(), enan(); | ||
181 | static void toe24(), toe53(), toe64(), toe113(); | ||
182 | void eremain(), einit(), eiremain(); | ||
183 | int ecmpm(), edivm(), emulm(), eisneg(), eisinf(); | ||
184 | void emovi(), emovo(), emovz(), ecleaz(), eadd1(); | ||
185 | void etodec(), todec(), dectoe(); | ||
186 | int eisnan(), eiisnan(); | ||
187 | |||
188 | |||
189 | |||
190 | void einit() | ||
191 | { | ||
192 | } | ||
193 | |||
194 | /* | ||
195 | ; Clear out entire external format number. | ||
196 | ; | ||
197 | ; unsigned short x[]; | ||
198 | ; eclear( x ); | ||
199 | */ | ||
200 | |||
201 | void eclear( x ) | ||
202 | register unsigned short *x; | ||
203 | { | ||
204 | register int i; | ||
205 | |||
206 | for( i=0; i<NE; i++ ) | ||
207 | *x++ = 0; | ||
208 | } | ||
209 | |||
210 | |||
211 | |||
212 | /* Move external format number from a to b. | ||
213 | * | ||
214 | * emov( a, b ); | ||
215 | */ | ||
216 | |||
217 | void emov( a, b ) | ||
218 | register unsigned short *a, *b; | ||
219 | { | ||
220 | register int i; | ||
221 | |||
222 | for( i=0; i<NE; i++ ) | ||
223 | *b++ = *a++; | ||
224 | } | ||
225 | |||
226 | |||
227 | /* | ||
228 | ; Absolute value of external format number | ||
229 | ; | ||
230 | ; short x[NE]; | ||
231 | ; eabs( x ); | ||
232 | */ | ||
233 | |||
234 | void eabs(x) | ||
235 | unsigned short x[]; /* x is the memory address of a short */ | ||
236 | { | ||
237 | |||
238 | x[NE-1] &= 0x7fff; /* sign is top bit of last word of external format */ | ||
239 | } | ||
240 | |||
241 | |||
242 | |||
243 | |||
244 | /* | ||
245 | ; Negate external format number | ||
246 | ; | ||
247 | ; unsigned short x[NE]; | ||
248 | ; eneg( x ); | ||
249 | */ | ||
250 | |||
251 | void eneg(x) | ||
252 | unsigned short x[]; | ||
253 | { | ||
254 | |||
255 | #ifdef NANS | ||
256 | if( eisnan(x) ) | ||
257 | return; | ||
258 | #endif | ||
259 | x[NE-1] ^= 0x8000; /* Toggle the sign bit */ | ||
260 | } | ||
261 | |||
262 | |||
263 | |||
264 | /* Return 1 if external format number is negative, | ||
265 | * else return zero. | ||
266 | */ | ||
267 | int eisneg(x) | ||
268 | unsigned short x[]; | ||
269 | { | ||
270 | |||
271 | #ifdef NANS | ||
272 | if( eisnan(x) ) | ||
273 | return( 0 ); | ||
274 | #endif | ||
275 | if( x[NE-1] & 0x8000 ) | ||
276 | return( 1 ); | ||
277 | else | ||
278 | return( 0 ); | ||
279 | } | ||
280 | |||
281 | |||
282 | /* Return 1 if external format number has maximum possible exponent, | ||
283 | * else return zero. | ||
284 | */ | ||
285 | int eisinf(x) | ||
286 | unsigned short x[]; | ||
287 | { | ||
288 | |||
289 | if( (x[NE-1] & 0x7fff) == 0x7fff ) | ||
290 | { | ||
291 | #ifdef NANS | ||
292 | if( eisnan(x) ) | ||
293 | return( 0 ); | ||
294 | #endif | ||
295 | return( 1 ); | ||
296 | } | ||
297 | else | ||
298 | return( 0 ); | ||
299 | } | ||
300 | |||
301 | /* Check if e-type number is not a number. | ||
302 | */ | ||
303 | int eisnan(x) | ||
304 | unsigned short x[]; | ||
305 | { | ||
306 | |||
307 | #ifdef NANS | ||
308 | int i; | ||
309 | /* NaN has maximum exponent */ | ||
310 | if( (x[NE-1] & 0x7fff) != 0x7fff ) | ||
311 | return (0); | ||
312 | /* ... and non-zero significand field. */ | ||
313 | for( i=0; i<NE-1; i++ ) | ||
314 | { | ||
315 | if( *x++ != 0 ) | ||
316 | return (1); | ||
317 | } | ||
318 | #endif | ||
319 | return (0); | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | ; Fill entire number, including exponent and significand, with | ||
324 | ; largest possible number. These programs implement a saturation | ||
325 | ; value that is an ordinary, legal number. A special value | ||
326 | ; "infinity" may also be implemented; this would require tests | ||
327 | ; for that value and implementation of special rules for arithmetic | ||
328 | ; operations involving inifinity. | ||
329 | */ | ||
330 | |||
331 | void einfin(x) | ||
332 | register unsigned short *x; | ||
333 | { | ||
334 | register int i; | ||
335 | |||
336 | #ifdef INFINITY | ||
337 | for( i=0; i<NE-1; i++ ) | ||
338 | *x++ = 0; | ||
339 | *x |= 32767; | ||
340 | #else | ||
341 | for( i=0; i<NE-1; i++ ) | ||
342 | *x++ = 0xffff; | ||
343 | *x |= 32766; | ||
344 | if( rndprc < NBITS ) | ||
345 | { | ||
346 | if (rndprc == 113) | ||
347 | { | ||
348 | *(x - 9) = 0; | ||
349 | *(x - 8) = 0; | ||
350 | } | ||
351 | if( rndprc == 64 ) | ||
352 | { | ||
353 | *(x-5) = 0; | ||
354 | } | ||
355 | if( rndprc == 53 ) | ||
356 | { | ||
357 | *(x-4) = 0xf800; | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | *(x-4) = 0; | ||
362 | *(x-3) = 0; | ||
363 | *(x-2) = 0xff00; | ||
364 | } | ||
365 | } | ||
366 | #endif | ||
367 | } | ||
368 | |||
369 | |||
370 | |||
371 | /* Move in external format number, | ||
372 | * converting it to internal format. | ||
373 | */ | ||
374 | void emovi( a, b ) | ||
375 | unsigned short *a, *b; | ||
376 | { | ||
377 | register unsigned short *p, *q; | ||
378 | int i; | ||
379 | |||
380 | q = b; | ||
381 | p = a + (NE-1); /* point to last word of external number */ | ||
382 | /* get the sign bit */ | ||
383 | if( *p & 0x8000 ) | ||
384 | *q++ = 0xffff; | ||
385 | else | ||
386 | *q++ = 0; | ||
387 | /* get the exponent */ | ||
388 | *q = *p--; | ||
389 | *q++ &= 0x7fff; /* delete the sign bit */ | ||
390 | #ifdef INFINITY | ||
391 | if( (*(q-1) & 0x7fff) == 0x7fff ) | ||
392 | { | ||
393 | #ifdef NANS | ||
394 | if( eisnan(a) ) | ||
395 | { | ||
396 | *q++ = 0; | ||
397 | for( i=3; i<NI; i++ ) | ||
398 | *q++ = *p--; | ||
399 | return; | ||
400 | } | ||
401 | #endif | ||
402 | for( i=2; i<NI; i++ ) | ||
403 | *q++ = 0; | ||
404 | return; | ||
405 | } | ||
406 | #endif | ||
407 | /* clear high guard word */ | ||
408 | *q++ = 0; | ||
409 | /* move in the significand */ | ||
410 | for( i=0; i<NE-1; i++ ) | ||
411 | *q++ = *p--; | ||
412 | /* clear low guard word */ | ||
413 | *q = 0; | ||
414 | } | ||
415 | |||
416 | |||
417 | /* Move internal format number out, | ||
418 | * converting it to external format. | ||
419 | */ | ||
420 | void emovo( a, b ) | ||
421 | unsigned short *a, *b; | ||
422 | { | ||
423 | register unsigned short *p, *q; | ||
424 | unsigned short i; | ||
425 | |||
426 | p = a; | ||
427 | q = b + (NE-1); /* point to output exponent */ | ||
428 | /* combine sign and exponent */ | ||
429 | i = *p++; | ||
430 | if( i ) | ||
431 | *q-- = *p++ | 0x8000; | ||
432 | else | ||
433 | *q-- = *p++; | ||
434 | #ifdef INFINITY | ||
435 | if( *(p-1) == 0x7fff ) | ||
436 | { | ||
437 | #ifdef NANS | ||
438 | if( eiisnan(a) ) | ||
439 | { | ||
440 | enan( b, NBITS ); | ||
441 | return; | ||
442 | } | ||
443 | #endif | ||
444 | einfin(b); | ||
445 | return; | ||
446 | } | ||
447 | #endif | ||
448 | /* skip over guard word */ | ||
449 | ++p; | ||
450 | /* move the significand */ | ||
451 | for( i=0; i<NE-1; i++ ) | ||
452 | *q-- = *p++; | ||
453 | } | ||
454 | |||
455 | |||
456 | |||
457 | |||
458 | /* Clear out internal format number. | ||
459 | */ | ||
460 | |||
461 | void ecleaz( xi ) | ||
462 | register unsigned short *xi; | ||
463 | { | ||
464 | register int i; | ||
465 | |||
466 | for( i=0; i<NI; i++ ) | ||
467 | *xi++ = 0; | ||
468 | } | ||
469 | |||
470 | /* same, but don't touch the sign. */ | ||
471 | |||
472 | void ecleazs( xi ) | ||
473 | register unsigned short *xi; | ||
474 | { | ||
475 | register int i; | ||
476 | |||
477 | ++xi; | ||
478 | for(i=0; i<NI-1; i++) | ||
479 | *xi++ = 0; | ||
480 | } | ||
481 | |||
482 | |||
483 | |||
484 | |||
485 | /* Move internal format number from a to b. | ||
486 | */ | ||
487 | void emovz( a, b ) | ||
488 | register unsigned short *a, *b; | ||
489 | { | ||
490 | register int i; | ||
491 | |||
492 | for( i=0; i<NI-1; i++ ) | ||
493 | *b++ = *a++; | ||
494 | /* clear low guard word */ | ||
495 | *b = 0; | ||
496 | } | ||
497 | |||
498 | /* Return nonzero if internal format number is a NaN. | ||
499 | */ | ||
500 | |||
501 | int eiisnan (x) | ||
502 | unsigned short x[]; | ||
503 | { | ||
504 | int i; | ||
505 | |||
506 | if( (x[E] & 0x7fff) == 0x7fff ) | ||
507 | { | ||
508 | for( i=M+1; i<NI; i++ ) | ||
509 | { | ||
510 | if( x[i] != 0 ) | ||
511 | return(1); | ||
512 | } | ||
513 | } | ||
514 | return(0); | ||
515 | } | ||
516 | |||
517 | #ifdef INFINITY | ||
518 | /* Return nonzero if internal format number is infinite. */ | ||
519 | |||
520 | static int | ||
521 | eiisinf (x) | ||
522 | unsigned short x[]; | ||
523 | { | ||
524 | |||
525 | #ifdef NANS | ||
526 | if (eiisnan (x)) | ||
527 | return (0); | ||
528 | #endif | ||
529 | if ((x[E] & 0x7fff) == 0x7fff) | ||
530 | return (1); | ||
531 | return (0); | ||
532 | } | ||
533 | #endif | ||
534 | |||
535 | /* | ||
536 | ; Compare significands of numbers in internal format. | ||
537 | ; Guard words are included in the comparison. | ||
538 | ; | ||
539 | ; unsigned short a[NI], b[NI]; | ||
540 | ; cmpm( a, b ); | ||
541 | ; | ||
542 | ; for the significands: | ||
543 | ; returns +1 if a > b | ||
544 | ; 0 if a == b | ||
545 | ; -1 if a < b | ||
546 | */ | ||
547 | int ecmpm( a, b ) | ||
548 | register unsigned short *a, *b; | ||
549 | { | ||
550 | int i; | ||
551 | |||
552 | a += M; /* skip up to significand area */ | ||
553 | b += M; | ||
554 | for( i=M; i<NI; i++ ) | ||
555 | { | ||
556 | if( *a++ != *b++ ) | ||
557 | goto difrnt; | ||
558 | } | ||
559 | return(0); | ||
560 | |||
561 | difrnt: | ||
562 | if( *(--a) > *(--b) ) | ||
563 | return(1); | ||
564 | else | ||
565 | return(-1); | ||
566 | } | ||
567 | |||
568 | |||
569 | /* | ||
570 | ; Shift significand down by 1 bit | ||
571 | */ | ||
572 | |||
573 | void eshdn1(x) | ||
574 | register unsigned short *x; | ||
575 | { | ||
576 | register unsigned short bits; | ||
577 | int i; | ||
578 | |||
579 | x += M; /* point to significand area */ | ||
580 | |||
581 | bits = 0; | ||
582 | for( i=M; i<NI; i++ ) | ||
583 | { | ||
584 | if( *x & 1 ) | ||
585 | bits |= 1; | ||
586 | *x >>= 1; | ||
587 | if( bits & 2 ) | ||
588 | *x |= 0x8000; | ||
589 | bits <<= 1; | ||
590 | ++x; | ||
591 | } | ||
592 | } | ||
593 | |||
594 | |||
595 | |||
596 | /* | ||
597 | ; Shift significand up by 1 bit | ||
598 | */ | ||
599 | |||
600 | void eshup1(x) | ||
601 | register unsigned short *x; | ||
602 | { | ||
603 | register unsigned short bits; | ||
604 | int i; | ||
605 | |||
606 | x += NI-1; | ||
607 | bits = 0; | ||
608 | |||
609 | for( i=M; i<NI; i++ ) | ||
610 | { | ||
611 | if( *x & 0x8000 ) | ||
612 | bits |= 1; | ||
613 | *x <<= 1; | ||
614 | if( bits & 2 ) | ||
615 | *x |= 1; | ||
616 | bits <<= 1; | ||
617 | --x; | ||
618 | } | ||
619 | } | ||
620 | |||
621 | |||
622 | |||
623 | /* | ||
624 | ; Shift significand down by 8 bits | ||
625 | */ | ||
626 | |||
627 | void eshdn8(x) | ||
628 | register unsigned short *x; | ||
629 | { | ||
630 | register unsigned short newbyt, oldbyt; | ||
631 | int i; | ||
632 | |||
633 | x += M; | ||
634 | oldbyt = 0; | ||
635 | for( i=M; i<NI; i++ ) | ||
636 | { | ||
637 | newbyt = *x << 8; | ||
638 | *x >>= 8; | ||
639 | *x |= oldbyt; | ||
640 | oldbyt = newbyt; | ||
641 | ++x; | ||
642 | } | ||
643 | } | ||
644 | |||
645 | /* | ||
646 | ; Shift significand up by 8 bits | ||
647 | */ | ||
648 | |||
649 | void eshup8(x) | ||
650 | register unsigned short *x; | ||
651 | { | ||
652 | int i; | ||
653 | register unsigned short newbyt, oldbyt; | ||
654 | |||
655 | x += NI-1; | ||
656 | oldbyt = 0; | ||
657 | |||
658 | for( i=M; i<NI; i++ ) | ||
659 | { | ||
660 | newbyt = *x >> 8; | ||
661 | *x <<= 8; | ||
662 | *x |= oldbyt; | ||
663 | oldbyt = newbyt; | ||
664 | --x; | ||
665 | } | ||
666 | } | ||
667 | |||
668 | /* | ||
669 | ; Shift significand up by 16 bits | ||
670 | */ | ||
671 | |||
672 | void eshup6(x) | ||
673 | register unsigned short *x; | ||
674 | { | ||
675 | int i; | ||
676 | register unsigned short *p; | ||
677 | |||
678 | p = x + M; | ||
679 | x += M + 1; | ||
680 | |||
681 | for( i=M; i<NI-1; i++ ) | ||
682 | *p++ = *x++; | ||
683 | |||
684 | *p = 0; | ||
685 | } | ||
686 | |||
687 | /* | ||
688 | ; Shift significand down by 16 bits | ||
689 | */ | ||
690 | |||
691 | void eshdn6(x) | ||
692 | register unsigned short *x; | ||
693 | { | ||
694 | int i; | ||
695 | register unsigned short *p; | ||
696 | |||
697 | x += NI-1; | ||
698 | p = x + 1; | ||
699 | |||
700 | for( i=M; i<NI-1; i++ ) | ||
701 | *(--p) = *(--x); | ||
702 | |||
703 | *(--p) = 0; | ||
704 | } | ||
705 | |||
706 | /* | ||
707 | ; Add significands | ||
708 | ; x + y replaces y | ||
709 | */ | ||
710 | |||
711 | void eaddm( x, y ) | ||
712 | unsigned short *x, *y; | ||
713 | { | ||
714 | register unsigned long a; | ||
715 | int i; | ||
716 | unsigned int carry; | ||
717 | |||
718 | x += NI-1; | ||
719 | y += NI-1; | ||
720 | carry = 0; | ||
721 | for( i=M; i<NI; i++ ) | ||
722 | { | ||
723 | a = (unsigned long )(*x) + (unsigned long )(*y) + carry; | ||
724 | if( a & 0x10000 ) | ||
725 | carry = 1; | ||
726 | else | ||
727 | carry = 0; | ||
728 | *y = (unsigned short )a; | ||
729 | --x; | ||
730 | --y; | ||
731 | } | ||
732 | } | ||
733 | |||
734 | /* | ||
735 | ; Subtract significands | ||
736 | ; y - x replaces y | ||
737 | */ | ||
738 | |||
739 | void esubm( x, y ) | ||
740 | unsigned short *x, *y; | ||
741 | { | ||
742 | unsigned long a; | ||
743 | int i; | ||
744 | unsigned int carry; | ||
745 | |||
746 | x += NI-1; | ||
747 | y += NI-1; | ||
748 | carry = 0; | ||
749 | for( i=M; i<NI; i++ ) | ||
750 | { | ||
751 | a = (unsigned long )(*y) - (unsigned long )(*x) - carry; | ||
752 | if( a & 0x10000 ) | ||
753 | carry = 1; | ||
754 | else | ||
755 | carry = 0; | ||
756 | *y = (unsigned short )a; | ||
757 | --x; | ||
758 | --y; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | |||
763 | /* Divide significands */ | ||
764 | |||
765 | static unsigned short equot[NI] = {0}; /* was static */ | ||
766 | |||
767 | #if 0 | ||
768 | int edivm( den, num ) | ||
769 | unsigned short den[], num[]; | ||
770 | { | ||
771 | int i; | ||
772 | register unsigned short *p, *q; | ||
773 | unsigned short j; | ||
774 | |||
775 | p = &equot[0]; | ||
776 | *p++ = num[0]; | ||
777 | *p++ = num[1]; | ||
778 | |||
779 | for( i=M; i<NI; i++ ) | ||
780 | { | ||
781 | *p++ = 0; | ||
782 | } | ||
783 | |||
784 | /* Use faster compare and subtraction if denominator | ||
785 | * has only 15 bits of significance. | ||
786 | */ | ||
787 | p = &den[M+2]; | ||
788 | if( *p++ == 0 ) | ||
789 | { | ||
790 | for( i=M+3; i<NI; i++ ) | ||
791 | { | ||
792 | if( *p++ != 0 ) | ||
793 | goto fulldiv; | ||
794 | } | ||
795 | if( (den[M+1] & 1) != 0 ) | ||
796 | goto fulldiv; | ||
797 | eshdn1(num); | ||
798 | eshdn1(den); | ||
799 | |||
800 | p = &den[M+1]; | ||
801 | q = &num[M+1]; | ||
802 | |||
803 | for( i=0; i<NBITS+2; i++ ) | ||
804 | { | ||
805 | if( *p <= *q ) | ||
806 | { | ||
807 | *q -= *p; | ||
808 | j = 1; | ||
809 | } | ||
810 | else | ||
811 | { | ||
812 | j = 0; | ||
813 | } | ||
814 | eshup1(equot); | ||
815 | equot[NI-2] |= j; | ||
816 | eshup1(num); | ||
817 | } | ||
818 | goto divdon; | ||
819 | } | ||
820 | |||
821 | /* The number of quotient bits to calculate is | ||
822 | * NBITS + 1 scaling guard bit + 1 roundoff bit. | ||
823 | */ | ||
824 | fulldiv: | ||
825 | |||
826 | p = &equot[NI-2]; | ||
827 | for( i=0; i<NBITS+2; i++ ) | ||
828 | { | ||
829 | if( ecmpm(den,num) <= 0 ) | ||
830 | { | ||
831 | esubm(den, num); | ||
832 | j = 1; /* quotient bit = 1 */ | ||
833 | } | ||
834 | else | ||
835 | j = 0; | ||
836 | eshup1(equot); | ||
837 | *p |= j; | ||
838 | eshup1(num); | ||
839 | } | ||
840 | |||
841 | divdon: | ||
842 | |||
843 | eshdn1( equot ); | ||
844 | eshdn1( equot ); | ||
845 | |||
846 | /* test for nonzero remainder after roundoff bit */ | ||
847 | p = &num[M]; | ||
848 | j = 0; | ||
849 | for( i=M; i<NI; i++ ) | ||
850 | { | ||
851 | j |= *p++; | ||
852 | } | ||
853 | if( j ) | ||
854 | j = 1; | ||
855 | |||
856 | |||
857 | for( i=0; i<NI; i++ ) | ||
858 | num[i] = equot[i]; | ||
859 | return( (int )j ); | ||
860 | } | ||
861 | |||
862 | /* Multiply significands */ | ||
863 | int emulm( a, b ) | ||
864 | unsigned short a[], b[]; | ||
865 | { | ||
866 | unsigned short *p, *q; | ||
867 | int i, j, k; | ||
868 | |||
869 | equot[0] = b[0]; | ||
870 | equot[1] = b[1]; | ||
871 | for( i=M; i<NI; i++ ) | ||
872 | equot[i] = 0; | ||
873 | |||
874 | p = &a[NI-2]; | ||
875 | k = NBITS; | ||
876 | while( *p == 0 ) /* significand is not supposed to be all zero */ | ||
877 | { | ||
878 | eshdn6(a); | ||
879 | k -= 16; | ||
880 | } | ||
881 | if( (*p & 0xff) == 0 ) | ||
882 | { | ||
883 | eshdn8(a); | ||
884 | k -= 8; | ||
885 | } | ||
886 | |||
887 | q = &equot[NI-1]; | ||
888 | j = 0; | ||
889 | for( i=0; i<k; i++ ) | ||
890 | { | ||
891 | if( *p & 1 ) | ||
892 | eaddm(b, equot); | ||
893 | /* remember if there were any nonzero bits shifted out */ | ||
894 | if( *q & 1 ) | ||
895 | j |= 1; | ||
896 | eshdn1(a); | ||
897 | eshdn1(equot); | ||
898 | } | ||
899 | |||
900 | for( i=0; i<NI; i++ ) | ||
901 | b[i] = equot[i]; | ||
902 | |||
903 | /* return flag for lost nonzero bits */ | ||
904 | return(j); | ||
905 | } | ||
906 | |||
907 | #else | ||
908 | |||
909 | /* Multiply significand of e-type number b | ||
910 | by 16-bit quantity a, e-type result to c. */ | ||
911 | |||
912 | void m16m( a, b, c ) | ||
913 | unsigned short a; | ||
914 | unsigned short b[], c[]; | ||
915 | { | ||
916 | register unsigned short *pp; | ||
917 | register unsigned long carry; | ||
918 | unsigned short *ps; | ||
919 | unsigned short p[NI]; | ||
920 | unsigned long aa, m; | ||
921 | int i; | ||
922 | |||
923 | aa = a; | ||
924 | pp = &p[NI-2]; | ||
925 | *pp++ = 0; | ||
926 | *pp = 0; | ||
927 | ps = &b[NI-1]; | ||
928 | |||
929 | for( i=M+1; i<NI; i++ ) | ||
930 | { | ||
931 | if( *ps == 0 ) | ||
932 | { | ||
933 | --ps; | ||
934 | --pp; | ||
935 | *(pp-1) = 0; | ||
936 | } | ||
937 | else | ||
938 | { | ||
939 | m = (unsigned long) aa * *ps--; | ||
940 | carry = (m & 0xffff) + *pp; | ||
941 | *pp-- = (unsigned short )carry; | ||
942 | carry = (carry >> 16) + (m >> 16) + *pp; | ||
943 | *pp = (unsigned short )carry; | ||
944 | *(pp-1) = carry >> 16; | ||
945 | } | ||
946 | } | ||
947 | for( i=M; i<NI; i++ ) | ||
948 | c[i] = p[i]; | ||
949 | } | ||
950 | |||
951 | |||
952 | /* Divide significands. Neither the numerator nor the denominator | ||
953 | is permitted to have its high guard word nonzero. */ | ||
954 | |||
955 | |||
956 | int edivm( den, num ) | ||
957 | unsigned short den[], num[]; | ||
958 | { | ||
959 | int i; | ||
960 | register unsigned short *p; | ||
961 | unsigned long tnum; | ||
962 | unsigned short j, tdenm, tquot; | ||
963 | unsigned short tprod[NI+1]; | ||
964 | |||
965 | p = &equot[0]; | ||
966 | *p++ = num[0]; | ||
967 | *p++ = num[1]; | ||
968 | |||
969 | for( i=M; i<NI; i++ ) | ||
970 | { | ||
971 | *p++ = 0; | ||
972 | } | ||
973 | eshdn1( num ); | ||
974 | tdenm = den[M+1]; | ||
975 | for( i=M; i<NI; i++ ) | ||
976 | { | ||
977 | /* Find trial quotient digit (the radix is 65536). */ | ||
978 | tnum = (((unsigned long) num[M]) << 16) + num[M+1]; | ||
979 | |||
980 | /* Do not execute the divide instruction if it will overflow. */ | ||
981 | if( (tdenm * 0xffffL) < tnum ) | ||
982 | tquot = 0xffff; | ||
983 | else | ||
984 | tquot = tnum / tdenm; | ||
985 | |||
986 | /* Prove that the divide worked. */ | ||
987 | /* | ||
988 | tcheck = (unsigned long )tquot * tdenm; | ||
989 | if( tnum - tcheck > tdenm ) | ||
990 | tquot = 0xffff; | ||
991 | */ | ||
992 | /* Multiply denominator by trial quotient digit. */ | ||
993 | m16m( tquot, den, tprod ); | ||
994 | /* The quotient digit may have been overestimated. */ | ||
995 | if( ecmpm( tprod, num ) > 0 ) | ||
996 | { | ||
997 | tquot -= 1; | ||
998 | esubm( den, tprod ); | ||
999 | if( ecmpm( tprod, num ) > 0 ) | ||
1000 | { | ||
1001 | tquot -= 1; | ||
1002 | esubm( den, tprod ); | ||
1003 | } | ||
1004 | } | ||
1005 | /* | ||
1006 | if( ecmpm( tprod, num ) > 0 ) | ||
1007 | { | ||
1008 | eshow( "tprod", tprod ); | ||
1009 | eshow( "num ", num ); | ||
1010 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
1011 | tnum, den[M+1], tquot ); | ||
1012 | } | ||
1013 | */ | ||
1014 | esubm( tprod, num ); | ||
1015 | /* | ||
1016 | if( ecmpm( num, den ) >= 0 ) | ||
1017 | { | ||
1018 | eshow( "num ", num ); | ||
1019 | eshow( "den ", den ); | ||
1020 | printf( "tnum = %08lx, tden = %04x, tquot = %04x\n", | ||
1021 | tnum, den[M+1], tquot ); | ||
1022 | } | ||
1023 | */ | ||
1024 | equot[i] = tquot; | ||
1025 | eshup6(num); | ||
1026 | } | ||
1027 | /* test for nonzero remainder after roundoff bit */ | ||
1028 | p = &num[M]; | ||
1029 | j = 0; | ||
1030 | for( i=M; i<NI; i++ ) | ||
1031 | { | ||
1032 | j |= *p++; | ||
1033 | } | ||
1034 | if( j ) | ||
1035 | j = 1; | ||
1036 | |||
1037 | for( i=0; i<NI; i++ ) | ||
1038 | num[i] = equot[i]; | ||
1039 | |||
1040 | return( (int )j ); | ||
1041 | } | ||
1042 | |||
1043 | |||
1044 | |||
1045 | /* Multiply significands */ | ||
1046 | int emulm( a, b ) | ||
1047 | unsigned short a[], b[]; | ||
1048 | { | ||
1049 | unsigned short *p, *q; | ||
1050 | unsigned short pprod[NI]; | ||
1051 | unsigned short j; | ||
1052 | int i; | ||
1053 | |||
1054 | equot[0] = b[0]; | ||
1055 | equot[1] = b[1]; | ||
1056 | for( i=M; i<NI; i++ ) | ||
1057 | equot[i] = 0; | ||
1058 | |||
1059 | j = 0; | ||
1060 | p = &a[NI-1]; | ||
1061 | q = &equot[NI-1]; | ||
1062 | for( i=M+1; i<NI; i++ ) | ||
1063 | { | ||
1064 | if( *p == 0 ) | ||
1065 | { | ||
1066 | --p; | ||
1067 | } | ||
1068 | else | ||
1069 | { | ||
1070 | m16m( *p--, b, pprod ); | ||
1071 | eaddm(pprod, equot); | ||
1072 | } | ||
1073 | j |= *q; | ||
1074 | eshdn6(equot); | ||
1075 | } | ||
1076 | |||
1077 | for( i=0; i<NI; i++ ) | ||
1078 | b[i] = equot[i]; | ||
1079 | |||
1080 | /* return flag for lost nonzero bits */ | ||
1081 | return( (int)j ); | ||
1082 | } | ||
1083 | |||
1084 | |||
1085 | /* | ||
1086 | eshow(str, x) | ||
1087 | char *str; | ||
1088 | unsigned short *x; | ||
1089 | { | ||
1090 | int i; | ||
1091 | |||
1092 | printf( "%s ", str ); | ||
1093 | for( i=0; i<NI; i++ ) | ||
1094 | printf( "%04x ", *x++ ); | ||
1095 | printf( "\n" ); | ||
1096 | } | ||
1097 | */ | ||
1098 | #endif | ||
1099 | |||
1100 | |||
1101 | |||
1102 | /* | ||
1103 | * Normalize and round off. | ||
1104 | * | ||
1105 | * The internal format number to be rounded is "s". | ||
1106 | * Input "lost" indicates whether the number is exact. | ||
1107 | * This is the so-called sticky bit. | ||
1108 | * | ||
1109 | * Input "subflg" indicates whether the number was obtained | ||
1110 | * by a subtraction operation. In that case if lost is nonzero | ||
1111 | * then the number is slightly smaller than indicated. | ||
1112 | * | ||
1113 | * Input "exp" is the biased exponent, which may be negative. | ||
1114 | * the exponent field of "s" is ignored but is replaced by | ||
1115 | * "exp" as adjusted by normalization and rounding. | ||
1116 | * | ||
1117 | * Input "rcntrl" is the rounding control. | ||
1118 | */ | ||
1119 | |||
1120 | static int rlast = -1; | ||
1121 | static int rw = 0; | ||
1122 | static unsigned short rmsk = 0; | ||
1123 | static unsigned short rmbit = 0; | ||
1124 | static unsigned short rebit = 0; | ||
1125 | static int re = 0; | ||
1126 | static unsigned short rbit[NI] = {0,0,0,0,0,0,0,0}; | ||
1127 | |||
1128 | void emdnorm( s, lost, subflg, exp, rcntrl ) | ||
1129 | unsigned short s[]; | ||
1130 | int lost; | ||
1131 | int subflg; | ||
1132 | long exp; | ||
1133 | int rcntrl; | ||
1134 | { | ||
1135 | int i, j; | ||
1136 | unsigned short r; | ||
1137 | |||
1138 | /* Normalize */ | ||
1139 | j = enormlz( s ); | ||
1140 | |||
1141 | /* a blank significand could mean either zero or infinity. */ | ||
1142 | #ifndef INFINITY | ||
1143 | if( j > NBITS ) | ||
1144 | { | ||
1145 | ecleazs( s ); | ||
1146 | return; | ||
1147 | } | ||
1148 | #endif | ||
1149 | exp -= j; | ||
1150 | #ifndef INFINITY | ||
1151 | if( exp >= 32767L ) | ||
1152 | goto overf; | ||
1153 | #else | ||
1154 | if( (j > NBITS) && (exp < 32767L) ) | ||
1155 | { | ||
1156 | ecleazs( s ); | ||
1157 | return; | ||
1158 | } | ||
1159 | #endif | ||
1160 | if( exp < 0L ) | ||
1161 | { | ||
1162 | if( exp > (long )(-NBITS-1) ) | ||
1163 | { | ||
1164 | j = (int )exp; | ||
1165 | i = eshift( s, j ); | ||
1166 | if( i ) | ||
1167 | lost = 1; | ||
1168 | } | ||
1169 | else | ||
1170 | { | ||
1171 | ecleazs( s ); | ||
1172 | return; | ||
1173 | } | ||
1174 | } | ||
1175 | /* Round off, unless told not to by rcntrl. */ | ||
1176 | if( rcntrl == 0 ) | ||
1177 | goto mdfin; | ||
1178 | /* Set up rounding parameters if the control register changed. */ | ||
1179 | if( rndprc != rlast ) | ||
1180 | { | ||
1181 | ecleaz( rbit ); | ||
1182 | switch( rndprc ) | ||
1183 | { | ||
1184 | default: | ||
1185 | case NBITS: | ||
1186 | rw = NI-1; /* low guard word */ | ||
1187 | rmsk = 0xffff; | ||
1188 | rmbit = 0x8000; | ||
1189 | rebit = 1; | ||
1190 | re = rw - 1; | ||
1191 | break; | ||
1192 | case 113: | ||
1193 | rw = 10; | ||
1194 | rmsk = 0x7fff; | ||
1195 | rmbit = 0x4000; | ||
1196 | rebit = 0x8000; | ||
1197 | re = rw; | ||
1198 | break; | ||
1199 | case 64: | ||
1200 | rw = 7; | ||
1201 | rmsk = 0xffff; | ||
1202 | rmbit = 0x8000; | ||
1203 | rebit = 1; | ||
1204 | re = rw-1; | ||
1205 | break; | ||
1206 | /* For DEC arithmetic */ | ||
1207 | case 56: | ||
1208 | rw = 6; | ||
1209 | rmsk = 0xff; | ||
1210 | rmbit = 0x80; | ||
1211 | rebit = 0x100; | ||
1212 | re = rw; | ||
1213 | break; | ||
1214 | case 53: | ||
1215 | rw = 6; | ||
1216 | rmsk = 0x7ff; | ||
1217 | rmbit = 0x0400; | ||
1218 | rebit = 0x800; | ||
1219 | re = rw; | ||
1220 | break; | ||
1221 | case 24: | ||
1222 | rw = 4; | ||
1223 | rmsk = 0xff; | ||
1224 | rmbit = 0x80; | ||
1225 | rebit = 0x100; | ||
1226 | re = rw; | ||
1227 | break; | ||
1228 | } | ||
1229 | rbit[re] = rebit; | ||
1230 | rlast = rndprc; | ||
1231 | } | ||
1232 | |||
1233 | /* Shift down 1 temporarily if the data structure has an implied | ||
1234 | * most significant bit and the number is denormal. | ||
1235 | * For rndprc = 64 or NBITS, there is no implied bit. | ||
1236 | * But Intel long double denormals lose one bit of significance even so. | ||
1237 | */ | ||
1238 | #ifdef IBMPC | ||
1239 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
1240 | #else | ||
1241 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
1242 | #endif | ||
1243 | { | ||
1244 | lost |= s[NI-1] & 1; | ||
1245 | eshdn1(s); | ||
1246 | } | ||
1247 | /* Clear out all bits below the rounding bit, | ||
1248 | * remembering in r if any were nonzero. | ||
1249 | */ | ||
1250 | r = s[rw] & rmsk; | ||
1251 | if( rndprc < NBITS ) | ||
1252 | { | ||
1253 | i = rw + 1; | ||
1254 | while( i < NI ) | ||
1255 | { | ||
1256 | if( s[i] ) | ||
1257 | r |= 1; | ||
1258 | s[i] = 0; | ||
1259 | ++i; | ||
1260 | } | ||
1261 | } | ||
1262 | s[rw] &= ~rmsk; | ||
1263 | if( (r & rmbit) != 0 ) | ||
1264 | { | ||
1265 | if( r == rmbit ) | ||
1266 | { | ||
1267 | if( lost == 0 ) | ||
1268 | { /* round to even */ | ||
1269 | if( (s[re] & rebit) == 0 ) | ||
1270 | goto mddone; | ||
1271 | } | ||
1272 | else | ||
1273 | { | ||
1274 | if( subflg != 0 ) | ||
1275 | goto mddone; | ||
1276 | } | ||
1277 | } | ||
1278 | eaddm( rbit, s ); | ||
1279 | } | ||
1280 | mddone: | ||
1281 | #ifdef IBMPC | ||
1282 | if( (exp <= 0) && (rndprc != NBITS) ) | ||
1283 | #else | ||
1284 | if( (exp <= 0) && (rndprc != 64) && (rndprc != NBITS) ) | ||
1285 | #endif | ||
1286 | { | ||
1287 | eshup1(s); | ||
1288 | } | ||
1289 | if( s[2] != 0 ) | ||
1290 | { /* overflow on roundoff */ | ||
1291 | eshdn1(s); | ||
1292 | exp += 1; | ||
1293 | } | ||
1294 | mdfin: | ||
1295 | s[NI-1] = 0; | ||
1296 | if( exp >= 32767L ) | ||
1297 | { | ||
1298 | #ifndef INFINITY | ||
1299 | overf: | ||
1300 | #endif | ||
1301 | #ifdef INFINITY | ||
1302 | s[1] = 32767; | ||
1303 | for( i=2; i<NI-1; i++ ) | ||
1304 | s[i] = 0; | ||
1305 | #else | ||
1306 | s[1] = 32766; | ||
1307 | s[2] = 0; | ||
1308 | for( i=M+1; i<NI-1; i++ ) | ||
1309 | s[i] = 0xffff; | ||
1310 | s[NI-1] = 0; | ||
1311 | if( (rndprc < 64) || (rndprc == 113) ) | ||
1312 | { | ||
1313 | s[rw] &= ~rmsk; | ||
1314 | if( rndprc == 24 ) | ||
1315 | { | ||
1316 | s[5] = 0; | ||
1317 | s[6] = 0; | ||
1318 | } | ||
1319 | } | ||
1320 | #endif | ||
1321 | return; | ||
1322 | } | ||
1323 | if( exp < 0 ) | ||
1324 | s[1] = 0; | ||
1325 | else | ||
1326 | s[1] = (unsigned short )exp; | ||
1327 | } | ||
1328 | |||
1329 | |||
1330 | |||
1331 | /* | ||
1332 | ; Subtract external format numbers. | ||
1333 | ; | ||
1334 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1335 | ; esub( a, b, c ); c = b - a | ||
1336 | */ | ||
1337 | |||
1338 | static int subflg = 0; | ||
1339 | |||
1340 | void esub( a, b, c ) | ||
1341 | unsigned short *a, *b, *c; | ||
1342 | { | ||
1343 | |||
1344 | #ifdef NANS | ||
1345 | if( eisnan(a) ) | ||
1346 | { | ||
1347 | emov (a, c); | ||
1348 | return; | ||
1349 | } | ||
1350 | if( eisnan(b) ) | ||
1351 | { | ||
1352 | emov(b,c); | ||
1353 | return; | ||
1354 | } | ||
1355 | /* Infinity minus infinity is a NaN. | ||
1356 | * Test for subtracting infinities of the same sign. | ||
1357 | */ | ||
1358 | if( eisinf(a) && eisinf(b) && ((eisneg (a) ^ eisneg (b)) == 0)) | ||
1359 | { | ||
1360 | mtherr( "esub", DOMAIN ); | ||
1361 | enan( c, NBITS ); | ||
1362 | return; | ||
1363 | } | ||
1364 | #endif | ||
1365 | subflg = 1; | ||
1366 | eadd1( a, b, c ); | ||
1367 | } | ||
1368 | |||
1369 | |||
1370 | /* | ||
1371 | ; Add. | ||
1372 | ; | ||
1373 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1374 | ; eadd( a, b, c ); c = b + a | ||
1375 | */ | ||
1376 | void eadd( a, b, c ) | ||
1377 | unsigned short *a, *b, *c; | ||
1378 | { | ||
1379 | |||
1380 | #ifdef NANS | ||
1381 | /* NaN plus anything is a NaN. */ | ||
1382 | if( eisnan(a) ) | ||
1383 | { | ||
1384 | emov(a,c); | ||
1385 | return; | ||
1386 | } | ||
1387 | if( eisnan(b) ) | ||
1388 | { | ||
1389 | emov(b,c); | ||
1390 | return; | ||
1391 | } | ||
1392 | /* Infinity minus infinity is a NaN. | ||
1393 | * Test for adding infinities of opposite signs. | ||
1394 | */ | ||
1395 | if( eisinf(a) && eisinf(b) | ||
1396 | && ((eisneg(a) ^ eisneg(b)) != 0) ) | ||
1397 | { | ||
1398 | mtherr( "eadd", DOMAIN ); | ||
1399 | enan( c, NBITS ); | ||
1400 | return; | ||
1401 | } | ||
1402 | #endif | ||
1403 | subflg = 0; | ||
1404 | eadd1( a, b, c ); | ||
1405 | } | ||
1406 | |||
1407 | void eadd1( a, b, c ) | ||
1408 | unsigned short *a, *b, *c; | ||
1409 | { | ||
1410 | unsigned short ai[NI], bi[NI], ci[NI]; | ||
1411 | int i, lost, j, k; | ||
1412 | long lt, lta, ltb; | ||
1413 | |||
1414 | #ifdef INFINITY | ||
1415 | if( eisinf(a) ) | ||
1416 | { | ||
1417 | emov(a,c); | ||
1418 | if( subflg ) | ||
1419 | eneg(c); | ||
1420 | return; | ||
1421 | } | ||
1422 | if( eisinf(b) ) | ||
1423 | { | ||
1424 | emov(b,c); | ||
1425 | return; | ||
1426 | } | ||
1427 | #endif | ||
1428 | emovi( a, ai ); | ||
1429 | emovi( b, bi ); | ||
1430 | if( subflg ) | ||
1431 | ai[0] = ~ai[0]; | ||
1432 | |||
1433 | /* compare exponents */ | ||
1434 | lta = ai[E]; | ||
1435 | ltb = bi[E]; | ||
1436 | lt = lta - ltb; | ||
1437 | if( lt > 0L ) | ||
1438 | { /* put the larger number in bi */ | ||
1439 | emovz( bi, ci ); | ||
1440 | emovz( ai, bi ); | ||
1441 | emovz( ci, ai ); | ||
1442 | ltb = bi[E]; | ||
1443 | lt = -lt; | ||
1444 | } | ||
1445 | lost = 0; | ||
1446 | if( lt != 0L ) | ||
1447 | { | ||
1448 | if( lt < (long )(-NBITS-1) ) | ||
1449 | goto done; /* answer same as larger addend */ | ||
1450 | k = (int )lt; | ||
1451 | lost = eshift( ai, k ); /* shift the smaller number down */ | ||
1452 | } | ||
1453 | else | ||
1454 | { | ||
1455 | /* exponents were the same, so must compare significands */ | ||
1456 | i = ecmpm( ai, bi ); | ||
1457 | if( i == 0 ) | ||
1458 | { /* the numbers are identical in magnitude */ | ||
1459 | /* if different signs, result is zero */ | ||
1460 | if( ai[0] != bi[0] ) | ||
1461 | { | ||
1462 | eclear(c); | ||
1463 | return; | ||
1464 | } | ||
1465 | /* if same sign, result is double */ | ||
1466 | /* double denomalized tiny number */ | ||
1467 | if( (bi[E] == 0) && ((bi[3] & 0x8000) == 0) ) | ||
1468 | { | ||
1469 | eshup1( bi ); | ||
1470 | goto done; | ||
1471 | } | ||
1472 | /* add 1 to exponent unless both are zero! */ | ||
1473 | for( j=1; j<NI-1; j++ ) | ||
1474 | { | ||
1475 | if( bi[j] != 0 ) | ||
1476 | { | ||
1477 | ltb += 1; | ||
1478 | if( ltb >= 0x7fff ) | ||
1479 | { | ||
1480 | eclear(c); | ||
1481 | einfin(c); | ||
1482 | if( ai[0] != 0 ) | ||
1483 | eneg(c); | ||
1484 | return; | ||
1485 | } | ||
1486 | break; | ||
1487 | } | ||
1488 | } | ||
1489 | bi[E] = (unsigned short )ltb; | ||
1490 | goto done; | ||
1491 | } | ||
1492 | if( i > 0 ) | ||
1493 | { /* put the larger number in bi */ | ||
1494 | emovz( bi, ci ); | ||
1495 | emovz( ai, bi ); | ||
1496 | emovz( ci, ai ); | ||
1497 | } | ||
1498 | } | ||
1499 | if( ai[0] == bi[0] ) | ||
1500 | { | ||
1501 | eaddm( ai, bi ); | ||
1502 | subflg = 0; | ||
1503 | } | ||
1504 | else | ||
1505 | { | ||
1506 | esubm( ai, bi ); | ||
1507 | subflg = 1; | ||
1508 | } | ||
1509 | emdnorm( bi, lost, subflg, ltb, 64 ); | ||
1510 | |||
1511 | done: | ||
1512 | emovo( bi, c ); | ||
1513 | } | ||
1514 | |||
1515 | |||
1516 | |||
1517 | /* | ||
1518 | ; Divide. | ||
1519 | ; | ||
1520 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1521 | ; ediv( a, b, c ); c = b / a | ||
1522 | */ | ||
1523 | void ediv( a, b, c ) | ||
1524 | unsigned short *a, *b, *c; | ||
1525 | { | ||
1526 | unsigned short ai[NI], bi[NI]; | ||
1527 | int i, sign; | ||
1528 | long lt, lta, ltb; | ||
1529 | |||
1530 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
1531 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
1532 | sign = eisneg(a) ^ eisneg(b); | ||
1533 | |||
1534 | #ifdef NANS | ||
1535 | /* Return any NaN input. */ | ||
1536 | if( eisnan(a) ) | ||
1537 | { | ||
1538 | emov(a,c); | ||
1539 | return; | ||
1540 | } | ||
1541 | if( eisnan(b) ) | ||
1542 | { | ||
1543 | emov(b,c); | ||
1544 | return; | ||
1545 | } | ||
1546 | /* Zero over zero, or infinity over infinity, is a NaN. */ | ||
1547 | if( ((ecmp(a,ezero) == 0) && (ecmp(b,ezero) == 0)) | ||
1548 | || (eisinf (a) && eisinf (b)) ) | ||
1549 | { | ||
1550 | mtherr( "ediv", DOMAIN ); | ||
1551 | enan( c, NBITS ); | ||
1552 | return; | ||
1553 | } | ||
1554 | #endif | ||
1555 | /* Infinity over anything else is infinity. */ | ||
1556 | #ifdef INFINITY | ||
1557 | if( eisinf(b) ) | ||
1558 | { | ||
1559 | einfin(c); | ||
1560 | goto divsign; | ||
1561 | } | ||
1562 | if( eisinf(a) ) | ||
1563 | { | ||
1564 | eclear(c); | ||
1565 | goto divsign; | ||
1566 | } | ||
1567 | #endif | ||
1568 | emovi( a, ai ); | ||
1569 | emovi( b, bi ); | ||
1570 | lta = ai[E]; | ||
1571 | ltb = bi[E]; | ||
1572 | if( bi[E] == 0 ) | ||
1573 | { /* See if numerator is zero. */ | ||
1574 | for( i=1; i<NI-1; i++ ) | ||
1575 | { | ||
1576 | if( bi[i] != 0 ) | ||
1577 | { | ||
1578 | ltb -= enormlz( bi ); | ||
1579 | goto dnzro1; | ||
1580 | } | ||
1581 | } | ||
1582 | eclear(c); | ||
1583 | goto divsign; | ||
1584 | } | ||
1585 | dnzro1: | ||
1586 | |||
1587 | if( ai[E] == 0 ) | ||
1588 | { /* possible divide by zero */ | ||
1589 | for( i=1; i<NI-1; i++ ) | ||
1590 | { | ||
1591 | if( ai[i] != 0 ) | ||
1592 | { | ||
1593 | lta -= enormlz( ai ); | ||
1594 | goto dnzro2; | ||
1595 | } | ||
1596 | } | ||
1597 | einfin(c); | ||
1598 | mtherr( "ediv", SING ); | ||
1599 | goto divsign; | ||
1600 | } | ||
1601 | dnzro2: | ||
1602 | |||
1603 | i = edivm( ai, bi ); | ||
1604 | /* calculate exponent */ | ||
1605 | lt = ltb - lta + EXONE; | ||
1606 | emdnorm( bi, i, 0, lt, 64 ); | ||
1607 | emovo( bi, c ); | ||
1608 | |||
1609 | divsign: | ||
1610 | |||
1611 | if( sign ) | ||
1612 | *(c+(NE-1)) |= 0x8000; | ||
1613 | else | ||
1614 | *(c+(NE-1)) &= ~0x8000; | ||
1615 | } | ||
1616 | |||
1617 | |||
1618 | |||
1619 | /* | ||
1620 | ; Multiply. | ||
1621 | ; | ||
1622 | ; unsigned short a[NE], b[NE], c[NE]; | ||
1623 | ; emul( a, b, c ); c = b * a | ||
1624 | */ | ||
1625 | void emul( a, b, c ) | ||
1626 | unsigned short *a, *b, *c; | ||
1627 | { | ||
1628 | unsigned short ai[NI], bi[NI]; | ||
1629 | int i, j, sign; | ||
1630 | long lt, lta, ltb; | ||
1631 | |||
1632 | /* IEEE says if result is not a NaN, the sign is "-" if and only if | ||
1633 | operands have opposite signs -- but flush -0 to 0 later if not IEEE. */ | ||
1634 | sign = eisneg(a) ^ eisneg(b); | ||
1635 | |||
1636 | #ifdef NANS | ||
1637 | /* NaN times anything is the same NaN. */ | ||
1638 | if( eisnan(a) ) | ||
1639 | { | ||
1640 | emov(a,c); | ||
1641 | return; | ||
1642 | } | ||
1643 | if( eisnan(b) ) | ||
1644 | { | ||
1645 | emov(b,c); | ||
1646 | return; | ||
1647 | } | ||
1648 | /* Zero times infinity is a NaN. */ | ||
1649 | if( (eisinf(a) && (ecmp(b,ezero) == 0)) | ||
1650 | || (eisinf(b) && (ecmp(a,ezero) == 0)) ) | ||
1651 | { | ||
1652 | mtherr( "emul", DOMAIN ); | ||
1653 | enan( c, NBITS ); | ||
1654 | return; | ||
1655 | } | ||
1656 | #endif | ||
1657 | /* Infinity times anything else is infinity. */ | ||
1658 | #ifdef INFINITY | ||
1659 | if( eisinf(a) || eisinf(b) ) | ||
1660 | { | ||
1661 | einfin(c); | ||
1662 | goto mulsign; | ||
1663 | } | ||
1664 | #endif | ||
1665 | emovi( a, ai ); | ||
1666 | emovi( b, bi ); | ||
1667 | lta = ai[E]; | ||
1668 | ltb = bi[E]; | ||
1669 | if( ai[E] == 0 ) | ||
1670 | { | ||
1671 | for( i=1; i<NI-1; i++ ) | ||
1672 | { | ||
1673 | if( ai[i] != 0 ) | ||
1674 | { | ||
1675 | lta -= enormlz( ai ); | ||
1676 | goto mnzer1; | ||
1677 | } | ||
1678 | } | ||
1679 | eclear(c); | ||
1680 | goto mulsign; | ||
1681 | } | ||
1682 | mnzer1: | ||
1683 | |||
1684 | if( bi[E] == 0 ) | ||
1685 | { | ||
1686 | for( i=1; i<NI-1; i++ ) | ||
1687 | { | ||
1688 | if( bi[i] != 0 ) | ||
1689 | { | ||
1690 | ltb -= enormlz( bi ); | ||
1691 | goto mnzer2; | ||
1692 | } | ||
1693 | } | ||
1694 | eclear(c); | ||
1695 | goto mulsign; | ||
1696 | } | ||
1697 | mnzer2: | ||
1698 | |||
1699 | /* Multiply significands */ | ||
1700 | j = emulm( ai, bi ); | ||
1701 | /* calculate exponent */ | ||
1702 | lt = lta + ltb - (EXONE - 1); | ||
1703 | emdnorm( bi, j, 0, lt, 64 ); | ||
1704 | emovo( bi, c ); | ||
1705 | /* IEEE says sign is "-" if and only if operands have opposite signs. */ | ||
1706 | mulsign: | ||
1707 | if( sign ) | ||
1708 | *(c+(NE-1)) |= 0x8000; | ||
1709 | else | ||
1710 | *(c+(NE-1)) &= ~0x8000; | ||
1711 | } | ||
1712 | |||
1713 | |||
1714 | |||
1715 | |||
1716 | /* | ||
1717 | ; Convert IEEE double precision to e type | ||
1718 | ; double d; | ||
1719 | ; unsigned short x[N+2]; | ||
1720 | ; e53toe( &d, x ); | ||
1721 | */ | ||
1722 | void e53toe( pe, y ) | ||
1723 | unsigned short *pe, *y; | ||
1724 | { | ||
1725 | #ifdef DEC | ||
1726 | |||
1727 | dectoe( pe, y ); /* see etodec.c */ | ||
1728 | |||
1729 | #else | ||
1730 | |||
1731 | register unsigned short r; | ||
1732 | register unsigned short *p, *e; | ||
1733 | unsigned short yy[NI]; | ||
1734 | int denorm, k; | ||
1735 | |||
1736 | e = pe; | ||
1737 | denorm = 0; /* flag if denormalized number */ | ||
1738 | ecleaz(yy); | ||
1739 | #ifdef IBMPC | ||
1740 | e += 3; | ||
1741 | #endif | ||
1742 | r = *e; | ||
1743 | yy[0] = 0; | ||
1744 | if( r & 0x8000 ) | ||
1745 | yy[0] = 0xffff; | ||
1746 | yy[M] = (r & 0x0f) | 0x10; | ||
1747 | r &= ~0x800f; /* strip sign and 4 significand bits */ | ||
1748 | #ifdef INFINITY | ||
1749 | if( r == 0x7ff0 ) | ||
1750 | { | ||
1751 | #ifdef NANS | ||
1752 | #ifdef IBMPC | ||
1753 | if( ((pe[3] & 0xf) != 0) || (pe[2] != 0) | ||
1754 | || (pe[1] != 0) || (pe[0] != 0) ) | ||
1755 | { | ||
1756 | enan( y, NBITS ); | ||
1757 | return; | ||
1758 | } | ||
1759 | #else | ||
1760 | if( ((pe[0] & 0xf) != 0) || (pe[1] != 0) | ||
1761 | || (pe[2] != 0) || (pe[3] != 0) ) | ||
1762 | { | ||
1763 | enan( y, NBITS ); | ||
1764 | return; | ||
1765 | } | ||
1766 | #endif | ||
1767 | #endif /* NANS */ | ||
1768 | eclear( y ); | ||
1769 | einfin( y ); | ||
1770 | if( yy[0] ) | ||
1771 | eneg(y); | ||
1772 | return; | ||
1773 | } | ||
1774 | #endif | ||
1775 | r >>= 4; | ||
1776 | /* If zero exponent, then the significand is denormalized. | ||
1777 | * So, take back the understood high significand bit. */ | ||
1778 | if( r == 0 ) | ||
1779 | { | ||
1780 | denorm = 1; | ||
1781 | yy[M] &= ~0x10; | ||
1782 | } | ||
1783 | r += EXONE - 01777; | ||
1784 | yy[E] = r; | ||
1785 | p = &yy[M+1]; | ||
1786 | #ifdef IBMPC | ||
1787 | *p++ = *(--e); | ||
1788 | *p++ = *(--e); | ||
1789 | *p++ = *(--e); | ||
1790 | #endif | ||
1791 | #ifdef MIEEE | ||
1792 | ++e; | ||
1793 | *p++ = *e++; | ||
1794 | *p++ = *e++; | ||
1795 | *p++ = *e++; | ||
1796 | #endif | ||
1797 | (void )eshift( yy, -5 ); | ||
1798 | if( denorm ) | ||
1799 | { /* if zero exponent, then normalize the significand */ | ||
1800 | if( (k = enormlz(yy)) > NBITS ) | ||
1801 | ecleazs(yy); | ||
1802 | else | ||
1803 | yy[E] -= (unsigned short )(k-1); | ||
1804 | } | ||
1805 | emovo( yy, y ); | ||
1806 | #endif /* not DEC */ | ||
1807 | } | ||
1808 | |||
1809 | void e64toe( pe, y ) | ||
1810 | unsigned short *pe, *y; | ||
1811 | { | ||
1812 | unsigned short yy[NI]; | ||
1813 | unsigned short *p, *q, *e; | ||
1814 | int i; | ||
1815 | |||
1816 | e = pe; | ||
1817 | p = yy; | ||
1818 | for( i=0; i<NE-5; i++ ) | ||
1819 | *p++ = 0; | ||
1820 | #ifdef IBMPC | ||
1821 | for( i=0; i<5; i++ ) | ||
1822 | *p++ = *e++; | ||
1823 | #endif | ||
1824 | #ifdef DEC | ||
1825 | for( i=0; i<5; i++ ) | ||
1826 | *p++ = *e++; | ||
1827 | #endif | ||
1828 | #ifdef MIEEE | ||
1829 | p = &yy[0] + (NE-1); | ||
1830 | *p-- = *e++; | ||
1831 | ++e; | ||
1832 | for( i=0; i<4; i++ ) | ||
1833 | *p-- = *e++; | ||
1834 | #endif | ||
1835 | |||
1836 | #ifdef IBMPC | ||
1837 | /* For Intel long double, shift denormal significand up 1 | ||
1838 | -- but only if the top significand bit is zero. */ | ||
1839 | if((yy[NE-1] & 0x7fff) == 0 && (yy[NE-2] & 0x8000) == 0) | ||
1840 | { | ||
1841 | unsigned short temp[NI+1]; | ||
1842 | emovi(yy, temp); | ||
1843 | eshup1(temp); | ||
1844 | emovo(temp,y); | ||
1845 | return; | ||
1846 | } | ||
1847 | #endif | ||
1848 | #ifdef INFINITY | ||
1849 | /* Point to the exponent field. */ | ||
1850 | p = &yy[NE-1]; | ||
1851 | if ((*p & 0x7fff) == 0x7fff) | ||
1852 | { | ||
1853 | #ifdef NANS | ||
1854 | #ifdef IBMPC | ||
1855 | for( i=0; i<4; i++ ) | ||
1856 | { | ||
1857 | if((i != 3 && pe[i] != 0) | ||
1858 | /* Check for Intel long double infinity pattern. */ | ||
1859 | || (i == 3 && pe[i] != 0x8000)) | ||
1860 | { | ||
1861 | enan( y, NBITS ); | ||
1862 | return; | ||
1863 | } | ||
1864 | } | ||
1865 | #else | ||
1866 | /* In Motorola extended precision format, the most significant | ||
1867 | bit of an infinity mantissa could be either 1 or 0. It is | ||
1868 | the lower order bits that tell whether the value is a NaN. */ | ||
1869 | if ((pe[2] & 0x7fff) != 0) | ||
1870 | goto bigend_nan; | ||
1871 | |||
1872 | for( i=3; i<=5; i++ ) | ||
1873 | { | ||
1874 | if( pe[i] != 0 ) | ||
1875 | { | ||
1876 | bigend_nan: | ||
1877 | enan( y, NBITS ); | ||
1878 | return; | ||
1879 | } | ||
1880 | } | ||
1881 | #endif | ||
1882 | #endif /* NANS */ | ||
1883 | eclear( y ); | ||
1884 | einfin( y ); | ||
1885 | if( *p & 0x8000 ) | ||
1886 | eneg(y); | ||
1887 | return; | ||
1888 | } | ||
1889 | #endif | ||
1890 | p = yy; | ||
1891 | q = y; | ||
1892 | for( i=0; i<NE; i++ ) | ||
1893 | *q++ = *p++; | ||
1894 | } | ||
1895 | |||
1896 | void e113toe(pe,y) | ||
1897 | unsigned short *pe, *y; | ||
1898 | { | ||
1899 | register unsigned short r; | ||
1900 | unsigned short *e, *p; | ||
1901 | unsigned short yy[NI]; | ||
1902 | int denorm, i; | ||
1903 | |||
1904 | e = pe; | ||
1905 | denorm = 0; | ||
1906 | ecleaz(yy); | ||
1907 | #ifdef IBMPC | ||
1908 | e += 7; | ||
1909 | #endif | ||
1910 | r = *e; | ||
1911 | yy[0] = 0; | ||
1912 | if( r & 0x8000 ) | ||
1913 | yy[0] = 0xffff; | ||
1914 | r &= 0x7fff; | ||
1915 | #ifdef INFINITY | ||
1916 | if( r == 0x7fff ) | ||
1917 | { | ||
1918 | #ifdef NANS | ||
1919 | #ifdef IBMPC | ||
1920 | for( i=0; i<7; i++ ) | ||
1921 | { | ||
1922 | if( pe[i] != 0 ) | ||
1923 | { | ||
1924 | enan( y, NBITS ); | ||
1925 | return; | ||
1926 | } | ||
1927 | } | ||
1928 | #else | ||
1929 | for( i=1; i<8; i++ ) | ||
1930 | { | ||
1931 | if( pe[i] != 0 ) | ||
1932 | { | ||
1933 | enan( y, NBITS ); | ||
1934 | return; | ||
1935 | } | ||
1936 | } | ||
1937 | #endif | ||
1938 | #endif /* NANS */ | ||
1939 | eclear( y ); | ||
1940 | einfin( y ); | ||
1941 | if( *e & 0x8000 ) | ||
1942 | eneg(y); | ||
1943 | return; | ||
1944 | } | ||
1945 | #endif /* INFINITY */ | ||
1946 | yy[E] = r; | ||
1947 | p = &yy[M + 1]; | ||
1948 | #ifdef IBMPC | ||
1949 | for( i=0; i<7; i++ ) | ||
1950 | *p++ = *(--e); | ||
1951 | #endif | ||
1952 | #ifdef MIEEE | ||
1953 | ++e; | ||
1954 | for( i=0; i<7; i++ ) | ||
1955 | *p++ = *e++; | ||
1956 | #endif | ||
1957 | /* If denormal, remove the implied bit; else shift down 1. */ | ||
1958 | if( r == 0 ) | ||
1959 | { | ||
1960 | yy[M] = 0; | ||
1961 | } | ||
1962 | else | ||
1963 | { | ||
1964 | yy[M] = 1; | ||
1965 | eshift( yy, -1 ); | ||
1966 | } | ||
1967 | emovo(yy,y); | ||
1968 | } | ||
1969 | |||
1970 | |||
1971 | /* | ||
1972 | ; Convert IEEE single precision to e type | ||
1973 | ; float d; | ||
1974 | ; unsigned short x[N+2]; | ||
1975 | ; dtox( &d, x ); | ||
1976 | */ | ||
1977 | void e24toe( pe, y ) | ||
1978 | unsigned short *pe, *y; | ||
1979 | { | ||
1980 | register unsigned short r; | ||
1981 | register unsigned short *p, *e; | ||
1982 | unsigned short yy[NI]; | ||
1983 | int denorm, k; | ||
1984 | |||
1985 | e = pe; | ||
1986 | denorm = 0; /* flag if denormalized number */ | ||
1987 | ecleaz(yy); | ||
1988 | #ifdef IBMPC | ||
1989 | e += 1; | ||
1990 | #endif | ||
1991 | #ifdef DEC | ||
1992 | e += 1; | ||
1993 | #endif | ||
1994 | r = *e; | ||
1995 | yy[0] = 0; | ||
1996 | if( r & 0x8000 ) | ||
1997 | yy[0] = 0xffff; | ||
1998 | yy[M] = (r & 0x7f) | 0200; | ||
1999 | r &= ~0x807f; /* strip sign and 7 significand bits */ | ||
2000 | #ifdef INFINITY | ||
2001 | if( r == 0x7f80 ) | ||
2002 | { | ||
2003 | #ifdef NANS | ||
2004 | #ifdef MIEEE | ||
2005 | if( ((pe[0] & 0x7f) != 0) || (pe[1] != 0) ) | ||
2006 | { | ||
2007 | enan( y, NBITS ); | ||
2008 | return; | ||
2009 | } | ||
2010 | #else | ||
2011 | if( ((pe[1] & 0x7f) != 0) || (pe[0] != 0) ) | ||
2012 | { | ||
2013 | enan( y, NBITS ); | ||
2014 | return; | ||
2015 | } | ||
2016 | #endif | ||
2017 | #endif /* NANS */ | ||
2018 | eclear( y ); | ||
2019 | einfin( y ); | ||
2020 | if( yy[0] ) | ||
2021 | eneg(y); | ||
2022 | return; | ||
2023 | } | ||
2024 | #endif | ||
2025 | r >>= 7; | ||
2026 | /* If zero exponent, then the significand is denormalized. | ||
2027 | * So, take back the understood high significand bit. */ | ||
2028 | if( r == 0 ) | ||
2029 | { | ||
2030 | denorm = 1; | ||
2031 | yy[M] &= ~0200; | ||
2032 | } | ||
2033 | r += EXONE - 0177; | ||
2034 | yy[E] = r; | ||
2035 | p = &yy[M+1]; | ||
2036 | #ifdef IBMPC | ||
2037 | *p++ = *(--e); | ||
2038 | #endif | ||
2039 | #ifdef DEC | ||
2040 | *p++ = *(--e); | ||
2041 | #endif | ||
2042 | #ifdef MIEEE | ||
2043 | ++e; | ||
2044 | *p++ = *e++; | ||
2045 | #endif | ||
2046 | (void )eshift( yy, -8 ); | ||
2047 | if( denorm ) | ||
2048 | { /* if zero exponent, then normalize the significand */ | ||
2049 | if( (k = enormlz(yy)) > NBITS ) | ||
2050 | ecleazs(yy); | ||
2051 | else | ||
2052 | yy[E] -= (unsigned short )(k-1); | ||
2053 | } | ||
2054 | emovo( yy, y ); | ||
2055 | } | ||
2056 | |||
2057 | void etoe113(x,e) | ||
2058 | unsigned short *x, *e; | ||
2059 | { | ||
2060 | unsigned short xi[NI]; | ||
2061 | long exp; | ||
2062 | int rndsav; | ||
2063 | |||
2064 | #ifdef NANS | ||
2065 | if( eisnan(x) ) | ||
2066 | { | ||
2067 | enan( e, 113 ); | ||
2068 | return; | ||
2069 | } | ||
2070 | #endif | ||
2071 | emovi( x, xi ); | ||
2072 | exp = (long )xi[E]; | ||
2073 | #ifdef INFINITY | ||
2074 | if( eisinf(x) ) | ||
2075 | goto nonorm; | ||
2076 | #endif | ||
2077 | /* round off to nearest or even */ | ||
2078 | rndsav = rndprc; | ||
2079 | rndprc = 113; | ||
2080 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2081 | rndprc = rndsav; | ||
2082 | nonorm: | ||
2083 | toe113 (xi, e); | ||
2084 | } | ||
2085 | |||
2086 | /* move out internal format to ieee long double */ | ||
2087 | static void toe113(a,b) | ||
2088 | unsigned short *a, *b; | ||
2089 | { | ||
2090 | register unsigned short *p, *q; | ||
2091 | unsigned short i; | ||
2092 | |||
2093 | #ifdef NANS | ||
2094 | if( eiisnan(a) ) | ||
2095 | { | ||
2096 | enan( b, 113 ); | ||
2097 | return; | ||
2098 | } | ||
2099 | #endif | ||
2100 | p = a; | ||
2101 | #ifdef MIEEE | ||
2102 | q = b; | ||
2103 | #else | ||
2104 | q = b + 7; /* point to output exponent */ | ||
2105 | #endif | ||
2106 | |||
2107 | /* If not denormal, delete the implied bit. */ | ||
2108 | if( a[E] != 0 ) | ||
2109 | { | ||
2110 | eshup1 (a); | ||
2111 | } | ||
2112 | /* combine sign and exponent */ | ||
2113 | i = *p++; | ||
2114 | #ifdef MIEEE | ||
2115 | if( i ) | ||
2116 | *q++ = *p++ | 0x8000; | ||
2117 | else | ||
2118 | *q++ = *p++; | ||
2119 | #else | ||
2120 | if( i ) | ||
2121 | *q-- = *p++ | 0x8000; | ||
2122 | else | ||
2123 | *q-- = *p++; | ||
2124 | #endif | ||
2125 | /* skip over guard word */ | ||
2126 | ++p; | ||
2127 | /* move the significand */ | ||
2128 | #ifdef MIEEE | ||
2129 | for (i = 0; i < 7; i++) | ||
2130 | *q++ = *p++; | ||
2131 | #else | ||
2132 | for (i = 0; i < 7; i++) | ||
2133 | *q-- = *p++; | ||
2134 | #endif | ||
2135 | } | ||
2136 | |||
2137 | |||
2138 | void etoe64( x, e ) | ||
2139 | unsigned short *x, *e; | ||
2140 | { | ||
2141 | unsigned short xi[NI]; | ||
2142 | long exp; | ||
2143 | int rndsav; | ||
2144 | |||
2145 | #ifdef NANS | ||
2146 | if( eisnan(x) ) | ||
2147 | { | ||
2148 | enan( e, 64 ); | ||
2149 | return; | ||
2150 | } | ||
2151 | #endif | ||
2152 | emovi( x, xi ); | ||
2153 | exp = (long )xi[E]; /* adjust exponent for offset */ | ||
2154 | #ifdef INFINITY | ||
2155 | if( eisinf(x) ) | ||
2156 | goto nonorm; | ||
2157 | #endif | ||
2158 | /* round off to nearest or even */ | ||
2159 | rndsav = rndprc; | ||
2160 | rndprc = 64; | ||
2161 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2162 | rndprc = rndsav; | ||
2163 | nonorm: | ||
2164 | toe64( xi, e ); | ||
2165 | } | ||
2166 | |||
2167 | /* move out internal format to ieee long double */ | ||
2168 | static void toe64( a, b ) | ||
2169 | unsigned short *a, *b; | ||
2170 | { | ||
2171 | register unsigned short *p, *q; | ||
2172 | unsigned short i; | ||
2173 | |||
2174 | #ifdef NANS | ||
2175 | if( eiisnan(a) ) | ||
2176 | { | ||
2177 | enan( b, 64 ); | ||
2178 | return; | ||
2179 | } | ||
2180 | #endif | ||
2181 | #ifdef IBMPC | ||
2182 | /* Shift Intel denormal significand down 1. */ | ||
2183 | if( a[E] == 0 ) | ||
2184 | eshdn1(a); | ||
2185 | #endif | ||
2186 | p = a; | ||
2187 | #ifdef MIEEE | ||
2188 | q = b; | ||
2189 | #else | ||
2190 | q = b + 4; /* point to output exponent */ | ||
2191 | #if 1 | ||
2192 | /* NOTE: if data type is 96 bits wide, clear the last word here. */ | ||
2193 | *(q+1)= 0; | ||
2194 | #endif | ||
2195 | #endif | ||
2196 | |||
2197 | /* combine sign and exponent */ | ||
2198 | i = *p++; | ||
2199 | #ifdef MIEEE | ||
2200 | if( i ) | ||
2201 | *q++ = *p++ | 0x8000; | ||
2202 | else | ||
2203 | *q++ = *p++; | ||
2204 | *q++ = 0; | ||
2205 | #else | ||
2206 | if( i ) | ||
2207 | *q-- = *p++ | 0x8000; | ||
2208 | else | ||
2209 | *q-- = *p++; | ||
2210 | #endif | ||
2211 | /* skip over guard word */ | ||
2212 | ++p; | ||
2213 | /* move the significand */ | ||
2214 | #ifdef MIEEE | ||
2215 | for( i=0; i<4; i++ ) | ||
2216 | *q++ = *p++; | ||
2217 | #else | ||
2218 | #ifdef INFINITY | ||
2219 | if (eiisinf (a)) | ||
2220 | { | ||
2221 | /* Intel long double infinity. */ | ||
2222 | *q-- = 0x8000; | ||
2223 | *q-- = 0; | ||
2224 | *q-- = 0; | ||
2225 | *q = 0; | ||
2226 | return; | ||
2227 | } | ||
2228 | #endif | ||
2229 | for( i=0; i<4; i++ ) | ||
2230 | *q-- = *p++; | ||
2231 | #endif | ||
2232 | } | ||
2233 | |||
2234 | |||
2235 | /* | ||
2236 | ; e type to IEEE double precision | ||
2237 | ; double d; | ||
2238 | ; unsigned short x[NE]; | ||
2239 | ; etoe53( x, &d ); | ||
2240 | */ | ||
2241 | |||
2242 | #ifdef DEC | ||
2243 | |||
2244 | void etoe53( x, e ) | ||
2245 | unsigned short *x, *e; | ||
2246 | { | ||
2247 | etodec( x, e ); /* see etodec.c */ | ||
2248 | } | ||
2249 | |||
2250 | static void toe53( x, y ) | ||
2251 | unsigned short *x, *y; | ||
2252 | { | ||
2253 | todec( x, y ); | ||
2254 | } | ||
2255 | |||
2256 | #else | ||
2257 | |||
2258 | void etoe53( x, e ) | ||
2259 | unsigned short *x, *e; | ||
2260 | { | ||
2261 | unsigned short xi[NI]; | ||
2262 | long exp; | ||
2263 | int rndsav; | ||
2264 | |||
2265 | #ifdef NANS | ||
2266 | if( eisnan(x) ) | ||
2267 | { | ||
2268 | enan( e, 53 ); | ||
2269 | return; | ||
2270 | } | ||
2271 | #endif | ||
2272 | emovi( x, xi ); | ||
2273 | exp = (long )xi[E] - (EXONE - 0x3ff); /* adjust exponent for offsets */ | ||
2274 | #ifdef INFINITY | ||
2275 | if( eisinf(x) ) | ||
2276 | goto nonorm; | ||
2277 | #endif | ||
2278 | /* round off to nearest or even */ | ||
2279 | rndsav = rndprc; | ||
2280 | rndprc = 53; | ||
2281 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2282 | rndprc = rndsav; | ||
2283 | nonorm: | ||
2284 | toe53( xi, e ); | ||
2285 | } | ||
2286 | |||
2287 | |||
2288 | static void toe53( x, y ) | ||
2289 | unsigned short *x, *y; | ||
2290 | { | ||
2291 | unsigned short i; | ||
2292 | unsigned short *p; | ||
2293 | |||
2294 | |||
2295 | #ifdef NANS | ||
2296 | if( eiisnan(x) ) | ||
2297 | { | ||
2298 | enan( y, 53 ); | ||
2299 | return; | ||
2300 | } | ||
2301 | #endif | ||
2302 | p = &x[0]; | ||
2303 | #ifdef IBMPC | ||
2304 | y += 3; | ||
2305 | #endif | ||
2306 | *y = 0; /* output high order */ | ||
2307 | if( *p++ ) | ||
2308 | *y = 0x8000; /* output sign bit */ | ||
2309 | |||
2310 | i = *p++; | ||
2311 | if( i >= (unsigned int )2047 ) | ||
2312 | { /* Saturate at largest number less than infinity. */ | ||
2313 | #ifdef INFINITY | ||
2314 | *y |= 0x7ff0; | ||
2315 | #ifdef IBMPC | ||
2316 | *(--y) = 0; | ||
2317 | *(--y) = 0; | ||
2318 | *(--y) = 0; | ||
2319 | #endif | ||
2320 | #ifdef MIEEE | ||
2321 | ++y; | ||
2322 | *y++ = 0; | ||
2323 | *y++ = 0; | ||
2324 | *y++ = 0; | ||
2325 | #endif | ||
2326 | #else | ||
2327 | *y |= (unsigned short )0x7fef; | ||
2328 | #ifdef IBMPC | ||
2329 | *(--y) = 0xffff; | ||
2330 | *(--y) = 0xffff; | ||
2331 | *(--y) = 0xffff; | ||
2332 | #endif | ||
2333 | #ifdef MIEEE | ||
2334 | ++y; | ||
2335 | *y++ = 0xffff; | ||
2336 | *y++ = 0xffff; | ||
2337 | *y++ = 0xffff; | ||
2338 | #endif | ||
2339 | #endif | ||
2340 | return; | ||
2341 | } | ||
2342 | if( i == 0 ) | ||
2343 | { | ||
2344 | (void )eshift( x, 4 ); | ||
2345 | } | ||
2346 | else | ||
2347 | { | ||
2348 | i <<= 4; | ||
2349 | (void )eshift( x, 5 ); | ||
2350 | } | ||
2351 | i |= *p++ & (unsigned short )0x0f; /* *p = xi[M] */ | ||
2352 | *y |= (unsigned short )i; /* high order output already has sign bit set */ | ||
2353 | #ifdef IBMPC | ||
2354 | *(--y) = *p++; | ||
2355 | *(--y) = *p++; | ||
2356 | *(--y) = *p; | ||
2357 | #endif | ||
2358 | #ifdef MIEEE | ||
2359 | ++y; | ||
2360 | *y++ = *p++; | ||
2361 | *y++ = *p++; | ||
2362 | *y++ = *p++; | ||
2363 | #endif | ||
2364 | } | ||
2365 | |||
2366 | #endif /* not DEC */ | ||
2367 | |||
2368 | |||
2369 | |||
2370 | /* | ||
2371 | ; e type to IEEE single precision | ||
2372 | ; float d; | ||
2373 | ; unsigned short x[N+2]; | ||
2374 | ; xtod( x, &d ); | ||
2375 | */ | ||
2376 | void etoe24( x, e ) | ||
2377 | unsigned short *x, *e; | ||
2378 | { | ||
2379 | long exp; | ||
2380 | unsigned short xi[NI]; | ||
2381 | int rndsav; | ||
2382 | |||
2383 | #ifdef NANS | ||
2384 | if( eisnan(x) ) | ||
2385 | { | ||
2386 | enan( e, 24 ); | ||
2387 | return; | ||
2388 | } | ||
2389 | #endif | ||
2390 | emovi( x, xi ); | ||
2391 | exp = (long )xi[E] - (EXONE - 0177); /* adjust exponent for offsets */ | ||
2392 | #ifdef INFINITY | ||
2393 | if( eisinf(x) ) | ||
2394 | goto nonorm; | ||
2395 | #endif | ||
2396 | /* round off to nearest or even */ | ||
2397 | rndsav = rndprc; | ||
2398 | rndprc = 24; | ||
2399 | emdnorm( xi, 0, 0, exp, 64 ); | ||
2400 | rndprc = rndsav; | ||
2401 | nonorm: | ||
2402 | toe24( xi, e ); | ||
2403 | } | ||
2404 | |||
2405 | static void toe24( x, y ) | ||
2406 | unsigned short *x, *y; | ||
2407 | { | ||
2408 | unsigned short i; | ||
2409 | unsigned short *p; | ||
2410 | |||
2411 | #ifdef NANS | ||
2412 | if( eiisnan(x) ) | ||
2413 | { | ||
2414 | enan( y, 24 ); | ||
2415 | return; | ||
2416 | } | ||
2417 | #endif | ||
2418 | p = &x[0]; | ||
2419 | #ifdef IBMPC | ||
2420 | y += 1; | ||
2421 | #endif | ||
2422 | #ifdef DEC | ||
2423 | y += 1; | ||
2424 | #endif | ||
2425 | *y = 0; /* output high order */ | ||
2426 | if( *p++ ) | ||
2427 | *y = 0x8000; /* output sign bit */ | ||
2428 | |||
2429 | i = *p++; | ||
2430 | if( i >= 255 ) | ||
2431 | { /* Saturate at largest number less than infinity. */ | ||
2432 | #ifdef INFINITY | ||
2433 | *y |= (unsigned short )0x7f80; | ||
2434 | #ifdef IBMPC | ||
2435 | *(--y) = 0; | ||
2436 | #endif | ||
2437 | #ifdef DEC | ||
2438 | *(--y) = 0; | ||
2439 | #endif | ||
2440 | #ifdef MIEEE | ||
2441 | ++y; | ||
2442 | *y = 0; | ||
2443 | #endif | ||
2444 | #else | ||
2445 | *y |= (unsigned short )0x7f7f; | ||
2446 | #ifdef IBMPC | ||
2447 | *(--y) = 0xffff; | ||
2448 | #endif | ||
2449 | #ifdef DEC | ||
2450 | *(--y) = 0xffff; | ||
2451 | #endif | ||
2452 | #ifdef MIEEE | ||
2453 | ++y; | ||
2454 | *y = 0xffff; | ||
2455 | #endif | ||
2456 | #endif | ||
2457 | return; | ||
2458 | } | ||
2459 | if( i == 0 ) | ||
2460 | { | ||
2461 | (void )eshift( x, 7 ); | ||
2462 | } | ||
2463 | else | ||
2464 | { | ||
2465 | i <<= 7; | ||
2466 | (void )eshift( x, 8 ); | ||
2467 | } | ||
2468 | i |= *p++ & (unsigned short )0x7f; /* *p = xi[M] */ | ||
2469 | *y |= i; /* high order output already has sign bit set */ | ||
2470 | #ifdef IBMPC | ||
2471 | *(--y) = *p; | ||
2472 | #endif | ||
2473 | #ifdef DEC | ||
2474 | *(--y) = *p; | ||
2475 | #endif | ||
2476 | #ifdef MIEEE | ||
2477 | ++y; | ||
2478 | *y = *p; | ||
2479 | #endif | ||
2480 | } | ||
2481 | |||
2482 | |||
2483 | /* Compare two e type numbers. | ||
2484 | * | ||
2485 | * unsigned short a[NE], b[NE]; | ||
2486 | * ecmp( a, b ); | ||
2487 | * | ||
2488 | * returns +1 if a > b | ||
2489 | * 0 if a == b | ||
2490 | * -1 if a < b | ||
2491 | * -2 if either a or b is a NaN. | ||
2492 | */ | ||
2493 | int ecmp( a, b ) | ||
2494 | unsigned short *a, *b; | ||
2495 | { | ||
2496 | unsigned short ai[NI], bi[NI]; | ||
2497 | register unsigned short *p, *q; | ||
2498 | register int i; | ||
2499 | int msign; | ||
2500 | |||
2501 | #ifdef NANS | ||
2502 | if (eisnan (a) || eisnan (b)) | ||
2503 | return( -2 ); | ||
2504 | #endif | ||
2505 | emovi( a, ai ); | ||
2506 | p = ai; | ||
2507 | emovi( b, bi ); | ||
2508 | q = bi; | ||
2509 | |||
2510 | if( *p != *q ) | ||
2511 | { /* the signs are different */ | ||
2512 | /* -0 equals + 0 */ | ||
2513 | for( i=1; i<NI-1; i++ ) | ||
2514 | { | ||
2515 | if( ai[i] != 0 ) | ||
2516 | goto nzro; | ||
2517 | if( bi[i] != 0 ) | ||
2518 | goto nzro; | ||
2519 | } | ||
2520 | return(0); | ||
2521 | nzro: | ||
2522 | if( *p == 0 ) | ||
2523 | return( 1 ); | ||
2524 | else | ||
2525 | return( -1 ); | ||
2526 | } | ||
2527 | /* both are the same sign */ | ||
2528 | if( *p == 0 ) | ||
2529 | msign = 1; | ||
2530 | else | ||
2531 | msign = -1; | ||
2532 | i = NI-1; | ||
2533 | do | ||
2534 | { | ||
2535 | if( *p++ != *q++ ) | ||
2536 | { | ||
2537 | goto diff; | ||
2538 | } | ||
2539 | } | ||
2540 | while( --i > 0 ); | ||
2541 | |||
2542 | return(0); /* equality */ | ||
2543 | |||
2544 | |||
2545 | |||
2546 | diff: | ||
2547 | |||
2548 | if( *(--p) > *(--q) ) | ||
2549 | return( msign ); /* p is bigger */ | ||
2550 | else | ||
2551 | return( -msign ); /* p is littler */ | ||
2552 | } | ||
2553 | |||
2554 | |||
2555 | |||
2556 | |||
2557 | /* Find nearest integer to x = floor( x + 0.5 ) | ||
2558 | * | ||
2559 | * unsigned short x[NE], y[NE] | ||
2560 | * eround( x, y ); | ||
2561 | */ | ||
2562 | void eround( x, y ) | ||
2563 | unsigned short *x, *y; | ||
2564 | { | ||
2565 | |||
2566 | eadd( ehalf, x, y ); | ||
2567 | efloor( y, y ); | ||
2568 | } | ||
2569 | |||
2570 | |||
2571 | |||
2572 | |||
2573 | /* | ||
2574 | ; convert long (32-bit) integer to e type | ||
2575 | ; | ||
2576 | ; long l; | ||
2577 | ; unsigned short x[NE]; | ||
2578 | ; ltoe( &l, x ); | ||
2579 | ; note &l is the memory address of l | ||
2580 | */ | ||
2581 | void ltoe( lp, y ) | ||
2582 | long *lp; /* lp is the memory address of a long integer */ | ||
2583 | unsigned short *y; /* y is the address of a short */ | ||
2584 | { | ||
2585 | unsigned short yi[NI]; | ||
2586 | unsigned long ll; | ||
2587 | int k; | ||
2588 | |||
2589 | ecleaz( yi ); | ||
2590 | if( *lp < 0 ) | ||
2591 | { | ||
2592 | ll = (unsigned long )( -(*lp) ); /* make it positive */ | ||
2593 | yi[0] = 0xffff; /* put correct sign in the e type number */ | ||
2594 | } | ||
2595 | else | ||
2596 | { | ||
2597 | ll = (unsigned long )( *lp ); | ||
2598 | } | ||
2599 | /* move the long integer to yi significand area */ | ||
2600 | if( sizeof(long) == 8 ) | ||
2601 | { | ||
2602 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
2603 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
2604 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
2605 | yi[M + 3] = (unsigned short) ll; | ||
2606 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
2607 | } | ||
2608 | else | ||
2609 | { | ||
2610 | yi[M] = (unsigned short )(ll >> 16); | ||
2611 | yi[M+1] = (unsigned short )ll; | ||
2612 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
2613 | } | ||
2614 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
2615 | ecleaz( yi ); /* it was zero */ | ||
2616 | else | ||
2617 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
2618 | emovo( yi, y ); /* output the answer */ | ||
2619 | } | ||
2620 | |||
2621 | /* | ||
2622 | ; convert unsigned long (32-bit) integer to e type | ||
2623 | ; | ||
2624 | ; unsigned long l; | ||
2625 | ; unsigned short x[NE]; | ||
2626 | ; ltox( &l, x ); | ||
2627 | ; note &l is the memory address of l | ||
2628 | */ | ||
2629 | void ultoe( lp, y ) | ||
2630 | unsigned long *lp; /* lp is the memory address of a long integer */ | ||
2631 | unsigned short *y; /* y is the address of a short */ | ||
2632 | { | ||
2633 | unsigned short yi[NI]; | ||
2634 | unsigned long ll; | ||
2635 | int k; | ||
2636 | |||
2637 | ecleaz( yi ); | ||
2638 | ll = *lp; | ||
2639 | |||
2640 | /* move the long integer to ayi significand area */ | ||
2641 | if( sizeof(long) == 8 ) | ||
2642 | { | ||
2643 | yi[M] = (unsigned short) (ll >> (LONGBITS - 16)); | ||
2644 | yi[M + 1] = (unsigned short) (ll >> (LONGBITS - 32)); | ||
2645 | yi[M + 2] = (unsigned short) (ll >> 16); | ||
2646 | yi[M + 3] = (unsigned short) ll; | ||
2647 | yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */ | ||
2648 | } | ||
2649 | else | ||
2650 | { | ||
2651 | yi[M] = (unsigned short )(ll >> 16); | ||
2652 | yi[M+1] = (unsigned short )ll; | ||
2653 | yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */ | ||
2654 | } | ||
2655 | if( (k = enormlz( yi )) > NBITS ) /* normalize the significand */ | ||
2656 | ecleaz( yi ); /* it was zero */ | ||
2657 | else | ||
2658 | yi[E] -= (unsigned short )k; /* subtract shift count from exponent */ | ||
2659 | emovo( yi, y ); /* output the answer */ | ||
2660 | } | ||
2661 | |||
2662 | |||
2663 | /* | ||
2664 | ; Find long integer and fractional parts | ||
2665 | |||
2666 | ; long i; | ||
2667 | ; unsigned short x[NE], frac[NE]; | ||
2668 | ; xifrac( x, &i, frac ); | ||
2669 | |||
2670 | The integer output has the sign of the input. The fraction is | ||
2671 | the positive fractional part of abs(x). | ||
2672 | */ | ||
2673 | void eifrac( x, i, frac ) | ||
2674 | unsigned short *x; | ||
2675 | long *i; | ||
2676 | unsigned short *frac; | ||
2677 | { | ||
2678 | unsigned short xi[NI]; | ||
2679 | int j, k; | ||
2680 | unsigned long ll; | ||
2681 | |||
2682 | emovi( x, xi ); | ||
2683 | k = (int )xi[E] - (EXONE - 1); | ||
2684 | if( k <= 0 ) | ||
2685 | { | ||
2686 | /* if exponent <= 0, integer = 0 and real output is fraction */ | ||
2687 | *i = 0L; | ||
2688 | emovo( xi, frac ); | ||
2689 | return; | ||
2690 | } | ||
2691 | if( k > (8 * sizeof(long) - 1) ) | ||
2692 | { | ||
2693 | /* | ||
2694 | ; long integer overflow: output large integer | ||
2695 | ; and correct fraction | ||
2696 | */ | ||
2697 | j = 8 * sizeof(long) - 1; | ||
2698 | if( xi[0] ) | ||
2699 | *i = (long) ((unsigned long) 1) << j; | ||
2700 | else | ||
2701 | *i = (long) (((unsigned long) (~(0L))) >> 1); | ||
2702 | (void )eshift( xi, k ); | ||
2703 | } | ||
2704 | if( k > 16 ) | ||
2705 | { | ||
2706 | /* | ||
2707 | Shift more than 16 bits: shift up k-16 mod 16 | ||
2708 | then shift by 16's. | ||
2709 | */ | ||
2710 | j = k - ((k >> 4) << 4); | ||
2711 | eshift (xi, j); | ||
2712 | ll = xi[M]; | ||
2713 | k -= j; | ||
2714 | do | ||
2715 | { | ||
2716 | eshup6 (xi); | ||
2717 | ll = (ll << 16) | xi[M]; | ||
2718 | } | ||
2719 | while ((k -= 16) > 0); | ||
2720 | *i = ll; | ||
2721 | if (xi[0]) | ||
2722 | *i = -(*i); | ||
2723 | } | ||
2724 | else | ||
2725 | { | ||
2726 | /* shift not more than 16 bits */ | ||
2727 | eshift( xi, k ); | ||
2728 | *i = (long )xi[M] & 0xffff; | ||
2729 | if( xi[0] ) | ||
2730 | *i = -(*i); | ||
2731 | } | ||
2732 | xi[0] = 0; | ||
2733 | xi[E] = EXONE - 1; | ||
2734 | xi[M] = 0; | ||
2735 | if( (k = enormlz( xi )) > NBITS ) | ||
2736 | ecleaz( xi ); | ||
2737 | else | ||
2738 | xi[E] -= (unsigned short )k; | ||
2739 | |||
2740 | emovo( xi, frac ); | ||
2741 | } | ||
2742 | |||
2743 | |||
2744 | /* | ||
2745 | ; Find unsigned long integer and fractional parts | ||
2746 | |||
2747 | ; unsigned long i; | ||
2748 | ; unsigned short x[NE], frac[NE]; | ||
2749 | ; xifrac( x, &i, frac ); | ||
2750 | |||
2751 | A negative e type input yields integer output = 0 | ||
2752 | but correct fraction. | ||
2753 | */ | ||
2754 | void euifrac( x, i, frac ) | ||
2755 | unsigned short *x; | ||
2756 | unsigned long *i; | ||
2757 | unsigned short *frac; | ||
2758 | { | ||
2759 | unsigned short xi[NI]; | ||
2760 | int j, k; | ||
2761 | unsigned long ll; | ||
2762 | |||
2763 | emovi( x, xi ); | ||
2764 | k = (int )xi[E] - (EXONE - 1); | ||
2765 | if( k <= 0 ) | ||
2766 | { | ||
2767 | /* if exponent <= 0, integer = 0 and argument is fraction */ | ||
2768 | *i = 0L; | ||
2769 | emovo( xi, frac ); | ||
2770 | return; | ||
2771 | } | ||
2772 | if( k > (8 * sizeof(long)) ) | ||
2773 | { | ||
2774 | /* | ||
2775 | ; long integer overflow: output large integer | ||
2776 | ; and correct fraction | ||
2777 | */ | ||
2778 | *i = ~(0L); | ||
2779 | (void )eshift( xi, k ); | ||
2780 | } | ||
2781 | else if( k > 16 ) | ||
2782 | { | ||
2783 | /* | ||
2784 | Shift more than 16 bits: shift up k-16 mod 16 | ||
2785 | then shift up by 16's. | ||
2786 | */ | ||
2787 | j = k - ((k >> 4) << 4); | ||
2788 | eshift (xi, j); | ||
2789 | ll = xi[M]; | ||
2790 | k -= j; | ||
2791 | do | ||
2792 | { | ||
2793 | eshup6 (xi); | ||
2794 | ll = (ll << 16) | xi[M]; | ||
2795 | } | ||
2796 | while ((k -= 16) > 0); | ||
2797 | *i = ll; | ||
2798 | } | ||
2799 | else | ||
2800 | { | ||
2801 | /* shift not more than 16 bits */ | ||
2802 | eshift( xi, k ); | ||
2803 | *i = (long )xi[M] & 0xffff; | ||
2804 | } | ||
2805 | |||
2806 | if( xi[0] ) /* A negative value yields unsigned integer 0. */ | ||
2807 | *i = 0L; | ||
2808 | |||
2809 | xi[0] = 0; | ||
2810 | xi[E] = EXONE - 1; | ||
2811 | xi[M] = 0; | ||
2812 | if( (k = enormlz( xi )) > NBITS ) | ||
2813 | ecleaz( xi ); | ||
2814 | else | ||
2815 | xi[E] -= (unsigned short )k; | ||
2816 | |||
2817 | emovo( xi, frac ); | ||
2818 | } | ||
2819 | |||
2820 | |||
2821 | |||
2822 | /* | ||
2823 | ; Shift significand | ||
2824 | ; | ||
2825 | ; Shifts significand area up or down by the number of bits | ||
2826 | ; given by the variable sc. | ||
2827 | */ | ||
2828 | int eshift( x, sc ) | ||
2829 | unsigned short *x; | ||
2830 | int sc; | ||
2831 | { | ||
2832 | unsigned short lost; | ||
2833 | unsigned short *p; | ||
2834 | |||
2835 | if( sc == 0 ) | ||
2836 | return( 0 ); | ||
2837 | |||
2838 | lost = 0; | ||
2839 | p = x + NI-1; | ||
2840 | |||
2841 | if( sc < 0 ) | ||
2842 | { | ||
2843 | sc = -sc; | ||
2844 | while( sc >= 16 ) | ||
2845 | { | ||
2846 | lost |= *p; /* remember lost bits */ | ||
2847 | eshdn6(x); | ||
2848 | sc -= 16; | ||
2849 | } | ||
2850 | |||
2851 | while( sc >= 8 ) | ||
2852 | { | ||
2853 | lost |= *p & 0xff; | ||
2854 | eshdn8(x); | ||
2855 | sc -= 8; | ||
2856 | } | ||
2857 | |||
2858 | while( sc > 0 ) | ||
2859 | { | ||
2860 | lost |= *p & 1; | ||
2861 | eshdn1(x); | ||
2862 | sc -= 1; | ||
2863 | } | ||
2864 | } | ||
2865 | else | ||
2866 | { | ||
2867 | while( sc >= 16 ) | ||
2868 | { | ||
2869 | eshup6(x); | ||
2870 | sc -= 16; | ||
2871 | } | ||
2872 | |||
2873 | while( sc >= 8 ) | ||
2874 | { | ||
2875 | eshup8(x); | ||
2876 | sc -= 8; | ||
2877 | } | ||
2878 | |||
2879 | while( sc > 0 ) | ||
2880 | { | ||
2881 | eshup1(x); | ||
2882 | sc -= 1; | ||
2883 | } | ||
2884 | } | ||
2885 | if( lost ) | ||
2886 | lost = 1; | ||
2887 | return( (int )lost ); | ||
2888 | } | ||
2889 | |||
2890 | |||
2891 | |||
2892 | /* | ||
2893 | ; normalize | ||
2894 | ; | ||
2895 | ; Shift normalizes the significand area pointed to by argument | ||
2896 | ; shift count (up = positive) is returned. | ||
2897 | */ | ||
2898 | int enormlz(x) | ||
2899 | unsigned short x[]; | ||
2900 | { | ||
2901 | register unsigned short *p; | ||
2902 | int sc; | ||
2903 | |||
2904 | sc = 0; | ||
2905 | p = &x[M]; | ||
2906 | if( *p != 0 ) | ||
2907 | goto normdn; | ||
2908 | ++p; | ||
2909 | if( *p & 0x8000 ) | ||
2910 | return( 0 ); /* already normalized */ | ||
2911 | while( *p == 0 ) | ||
2912 | { | ||
2913 | eshup6(x); | ||
2914 | sc += 16; | ||
2915 | /* With guard word, there are NBITS+16 bits available. | ||
2916 | * return true if all are zero. | ||
2917 | */ | ||
2918 | if( sc > NBITS ) | ||
2919 | return( sc ); | ||
2920 | } | ||
2921 | /* see if high byte is zero */ | ||
2922 | while( (*p & 0xff00) == 0 ) | ||
2923 | { | ||
2924 | eshup8(x); | ||
2925 | sc += 8; | ||
2926 | } | ||
2927 | /* now shift 1 bit at a time */ | ||
2928 | while( (*p & 0x8000) == 0) | ||
2929 | { | ||
2930 | eshup1(x); | ||
2931 | sc += 1; | ||
2932 | if( sc > (NBITS+16) ) | ||
2933 | { | ||
2934 | mtherr( "enormlz", UNDERFLOW ); | ||
2935 | return( sc ); | ||
2936 | } | ||
2937 | } | ||
2938 | return( sc ); | ||
2939 | |||
2940 | /* Normalize by shifting down out of the high guard word | ||
2941 | of the significand */ | ||
2942 | normdn: | ||
2943 | |||
2944 | if( *p & 0xff00 ) | ||
2945 | { | ||
2946 | eshdn8(x); | ||
2947 | sc -= 8; | ||
2948 | } | ||
2949 | while( *p != 0 ) | ||
2950 | { | ||
2951 | eshdn1(x); | ||
2952 | sc -= 1; | ||
2953 | |||
2954 | if( sc < -NBITS ) | ||
2955 | { | ||
2956 | mtherr( "enormlz", OVERFLOW ); | ||
2957 | return( sc ); | ||
2958 | } | ||
2959 | } | ||
2960 | return( sc ); | ||
2961 | } | ||
2962 | |||
2963 | |||
2964 | |||
2965 | |||
2966 | /* Convert e type number to decimal format ASCII string. | ||
2967 | * The constants are for 64 bit precision. | ||
2968 | */ | ||
2969 | |||
2970 | #define NTEN 12 | ||
2971 | #define MAXP 4096 | ||
2972 | |||
2973 | #if NE == 10 | ||
2974 | static unsigned short etens[NTEN + 1][NE] = | ||
2975 | { | ||
2976 | {0x6576, 0x4a92, 0x804a, 0x153f, | ||
2977 | 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */ | ||
2978 | {0x6a32, 0xce52, 0x329a, 0x28ce, | ||
2979 | 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */ | ||
2980 | {0x526c, 0x50ce, 0xf18b, 0x3d28, | ||
2981 | 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,}, | ||
2982 | {0x9c66, 0x58f8, 0xbc50, 0x5c54, | ||
2983 | 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,}, | ||
2984 | {0x851e, 0xeab7, 0x98fe, 0x901b, | ||
2985 | 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,}, | ||
2986 | {0x0235, 0x0137, 0x36b1, 0x336c, | ||
2987 | 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,}, | ||
2988 | {0x50f8, 0x25fb, 0xc76b, 0x6b71, | ||
2989 | 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,}, | ||
2990 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2991 | 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,}, | ||
2992 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2993 | 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,}, | ||
2994 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2995 | 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,}, | ||
2996 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2997 | 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,}, | ||
2998 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
2999 | 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,}, | ||
3000 | {0x0000, 0x0000, 0x0000, 0x0000, | ||
3001 | 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */ | ||
3002 | }; | ||
3003 | |||
3004 | static unsigned short emtens[NTEN + 1][NE] = | ||
3005 | { | ||
3006 | {0x2030, 0xcffc, 0xa1c3, 0x8123, | ||
3007 | 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */ | ||
3008 | {0x8264, 0xd2cb, 0xf2ea, 0x12d4, | ||
3009 | 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */ | ||
3010 | {0xf53f, 0xf698, 0x6bd3, 0x0158, | ||
3011 | 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,}, | ||
3012 | {0xe731, 0x04d4, 0xe3f2, 0xd332, | ||
3013 | 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,}, | ||
3014 | {0xa23e, 0x5308, 0xfefb, 0x1155, | ||
3015 | 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,}, | ||
3016 | {0xe26d, 0xdbde, 0xd05d, 0xb3f6, | ||
3017 | 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,}, | ||
3018 | {0x2a20, 0x6224, 0x47b3, 0x98d7, | ||
3019 | 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,}, | ||
3020 | {0x0b5b, 0x4af2, 0xa581, 0x18ed, | ||
3021 | 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,}, | ||
3022 | {0xbf71, 0xa9b3, 0x7989, 0xbe68, | ||
3023 | 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,}, | ||
3024 | {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b, | ||
3025 | 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,}, | ||
3026 | {0xc155, 0xa4a8, 0x404e, 0x6113, | ||
3027 | 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,}, | ||
3028 | {0xd70a, 0x70a3, 0x0a3d, 0xa3d7, | ||
3029 | 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,}, | ||
3030 | {0xcccd, 0xcccc, 0xcccc, 0xcccc, | ||
3031 | 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */ | ||
3032 | }; | ||
3033 | #else | ||
3034 | static unsigned short etens[NTEN+1][NE] = { | ||
3035 | {0xc94c,0x979a,0x8a20,0x5202,0xc460,0x7525,},/* 10**4096 */ | ||
3036 | {0xa74d,0x5de4,0xc53d,0x3b5d,0x9e8b,0x5a92,},/* 10**2048 */ | ||
3037 | {0x650d,0x0c17,0x8175,0x7586,0xc976,0x4d48,}, | ||
3038 | {0xcc65,0x91c6,0xa60e,0xa0ae,0xe319,0x46a3,}, | ||
3039 | {0xddbc,0xde8d,0x9df9,0xebfb,0xaa7e,0x4351,}, | ||
3040 | {0xc66f,0x8cdf,0x80e9,0x47c9,0x93ba,0x41a8,}, | ||
3041 | {0x3cbf,0xa6d5,0xffcf,0x1f49,0xc278,0x40d3,}, | ||
3042 | {0xf020,0xb59d,0x2b70,0xada8,0x9dc5,0x4069,}, | ||
3043 | {0x0000,0x0000,0x0400,0xc9bf,0x8e1b,0x4034,}, | ||
3044 | {0x0000,0x0000,0x0000,0x2000,0xbebc,0x4019,}, | ||
3045 | {0x0000,0x0000,0x0000,0x0000,0x9c40,0x400c,}, | ||
3046 | {0x0000,0x0000,0x0000,0x0000,0xc800,0x4005,}, | ||
3047 | {0x0000,0x0000,0x0000,0x0000,0xa000,0x4002,}, /* 10**1 */ | ||
3048 | }; | ||
3049 | |||
3050 | static unsigned short emtens[NTEN+1][NE] = { | ||
3051 | {0x2de4,0x9fde,0xd2ce,0x04c8,0xa6dd,0x0ad8,}, /* 10**-4096 */ | ||
3052 | {0x4925,0x2de4,0x3436,0x534f,0xceae,0x256b,}, /* 10**-2048 */ | ||
3053 | {0x87a6,0xc0bd,0xda57,0x82a5,0xa2a6,0x32b5,}, | ||
3054 | {0x7133,0xd21c,0xdb23,0xee32,0x9049,0x395a,}, | ||
3055 | {0xfa91,0x1939,0x637a,0x4325,0xc031,0x3cac,}, | ||
3056 | {0xac7d,0xe4a0,0x64bc,0x467c,0xddd0,0x3e55,}, | ||
3057 | {0x3f24,0xe9a5,0xa539,0xea27,0xa87f,0x3f2a,}, | ||
3058 | {0x67de,0x94ba,0x4539,0x1ead,0xcfb1,0x3f94,}, | ||
3059 | {0x4c2f,0xe15b,0xc44d,0x94be,0xe695,0x3fc9,}, | ||
3060 | {0xfdc2,0xcefc,0x8461,0x7711,0xabcc,0x3fe4,}, | ||
3061 | {0xd3c3,0x652b,0xe219,0x1758,0xd1b7,0x3ff1,}, | ||
3062 | {0x3d71,0xd70a,0x70a3,0x0a3d,0xa3d7,0x3ff8,}, | ||
3063 | {0xcccd,0xcccc,0xcccc,0xcccc,0xcccc,0x3ffb,}, /* 10**-1 */ | ||
3064 | }; | ||
3065 | #endif | ||
3066 | |||
3067 | void e24toasc( x, string, ndigs ) | ||
3068 | unsigned short x[]; | ||
3069 | char *string; | ||
3070 | int ndigs; | ||
3071 | { | ||
3072 | unsigned short w[NI]; | ||
3073 | |||
3074 | e24toe( x, w ); | ||
3075 | etoasc( w, string, ndigs ); | ||
3076 | } | ||
3077 | |||
3078 | |||
3079 | void e53toasc( x, string, ndigs ) | ||
3080 | unsigned short x[]; | ||
3081 | char *string; | ||
3082 | int ndigs; | ||
3083 | { | ||
3084 | unsigned short w[NI]; | ||
3085 | |||
3086 | e53toe( x, w ); | ||
3087 | etoasc( w, string, ndigs ); | ||
3088 | } | ||
3089 | |||
3090 | |||
3091 | void e64toasc( x, string, ndigs ) | ||
3092 | unsigned short x[]; | ||
3093 | char *string; | ||
3094 | int ndigs; | ||
3095 | { | ||
3096 | unsigned short w[NI]; | ||
3097 | |||
3098 | e64toe( x, w ); | ||
3099 | etoasc( w, string, ndigs ); | ||
3100 | } | ||
3101 | |||
3102 | void e113toasc (x, string, ndigs) | ||
3103 | unsigned short x[]; | ||
3104 | char *string; | ||
3105 | int ndigs; | ||
3106 | { | ||
3107 | unsigned short w[NI]; | ||
3108 | |||
3109 | e113toe (x, w); | ||
3110 | etoasc (w, string, ndigs); | ||
3111 | } | ||
3112 | |||
3113 | |||
3114 | void etoasc( x, string, ndigs ) | ||
3115 | unsigned short x[]; | ||
3116 | char *string; | ||
3117 | int ndigs; | ||
3118 | { | ||
3119 | long digit; | ||
3120 | unsigned short y[NI], t[NI], u[NI], w[NI]; | ||
3121 | unsigned short *p, *r, *ten; | ||
3122 | unsigned short sign; | ||
3123 | int i, j, k, expon, rndsav; | ||
3124 | char *s, *ss; | ||
3125 | unsigned short m; | ||
3126 | |||
3127 | rndsav = rndprc; | ||
3128 | #ifdef NANS | ||
3129 | if( eisnan(x) ) | ||
3130 | { | ||
3131 | sprintf( string, " NaN " ); | ||
3132 | goto bxit; | ||
3133 | } | ||
3134 | #endif | ||
3135 | rndprc = NBITS; /* set to full precision */ | ||
3136 | emov( x, y ); /* retain external format */ | ||
3137 | if( y[NE-1] & 0x8000 ) | ||
3138 | { | ||
3139 | sign = 0xffff; | ||
3140 | y[NE-1] &= 0x7fff; | ||
3141 | } | ||
3142 | else | ||
3143 | { | ||
3144 | sign = 0; | ||
3145 | } | ||
3146 | expon = 0; | ||
3147 | ten = &etens[NTEN][0]; | ||
3148 | emov( eone, t ); | ||
3149 | /* Test for zero exponent */ | ||
3150 | if( y[NE-1] == 0 ) | ||
3151 | { | ||
3152 | for( k=0; k<NE-1; k++ ) | ||
3153 | { | ||
3154 | if( y[k] != 0 ) | ||
3155 | goto tnzro; /* denormalized number */ | ||
3156 | } | ||
3157 | goto isone; /* legal all zeros */ | ||
3158 | } | ||
3159 | tnzro: | ||
3160 | |||
3161 | /* Test for infinity. | ||
3162 | */ | ||
3163 | if( y[NE-1] == 0x7fff ) | ||
3164 | { | ||
3165 | if( sign ) | ||
3166 | sprintf( string, " -Infinity " ); | ||
3167 | else | ||
3168 | sprintf( string, " Infinity " ); | ||
3169 | goto bxit; | ||
3170 | } | ||
3171 | |||
3172 | /* Test for exponent nonzero but significand denormalized. | ||
3173 | * This is an error condition. | ||
3174 | */ | ||
3175 | if( (y[NE-1] != 0) && ((y[NE-2] & 0x8000) == 0) ) | ||
3176 | { | ||
3177 | mtherr( "etoasc", DOMAIN ); | ||
3178 | sprintf( string, "NaN" ); | ||
3179 | goto bxit; | ||
3180 | } | ||
3181 | |||
3182 | /* Compare to 1.0 */ | ||
3183 | i = ecmp( eone, y ); | ||
3184 | if( i == 0 ) | ||
3185 | goto isone; | ||
3186 | |||
3187 | if( i < 0 ) | ||
3188 | { /* Number is greater than 1 */ | ||
3189 | /* Convert significand to an integer and strip trailing decimal zeros. */ | ||
3190 | emov( y, u ); | ||
3191 | u[NE-1] = EXONE + NBITS - 1; | ||
3192 | |||
3193 | p = &etens[NTEN-4][0]; | ||
3194 | m = 16; | ||
3195 | do | ||
3196 | { | ||
3197 | ediv( p, u, t ); | ||
3198 | efloor( t, w ); | ||
3199 | for( j=0; j<NE-1; j++ ) | ||
3200 | { | ||
3201 | if( t[j] != w[j] ) | ||
3202 | goto noint; | ||
3203 | } | ||
3204 | emov( t, u ); | ||
3205 | expon += (int )m; | ||
3206 | noint: | ||
3207 | p += NE; | ||
3208 | m >>= 1; | ||
3209 | } | ||
3210 | while( m != 0 ); | ||
3211 | |||
3212 | /* Rescale from integer significand */ | ||
3213 | u[NE-1] += y[NE-1] - (unsigned int )(EXONE + NBITS - 1); | ||
3214 | emov( u, y ); | ||
3215 | /* Find power of 10 */ | ||
3216 | emov( eone, t ); | ||
3217 | m = MAXP; | ||
3218 | p = &etens[0][0]; | ||
3219 | while( ecmp( ten, u ) <= 0 ) | ||
3220 | { | ||
3221 | if( ecmp( p, u ) <= 0 ) | ||
3222 | { | ||
3223 | ediv( p, u, u ); | ||
3224 | emul( p, t, t ); | ||
3225 | expon += (int )m; | ||
3226 | } | ||
3227 | m >>= 1; | ||
3228 | if( m == 0 ) | ||
3229 | break; | ||
3230 | p += NE; | ||
3231 | } | ||
3232 | } | ||
3233 | else | ||
3234 | { /* Number is less than 1.0 */ | ||
3235 | /* Pad significand with trailing decimal zeros. */ | ||
3236 | if( y[NE-1] == 0 ) | ||
3237 | { | ||
3238 | while( (y[NE-2] & 0x8000) == 0 ) | ||
3239 | { | ||
3240 | emul( ten, y, y ); | ||
3241 | expon -= 1; | ||
3242 | } | ||
3243 | } | ||
3244 | else | ||
3245 | { | ||
3246 | emovi( y, w ); | ||
3247 | for( i=0; i<NDEC+1; i++ ) | ||
3248 | { | ||
3249 | if( (w[NI-1] & 0x7) != 0 ) | ||
3250 | break; | ||
3251 | /* multiply by 10 */ | ||
3252 | emovz( w, u ); | ||
3253 | eshdn1( u ); | ||
3254 | eshdn1( u ); | ||
3255 | eaddm( w, u ); | ||
3256 | u[1] += 3; | ||
3257 | while( u[2] != 0 ) | ||
3258 | { | ||
3259 | eshdn1(u); | ||
3260 | u[1] += 1; | ||
3261 | } | ||
3262 | if( u[NI-1] != 0 ) | ||
3263 | break; | ||
3264 | if( eone[NE-1] <= u[1] ) | ||
3265 | break; | ||
3266 | emovz( u, w ); | ||
3267 | expon -= 1; | ||
3268 | } | ||
3269 | emovo( w, y ); | ||
3270 | } | ||
3271 | k = -MAXP; | ||
3272 | p = &emtens[0][0]; | ||
3273 | r = &etens[0][0]; | ||
3274 | emov( y, w ); | ||
3275 | emov( eone, t ); | ||
3276 | while( ecmp( eone, w ) > 0 ) | ||
3277 | { | ||
3278 | if( ecmp( p, w ) >= 0 ) | ||
3279 | { | ||
3280 | emul( r, w, w ); | ||
3281 | emul( r, t, t ); | ||
3282 | expon += k; | ||
3283 | } | ||
3284 | k /= 2; | ||
3285 | if( k == 0 ) | ||
3286 | break; | ||
3287 | p += NE; | ||
3288 | r += NE; | ||
3289 | } | ||
3290 | ediv( t, eone, t ); | ||
3291 | } | ||
3292 | isone: | ||
3293 | /* Find the first (leading) digit. */ | ||
3294 | emovi( t, w ); | ||
3295 | emovz( w, t ); | ||
3296 | emovi( y, w ); | ||
3297 | emovz( w, y ); | ||
3298 | eiremain( t, y ); | ||
3299 | digit = equot[NI-1]; | ||
3300 | while( (digit == 0) && (ecmp(y,ezero) != 0) ) | ||
3301 | { | ||
3302 | eshup1( y ); | ||
3303 | emovz( y, u ); | ||
3304 | eshup1( u ); | ||
3305 | eshup1( u ); | ||
3306 | eaddm( u, y ); | ||
3307 | eiremain( t, y ); | ||
3308 | digit = equot[NI-1]; | ||
3309 | expon -= 1; | ||
3310 | } | ||
3311 | s = string; | ||
3312 | if( sign ) | ||
3313 | *s++ = '-'; | ||
3314 | else | ||
3315 | *s++ = ' '; | ||
3316 | /* Examine number of digits requested by caller. */ | ||
3317 | if( ndigs < 0 ) | ||
3318 | ndigs = 0; | ||
3319 | if( ndigs > NDEC ) | ||
3320 | ndigs = NDEC; | ||
3321 | if( digit == 10 ) | ||
3322 | { | ||
3323 | *s++ = '1'; | ||
3324 | *s++ = '.'; | ||
3325 | if( ndigs > 0 ) | ||
3326 | { | ||
3327 | *s++ = '0'; | ||
3328 | ndigs -= 1; | ||
3329 | } | ||
3330 | expon += 1; | ||
3331 | } | ||
3332 | else | ||
3333 | { | ||
3334 | *s++ = (char )digit + '0'; | ||
3335 | *s++ = '.'; | ||
3336 | } | ||
3337 | /* Generate digits after the decimal point. */ | ||
3338 | for( k=0; k<=ndigs; k++ ) | ||
3339 | { | ||
3340 | /* multiply current number by 10, without normalizing */ | ||
3341 | eshup1( y ); | ||
3342 | emovz( y, u ); | ||
3343 | eshup1( u ); | ||
3344 | eshup1( u ); | ||
3345 | eaddm( u, y ); | ||
3346 | eiremain( t, y ); | ||
3347 | *s++ = (char )equot[NI-1] + '0'; | ||
3348 | } | ||
3349 | digit = equot[NI-1]; | ||
3350 | --s; | ||
3351 | ss = s; | ||
3352 | /* round off the ASCII string */ | ||
3353 | if( digit > 4 ) | ||
3354 | { | ||
3355 | /* Test for critical rounding case in ASCII output. */ | ||
3356 | if( digit == 5 ) | ||
3357 | { | ||
3358 | emovo( y, t ); | ||
3359 | if( ecmp(t,ezero) != 0 ) | ||
3360 | goto roun; /* round to nearest */ | ||
3361 | if( (*(s-1) & 1) == 0 ) | ||
3362 | goto doexp; /* round to even */ | ||
3363 | } | ||
3364 | /* Round up and propagate carry-outs */ | ||
3365 | roun: | ||
3366 | --s; | ||
3367 | k = *s & 0x7f; | ||
3368 | /* Carry out to most significant digit? */ | ||
3369 | if( k == '.' ) | ||
3370 | { | ||
3371 | --s; | ||
3372 | k = *s; | ||
3373 | k += 1; | ||
3374 | *s = (char )k; | ||
3375 | /* Most significant digit carries to 10? */ | ||
3376 | if( k > '9' ) | ||
3377 | { | ||
3378 | expon += 1; | ||
3379 | *s = '1'; | ||
3380 | } | ||
3381 | goto doexp; | ||
3382 | } | ||
3383 | /* Round up and carry out from less significant digits */ | ||
3384 | k += 1; | ||
3385 | *s = (char )k; | ||
3386 | if( k > '9' ) | ||
3387 | { | ||
3388 | *s = '0'; | ||
3389 | goto roun; | ||
3390 | } | ||
3391 | } | ||
3392 | doexp: | ||
3393 | /* | ||
3394 | if( expon >= 0 ) | ||
3395 | sprintf( ss, "e+%d", expon ); | ||
3396 | else | ||
3397 | sprintf( ss, "e%d", expon ); | ||
3398 | */ | ||
3399 | sprintf( ss, "E%d", expon ); | ||
3400 | bxit: | ||
3401 | rndprc = rndsav; | ||
3402 | } | ||
3403 | |||
3404 | |||
3405 | |||
3406 | |||
3407 | /* | ||
3408 | ; ASCTOQ | ||
3409 | ; ASCTOQ.MAC LATEST REV: 11 JAN 84 | ||
3410 | ; SLM, 3 JAN 78 | ||
3411 | ; | ||
3412 | ; Convert ASCII string to quadruple precision floating point | ||
3413 | ; | ||
3414 | ; Numeric input is free field decimal number | ||
3415 | ; with max of 15 digits with or without | ||
3416 | ; decimal point entered as ASCII from teletype. | ||
3417 | ; Entering E after the number followed by a second | ||
3418 | ; number causes the second number to be interpreted | ||
3419 | ; as a power of 10 to be multiplied by the first number | ||
3420 | ; (i.e., "scientific" notation). | ||
3421 | ; | ||
3422 | ; Usage: | ||
3423 | ; asctoq( string, q ); | ||
3424 | */ | ||
3425 | |||
3426 | /* ASCII to single */ | ||
3427 | void asctoe24( s, y ) | ||
3428 | char *s; | ||
3429 | unsigned short *y; | ||
3430 | { | ||
3431 | asctoeg( s, y, 24 ); | ||
3432 | } | ||
3433 | |||
3434 | |||
3435 | /* ASCII to double */ | ||
3436 | void asctoe53( s, y ) | ||
3437 | char *s; | ||
3438 | unsigned short *y; | ||
3439 | { | ||
3440 | #ifdef DEC | ||
3441 | asctoeg( s, y, 56 ); | ||
3442 | #else | ||
3443 | asctoeg( s, y, 53 ); | ||
3444 | #endif | ||
3445 | } | ||
3446 | |||
3447 | |||
3448 | /* ASCII to long double */ | ||
3449 | void asctoe64( s, y ) | ||
3450 | char *s; | ||
3451 | unsigned short *y; | ||
3452 | { | ||
3453 | asctoeg( s, y, 64 ); | ||
3454 | } | ||
3455 | |||
3456 | /* ASCII to 128-bit long double */ | ||
3457 | void asctoe113 (s, y) | ||
3458 | char *s; | ||
3459 | unsigned short *y; | ||
3460 | { | ||
3461 | asctoeg( s, y, 113 ); | ||
3462 | } | ||
3463 | |||
3464 | /* ASCII to super double */ | ||
3465 | void asctoe( s, y ) | ||
3466 | char *s; | ||
3467 | unsigned short *y; | ||
3468 | { | ||
3469 | asctoeg( s, y, NBITS ); | ||
3470 | } | ||
3471 | |||
3472 | /* Space to make a copy of the input string: */ | ||
3473 | static char lstr[82] = {0}; | ||
3474 | |||
3475 | void asctoeg( ss, y, oprec ) | ||
3476 | char *ss; | ||
3477 | unsigned short *y; | ||
3478 | int oprec; | ||
3479 | { | ||
3480 | unsigned short yy[NI], xt[NI], tt[NI]; | ||
3481 | int esign, decflg, sgnflg, nexp, exp, prec, lost; | ||
3482 | int k, trail, c, rndsav; | ||
3483 | long lexp; | ||
3484 | unsigned short nsign, *p; | ||
3485 | char *sp, *s; | ||
3486 | |||
3487 | /* Copy the input string. */ | ||
3488 | s = ss; | ||
3489 | while( *s == ' ' ) /* skip leading spaces */ | ||
3490 | ++s; | ||
3491 | sp = lstr; | ||
3492 | for( k=0; k<79; k++ ) | ||
3493 | { | ||
3494 | if( (*sp++ = *s++) == '\0' ) | ||
3495 | break; | ||
3496 | } | ||
3497 | *sp = '\0'; | ||
3498 | s = lstr; | ||
3499 | |||
3500 | rndsav = rndprc; | ||
3501 | rndprc = NBITS; /* Set to full precision */ | ||
3502 | lost = 0; | ||
3503 | nsign = 0; | ||
3504 | decflg = 0; | ||
3505 | sgnflg = 0; | ||
3506 | nexp = 0; | ||
3507 | exp = 0; | ||
3508 | prec = 0; | ||
3509 | ecleaz( yy ); | ||
3510 | trail = 0; | ||
3511 | |||
3512 | nxtcom: | ||
3513 | k = *s - '0'; | ||
3514 | if( (k >= 0) && (k <= 9) ) | ||
3515 | { | ||
3516 | /* Ignore leading zeros */ | ||
3517 | if( (prec == 0) && (decflg == 0) && (k == 0) ) | ||
3518 | goto donchr; | ||
3519 | /* Identify and strip trailing zeros after the decimal point. */ | ||
3520 | if( (trail == 0) && (decflg != 0) ) | ||
3521 | { | ||
3522 | sp = s; | ||
3523 | while( (*sp >= '0') && (*sp <= '9') ) | ||
3524 | ++sp; | ||
3525 | /* Check for syntax error */ | ||
3526 | c = *sp & 0x7f; | ||
3527 | if( (c != 'e') && (c != 'E') && (c != '\0') | ||
3528 | && (c != '\n') && (c != '\r') && (c != ' ') | ||
3529 | && (c != ',') ) | ||
3530 | goto error; | ||
3531 | --sp; | ||
3532 | while( *sp == '0' ) | ||
3533 | *sp-- = 'z'; | ||
3534 | trail = 1; | ||
3535 | if( *s == 'z' ) | ||
3536 | goto donchr; | ||
3537 | } | ||
3538 | /* If enough digits were given to more than fill up the yy register, | ||
3539 | * continuing until overflow into the high guard word yy[2] | ||
3540 | * guarantees that there will be a roundoff bit at the top | ||
3541 | * of the low guard word after normalization. | ||
3542 | */ | ||
3543 | if( yy[2] == 0 ) | ||
3544 | { | ||
3545 | if( decflg ) | ||
3546 | nexp += 1; /* count digits after decimal point */ | ||
3547 | eshup1( yy ); /* multiply current number by 10 */ | ||
3548 | emovz( yy, xt ); | ||
3549 | eshup1( xt ); | ||
3550 | eshup1( xt ); | ||
3551 | eaddm( xt, yy ); | ||
3552 | ecleaz( xt ); | ||
3553 | xt[NI-2] = (unsigned short )k; | ||
3554 | eaddm( xt, yy ); | ||
3555 | } | ||
3556 | else | ||
3557 | { | ||
3558 | /* Mark any lost non-zero digit. */ | ||
3559 | lost |= k; | ||
3560 | /* Count lost digits before the decimal point. */ | ||
3561 | if (decflg == 0) | ||
3562 | nexp -= 1; | ||
3563 | } | ||
3564 | prec += 1; | ||
3565 | goto donchr; | ||
3566 | } | ||
3567 | |||
3568 | switch( *s ) | ||
3569 | { | ||
3570 | case 'z': | ||
3571 | break; | ||
3572 | case 'E': | ||
3573 | case 'e': | ||
3574 | goto expnt; | ||
3575 | case '.': /* decimal point */ | ||
3576 | if( decflg ) | ||
3577 | goto error; | ||
3578 | ++decflg; | ||
3579 | break; | ||
3580 | case '-': | ||
3581 | nsign = 0xffff; | ||
3582 | if( sgnflg ) | ||
3583 | goto error; | ||
3584 | ++sgnflg; | ||
3585 | break; | ||
3586 | case '+': | ||
3587 | if( sgnflg ) | ||
3588 | goto error; | ||
3589 | ++sgnflg; | ||
3590 | break; | ||
3591 | case ',': | ||
3592 | case ' ': | ||
3593 | case '\0': | ||
3594 | case '\n': | ||
3595 | case '\r': | ||
3596 | goto daldone; | ||
3597 | case 'i': | ||
3598 | case 'I': | ||
3599 | goto infinite; | ||
3600 | default: | ||
3601 | error: | ||
3602 | #ifdef NANS | ||
3603 | enan( yy, NI*16 ); | ||
3604 | #else | ||
3605 | mtherr( "asctoe", DOMAIN ); | ||
3606 | ecleaz(yy); | ||
3607 | #endif | ||
3608 | goto aexit; | ||
3609 | } | ||
3610 | donchr: | ||
3611 | ++s; | ||
3612 | goto nxtcom; | ||
3613 | |||
3614 | /* Exponent interpretation */ | ||
3615 | expnt: | ||
3616 | |||
3617 | esign = 1; | ||
3618 | exp = 0; | ||
3619 | ++s; | ||
3620 | /* check for + or - */ | ||
3621 | if( *s == '-' ) | ||
3622 | { | ||
3623 | esign = -1; | ||
3624 | ++s; | ||
3625 | } | ||
3626 | if( *s == '+' ) | ||
3627 | ++s; | ||
3628 | while( (*s >= '0') && (*s <= '9') ) | ||
3629 | { | ||
3630 | exp *= 10; | ||
3631 | exp += *s++ - '0'; | ||
3632 | if (exp > 4977) | ||
3633 | { | ||
3634 | if (esign < 0) | ||
3635 | goto zero; | ||
3636 | else | ||
3637 | goto infinite; | ||
3638 | } | ||
3639 | } | ||
3640 | if( esign < 0 ) | ||
3641 | exp = -exp; | ||
3642 | if( exp > 4932 ) | ||
3643 | { | ||
3644 | infinite: | ||
3645 | ecleaz(yy); | ||
3646 | yy[E] = 0x7fff; /* infinity */ | ||
3647 | goto aexit; | ||
3648 | } | ||
3649 | if( exp < -4977 ) | ||
3650 | { | ||
3651 | zero: | ||
3652 | ecleaz(yy); | ||
3653 | goto aexit; | ||
3654 | } | ||
3655 | |||
3656 | daldone: | ||
3657 | nexp = exp - nexp; | ||
3658 | /* Pad trailing zeros to minimize power of 10, per IEEE spec. */ | ||
3659 | while( (nexp > 0) && (yy[2] == 0) ) | ||
3660 | { | ||
3661 | emovz( yy, xt ); | ||
3662 | eshup1( xt ); | ||
3663 | eshup1( xt ); | ||
3664 | eaddm( yy, xt ); | ||
3665 | eshup1( xt ); | ||
3666 | if( xt[2] != 0 ) | ||
3667 | break; | ||
3668 | nexp -= 1; | ||
3669 | emovz( xt, yy ); | ||
3670 | } | ||
3671 | if( (k = enormlz(yy)) > NBITS ) | ||
3672 | { | ||
3673 | ecleaz(yy); | ||
3674 | goto aexit; | ||
3675 | } | ||
3676 | lexp = (EXONE - 1 + NBITS) - k; | ||
3677 | emdnorm( yy, lost, 0, lexp, 64 ); | ||
3678 | /* convert to external format */ | ||
3679 | |||
3680 | |||
3681 | /* Multiply by 10**nexp. If precision is 64 bits, | ||
3682 | * the maximum relative error incurred in forming 10**n | ||
3683 | * for 0 <= n <= 324 is 8.2e-20, at 10**180. | ||
3684 | * For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947. | ||
3685 | * For 0 >= n >= -999, it is -1.55e-19 at 10**-435. | ||
3686 | */ | ||
3687 | lexp = yy[E]; | ||
3688 | if( nexp == 0 ) | ||
3689 | { | ||
3690 | k = 0; | ||
3691 | goto expdon; | ||
3692 | } | ||
3693 | esign = 1; | ||
3694 | if( nexp < 0 ) | ||
3695 | { | ||
3696 | nexp = -nexp; | ||
3697 | esign = -1; | ||
3698 | if( nexp > 4096 ) | ||
3699 | { /* Punt. Can't handle this without 2 divides. */ | ||
3700 | emovi( etens[0], tt ); | ||
3701 | lexp -= tt[E]; | ||
3702 | k = edivm( tt, yy ); | ||
3703 | lexp += EXONE; | ||
3704 | nexp -= 4096; | ||
3705 | } | ||
3706 | } | ||
3707 | p = &etens[NTEN][0]; | ||
3708 | emov( eone, xt ); | ||
3709 | exp = 1; | ||
3710 | do | ||
3711 | { | ||
3712 | if( exp & nexp ) | ||
3713 | emul( p, xt, xt ); | ||
3714 | p -= NE; | ||
3715 | exp = exp + exp; | ||
3716 | } | ||
3717 | while( exp <= MAXP ); | ||
3718 | |||
3719 | emovi( xt, tt ); | ||
3720 | if( esign < 0 ) | ||
3721 | { | ||
3722 | lexp -= tt[E]; | ||
3723 | k = edivm( tt, yy ); | ||
3724 | lexp += EXONE; | ||
3725 | } | ||
3726 | else | ||
3727 | { | ||
3728 | lexp += tt[E]; | ||
3729 | k = emulm( tt, yy ); | ||
3730 | lexp -= EXONE - 1; | ||
3731 | } | ||
3732 | |||
3733 | expdon: | ||
3734 | |||
3735 | /* Round and convert directly to the destination type */ | ||
3736 | if( oprec == 53 ) | ||
3737 | lexp -= EXONE - 0x3ff; | ||
3738 | else if( oprec == 24 ) | ||
3739 | lexp -= EXONE - 0177; | ||
3740 | #ifdef DEC | ||
3741 | else if( oprec == 56 ) | ||
3742 | lexp -= EXONE - 0201; | ||
3743 | #endif | ||
3744 | rndprc = oprec; | ||
3745 | emdnorm( yy, k, 0, lexp, 64 ); | ||
3746 | |||
3747 | aexit: | ||
3748 | |||
3749 | rndprc = rndsav; | ||
3750 | yy[0] = nsign; | ||
3751 | switch( oprec ) | ||
3752 | { | ||
3753 | #ifdef DEC | ||
3754 | case 56: | ||
3755 | todec( yy, y ); /* see etodec.c */ | ||
3756 | break; | ||
3757 | #endif | ||
3758 | case 53: | ||
3759 | toe53( yy, y ); | ||
3760 | break; | ||
3761 | case 24: | ||
3762 | toe24( yy, y ); | ||
3763 | break; | ||
3764 | case 64: | ||
3765 | toe64( yy, y ); | ||
3766 | break; | ||
3767 | case 113: | ||
3768 | toe113( yy, y ); | ||
3769 | break; | ||
3770 | case NBITS: | ||
3771 | emovo( yy, y ); | ||
3772 | break; | ||
3773 | } | ||
3774 | } | ||
3775 | |||
3776 | |||
3777 | |||
3778 | /* y = largest integer not greater than x | ||
3779 | * (truncated toward minus infinity) | ||
3780 | * | ||
3781 | * unsigned short x[NE], y[NE] | ||
3782 | * | ||
3783 | * efloor( x, y ); | ||
3784 | */ | ||
3785 | static unsigned short bmask[] = { | ||
3786 | 0xffff, | ||
3787 | 0xfffe, | ||
3788 | 0xfffc, | ||
3789 | 0xfff8, | ||
3790 | 0xfff0, | ||
3791 | 0xffe0, | ||
3792 | 0xffc0, | ||
3793 | 0xff80, | ||
3794 | 0xff00, | ||
3795 | 0xfe00, | ||
3796 | 0xfc00, | ||
3797 | 0xf800, | ||
3798 | 0xf000, | ||
3799 | 0xe000, | ||
3800 | 0xc000, | ||
3801 | 0x8000, | ||
3802 | 0x0000, | ||
3803 | }; | ||
3804 | |||
3805 | void efloor( x, y ) | ||
3806 | unsigned short x[], y[]; | ||
3807 | { | ||
3808 | register unsigned short *p; | ||
3809 | int e, expon, i; | ||
3810 | unsigned short f[NE]; | ||
3811 | |||
3812 | emov( x, f ); /* leave in external format */ | ||
3813 | expon = (int )f[NE-1]; | ||
3814 | e = (expon & 0x7fff) - (EXONE - 1); | ||
3815 | if( e <= 0 ) | ||
3816 | { | ||
3817 | eclear(y); | ||
3818 | goto isitneg; | ||
3819 | } | ||
3820 | /* number of bits to clear out */ | ||
3821 | e = NBITS - e; | ||
3822 | emov( f, y ); | ||
3823 | if( e <= 0 ) | ||
3824 | return; | ||
3825 | |||
3826 | p = &y[0]; | ||
3827 | while( e >= 16 ) | ||
3828 | { | ||
3829 | *p++ = 0; | ||
3830 | e -= 16; | ||
3831 | } | ||
3832 | /* clear the remaining bits */ | ||
3833 | *p &= bmask[e]; | ||
3834 | /* truncate negatives toward minus infinity */ | ||
3835 | isitneg: | ||
3836 | |||
3837 | if( (unsigned short )expon & (unsigned short )0x8000 ) | ||
3838 | { | ||
3839 | for( i=0; i<NE-1; i++ ) | ||
3840 | { | ||
3841 | if( f[i] != y[i] ) | ||
3842 | { | ||
3843 | esub( eone, y, y ); | ||
3844 | break; | ||
3845 | } | ||
3846 | } | ||
3847 | } | ||
3848 | } | ||
3849 | |||
3850 | |||
3851 | /* unsigned short x[], s[]; | ||
3852 | * long *exp; | ||
3853 | * | ||
3854 | * efrexp( x, exp, s ); | ||
3855 | * | ||
3856 | * Returns s and exp such that s * 2**exp = x and .5 <= s < 1. | ||
3857 | * For example, 1.1 = 0.55 * 2**1 | ||
3858 | * Handles denormalized numbers properly using long integer exp. | ||
3859 | */ | ||
3860 | void efrexp( x, exp, s ) | ||
3861 | unsigned short x[]; | ||
3862 | long *exp; | ||
3863 | unsigned short s[]; | ||
3864 | { | ||
3865 | unsigned short xi[NI]; | ||
3866 | long li; | ||
3867 | |||
3868 | emovi( x, xi ); | ||
3869 | li = (long )((short )xi[1]); | ||
3870 | |||
3871 | if( li == 0 ) | ||
3872 | { | ||
3873 | li -= enormlz( xi ); | ||
3874 | } | ||
3875 | xi[1] = 0x3ffe; | ||
3876 | emovo( xi, s ); | ||
3877 | *exp = li - 0x3ffe; | ||
3878 | } | ||
3879 | |||
3880 | |||
3881 | |||
3882 | /* unsigned short x[], y[]; | ||
3883 | * long pwr2; | ||
3884 | * | ||
3885 | * eldexp( x, pwr2, y ); | ||
3886 | * | ||
3887 | * Returns y = x * 2**pwr2. | ||
3888 | */ | ||
3889 | void eldexp( x, pwr2, y ) | ||
3890 | unsigned short x[]; | ||
3891 | long pwr2; | ||
3892 | unsigned short y[]; | ||
3893 | { | ||
3894 | unsigned short xi[NI]; | ||
3895 | long li; | ||
3896 | int i; | ||
3897 | |||
3898 | emovi( x, xi ); | ||
3899 | li = xi[1]; | ||
3900 | li += pwr2; | ||
3901 | i = 0; | ||
3902 | emdnorm( xi, i, i, li, 64 ); | ||
3903 | emovo( xi, y ); | ||
3904 | } | ||
3905 | |||
3906 | |||
3907 | /* c = remainder after dividing b by a | ||
3908 | * Least significant integer quotient bits left in equot[]. | ||
3909 | */ | ||
3910 | void eremain( a, b, c ) | ||
3911 | unsigned short a[], b[], c[]; | ||
3912 | { | ||
3913 | unsigned short den[NI], num[NI]; | ||
3914 | |||
3915 | #ifdef NANS | ||
3916 | if( eisinf(b) || (ecmp(a,ezero) == 0) || eisnan(a) || eisnan(b)) | ||
3917 | { | ||
3918 | enan( c, NBITS ); | ||
3919 | return; | ||
3920 | } | ||
3921 | #endif | ||
3922 | if( ecmp(a,ezero) == 0 ) | ||
3923 | { | ||
3924 | mtherr( "eremain", SING ); | ||
3925 | eclear( c ); | ||
3926 | return; | ||
3927 | } | ||
3928 | emovi( a, den ); | ||
3929 | emovi( b, num ); | ||
3930 | eiremain( den, num ); | ||
3931 | /* Sign of remainder = sign of quotient */ | ||
3932 | if( a[0] == b[0] ) | ||
3933 | num[0] = 0; | ||
3934 | else | ||
3935 | num[0] = 0xffff; | ||
3936 | emovo( num, c ); | ||
3937 | } | ||
3938 | |||
3939 | |||
3940 | void eiremain( den, num ) | ||
3941 | unsigned short den[], num[]; | ||
3942 | { | ||
3943 | long ld, ln; | ||
3944 | unsigned short j; | ||
3945 | |||
3946 | ld = den[E]; | ||
3947 | ld -= enormlz( den ); | ||
3948 | ln = num[E]; | ||
3949 | ln -= enormlz( num ); | ||
3950 | ecleaz( equot ); | ||
3951 | while( ln >= ld ) | ||
3952 | { | ||
3953 | if( ecmpm(den,num) <= 0 ) | ||
3954 | { | ||
3955 | esubm(den, num); | ||
3956 | j = 1; | ||
3957 | } | ||
3958 | else | ||
3959 | { | ||
3960 | j = 0; | ||
3961 | } | ||
3962 | eshup1(equot); | ||
3963 | equot[NI-1] |= j; | ||
3964 | eshup1(num); | ||
3965 | ln -= 1; | ||
3966 | } | ||
3967 | emdnorm( num, 0, 0, ln, 0 ); | ||
3968 | } | ||
3969 | |||
3970 | /* NaN bit patterns | ||
3971 | */ | ||
3972 | #ifdef MIEEE | ||
3973 | unsigned short nan113[8] = { | ||
3974 | 0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
3975 | unsigned short nan64[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}; | ||
3976 | unsigned short nan53[4] = {0x7fff, 0xffff, 0xffff, 0xffff}; | ||
3977 | unsigned short nan24[2] = {0x7fff, 0xffff}; | ||
3978 | #endif | ||
3979 | |||
3980 | #ifdef IBMPC | ||
3981 | unsigned short nan113[8] = {0, 0, 0, 0, 0, 0, 0xc000, 0xffff}; | ||
3982 | unsigned short nan64[6] = {0, 0, 0, 0xc000, 0xffff, 0}; | ||
3983 | unsigned short nan53[4] = {0, 0, 0, 0xfff8}; | ||
3984 | unsigned short nan24[2] = {0, 0xffc0}; | ||
3985 | #endif | ||
3986 | |||
3987 | |||
3988 | void enan (nan, size) | ||
3989 | unsigned short *nan; | ||
3990 | int size; | ||
3991 | { | ||
3992 | int i, n; | ||
3993 | unsigned short *p; | ||
3994 | |||
3995 | switch( size ) | ||
3996 | { | ||
3997 | #ifndef DEC | ||
3998 | case 113: | ||
3999 | n = 8; | ||
4000 | p = nan113; | ||
4001 | break; | ||
4002 | |||
4003 | case 64: | ||
4004 | n = 6; | ||
4005 | p = nan64; | ||
4006 | break; | ||
4007 | |||
4008 | case 53: | ||
4009 | n = 4; | ||
4010 | p = nan53; | ||
4011 | break; | ||
4012 | |||
4013 | case 24: | ||
4014 | n = 2; | ||
4015 | p = nan24; | ||
4016 | break; | ||
4017 | |||
4018 | case NBITS: | ||
4019 | for( i=0; i<NE-2; i++ ) | ||
4020 | *nan++ = 0; | ||
4021 | *nan++ = 0xc000; | ||
4022 | *nan++ = 0x7fff; | ||
4023 | return; | ||
4024 | |||
4025 | case NI*16: | ||
4026 | *nan++ = 0; | ||
4027 | *nan++ = 0x7fff; | ||
4028 | *nan++ = 0; | ||
4029 | *nan++ = 0xc000; | ||
4030 | for( i=4; i<NI; i++ ) | ||
4031 | *nan++ = 0; | ||
4032 | return; | ||
4033 | #endif | ||
4034 | default: | ||
4035 | mtherr( "enan", DOMAIN ); | ||
4036 | return; | ||
4037 | } | ||
4038 | for (i=0; i < n; i++) | ||
4039 | *nan++ = *p++; | ||
4040 | } | ||
4041 | |||
4042 | |||
4043 | |||
4044 | /* Longhand square root. */ | ||
4045 | |||
4046 | static int esqinited = 0; | ||
4047 | static unsigned short sqrndbit[NI]; | ||
4048 | |||
4049 | void esqrt( x, y ) | ||
4050 | short *x, *y; | ||
4051 | { | ||
4052 | unsigned short temp[NI], num[NI], sq[NI], xx[NI]; | ||
4053 | int i, j, k, n, nlups; | ||
4054 | long m, exp; | ||
4055 | |||
4056 | if( esqinited == 0 ) | ||
4057 | { | ||
4058 | ecleaz( sqrndbit ); | ||
4059 | sqrndbit[NI-2] = 1; | ||
4060 | esqinited = 1; | ||
4061 | } | ||
4062 | /* Check for arg <= 0 */ | ||
4063 | i = ecmp( x, ezero ); | ||
4064 | if( i <= 0 ) | ||
4065 | { | ||
4066 | #ifdef NANS | ||
4067 | if (i == -2) | ||
4068 | { | ||
4069 | enan (y, NBITS); | ||
4070 | return; | ||
4071 | } | ||
4072 | #endif | ||
4073 | eclear(y); | ||
4074 | if( i < 0 ) | ||
4075 | mtherr( "esqrt", DOMAIN ); | ||
4076 | return; | ||
4077 | } | ||
4078 | |||
4079 | #ifdef INFINITY | ||
4080 | if( eisinf(x) ) | ||
4081 | { | ||
4082 | eclear(y); | ||
4083 | einfin(y); | ||
4084 | return; | ||
4085 | } | ||
4086 | #endif | ||
4087 | /* Bring in the arg and renormalize if it is denormal. */ | ||
4088 | emovi( x, xx ); | ||
4089 | m = (long )xx[1]; /* local long word exponent */ | ||
4090 | if( m == 0 ) | ||
4091 | m -= enormlz( xx ); | ||
4092 | |||
4093 | /* Divide exponent by 2 */ | ||
4094 | m -= 0x3ffe; | ||
4095 | exp = (unsigned short )( (m / 2) + 0x3ffe ); | ||
4096 | |||
4097 | /* Adjust if exponent odd */ | ||
4098 | if( (m & 1) != 0 ) | ||
4099 | { | ||
4100 | if( m > 0 ) | ||
4101 | exp += 1; | ||
4102 | eshdn1( xx ); | ||
4103 | } | ||
4104 | |||
4105 | ecleaz( sq ); | ||
4106 | ecleaz( num ); | ||
4107 | n = 8; /* get 8 bits of result per inner loop */ | ||
4108 | nlups = rndprc; | ||
4109 | j = 0; | ||
4110 | |||
4111 | while( nlups > 0 ) | ||
4112 | { | ||
4113 | /* bring in next word of arg */ | ||
4114 | if( j < NE ) | ||
4115 | num[NI-1] = xx[j+3]; | ||
4116 | /* Do additional bit on last outer loop, for roundoff. */ | ||
4117 | if( nlups <= 8 ) | ||
4118 | n = nlups + 1; | ||
4119 | for( i=0; i<n; i++ ) | ||
4120 | { | ||
4121 | /* Next 2 bits of arg */ | ||
4122 | eshup1( num ); | ||
4123 | eshup1( num ); | ||
4124 | /* Shift up answer */ | ||
4125 | eshup1( sq ); | ||
4126 | /* Make trial divisor */ | ||
4127 | for( k=0; k<NI; k++ ) | ||
4128 | temp[k] = sq[k]; | ||
4129 | eshup1( temp ); | ||
4130 | eaddm( sqrndbit, temp ); | ||
4131 | /* Subtract and insert answer bit if it goes in */ | ||
4132 | if( ecmpm( temp, num ) <= 0 ) | ||
4133 | { | ||
4134 | esubm( temp, num ); | ||
4135 | sq[NI-2] |= 1; | ||
4136 | } | ||
4137 | } | ||
4138 | nlups -= n; | ||
4139 | j += 1; | ||
4140 | } | ||
4141 | |||
4142 | /* Adjust for extra, roundoff loop done. */ | ||
4143 | exp += (NBITS - 1) - rndprc; | ||
4144 | |||
4145 | /* Sticky bit = 1 if the remainder is nonzero. */ | ||
4146 | k = 0; | ||
4147 | for( i=3; i<NI; i++ ) | ||
4148 | k |= (int )num[i]; | ||
4149 | |||
4150 | /* Renormalize and round off. */ | ||
4151 | emdnorm( sq, k, 0, exp, 64 ); | ||
4152 | emovo( sq, y ); | ||
4153 | } | ||
diff --git a/src/regress/lib/libc/cephes/ieetst.c b/src/regress/lib/libc/cephes/ieetst.c new file mode 100644 index 0000000000..41dfd6a96e --- /dev/null +++ b/src/regress/lib/libc/cephes/ieetst.c | |||
@@ -0,0 +1,880 @@ | |||
1 | /* $OpenBSD: ieetst.c,v 1.2 2011/07/03 13:39:07 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* Floating point to ASCII input and output string test program. | ||
20 | * | ||
21 | * Numbers in the native machine data structure are converted | ||
22 | * to e type, then to and from decimal ASCII strings. Native | ||
23 | * printf() and scanf() functions are also used to produce | ||
24 | * and read strings. The resulting e type binary values | ||
25 | * are compared, with diagnostic printouts of any discrepancies. | ||
26 | * | ||
27 | * Steve Moshier, 16 Dec 88 | ||
28 | * last revision: 16 May 92 | ||
29 | */ | ||
30 | |||
31 | #include <float.h> | ||
32 | #include <stdio.h> | ||
33 | |||
34 | #include "mconf.h" | ||
35 | #include "ehead.h" | ||
36 | |||
37 | /* Include tests of 80-bit long double precision: */ | ||
38 | #if LDBL_MANT_DIG == 64 | ||
39 | #define LDOUBLE 1 | ||
40 | #else /* LDBL_MANT_DIG == 64 */ | ||
41 | #define LDOUBLE 0 | ||
42 | #endif /* LDBL_MANT_DIG == 64 */ | ||
43 | /* Abort subtest after getting this many errors: */ | ||
44 | #define MAXERR 5 | ||
45 | /* Number of random arguments to try (set as large as you have | ||
46 | * patience for): */ | ||
47 | #define NRAND 100 | ||
48 | /* Perform internal consistency test: */ | ||
49 | #define CHKINTERNAL 0 | ||
50 | |||
51 | static unsigned short fullp[NE], rounded[NE]; | ||
52 | float prec24, sprec24, ssprec24; | ||
53 | double prec53, sprec53, ssprec53; | ||
54 | #if LDOUBLE | ||
55 | long double prec64, sprec64, ssprec64; | ||
56 | #endif | ||
57 | |||
58 | static unsigned short rprint[NE], rscan[NE]; | ||
59 | static unsigned short q1[NE], q2[NE], q5[NE]; | ||
60 | static unsigned short e1[NE], e2[NE], e3[NE]; | ||
61 | static double d1, d2; | ||
62 | static int errprint = 0; | ||
63 | static int errscan = 0; | ||
64 | static int identerr = 0; | ||
65 | static int errtot = 0; | ||
66 | static int count = 0; | ||
67 | static char str0[80], str1[80], str2[80], str3[80]; | ||
68 | static unsigned short eten[NE], maxm[NE]; | ||
69 | |||
70 | int m, n, k2, mprec, SPREC; | ||
71 | |||
72 | char *Ten = "10.0"; | ||
73 | char tformat[10]; | ||
74 | char *format24 = "%.8e"; | ||
75 | #ifdef DEC | ||
76 | char *format53 = "%.17e"; | ||
77 | #else | ||
78 | char *format53 = "%.16e"; | ||
79 | #endif | ||
80 | char *fformat24 = "%e"; | ||
81 | char *fformat53 = "%le"; | ||
82 | char *pct = "%"; | ||
83 | char *quo = "\042"; | ||
84 | #if LDOUBLE | ||
85 | char *format64 = "%.20Le"; | ||
86 | char *fformat64 = "%Le"; | ||
87 | #endif | ||
88 | char *format; | ||
89 | char *fformat; | ||
90 | char *toomany = "Too many errors; aborting this test.\n"; | ||
91 | |||
92 | static int mnrflag; | ||
93 | static int etrflag; | ||
94 | void chkit(), printerr(), mnrand(), etrand(), shownoncrit(); | ||
95 | void chkid(), pvec(); | ||
96 | |||
97 | main() | ||
98 | { | ||
99 | int i, iprec, retval = 0; | ||
100 | |||
101 | printf( "Steve Moshier's printf/scanf tester, version 0.2.\n\n" ); | ||
102 | #ifdef DEC | ||
103 | /* DEC PDP-11/VAX single precision not yet implemented */ | ||
104 | for( iprec = 1; iprec<2; iprec++ ) | ||
105 | #else | ||
106 | for( iprec = 0; iprec<3; iprec++ ) | ||
107 | /*for( iprec = 2; iprec<3; iprec++ )*/ | ||
108 | #endif | ||
109 | { | ||
110 | errscan = 0; | ||
111 | identerr = 0; | ||
112 | errprint = 0; | ||
113 | eclear( rprint ); | ||
114 | eclear( rscan ); | ||
115 | |||
116 | switch( iprec ) | ||
117 | { | ||
118 | case 0: | ||
119 | SPREC = 8; /* # digits after the decimal point */ | ||
120 | mprec = 24; /* # bits in the significand */ | ||
121 | m = 9; /* max # decimal digits for correct rounding */ | ||
122 | n = 13; /* max power of ten for correct rounding */ | ||
123 | k2 = -125; /* underflow beyond 2^-k2 */ | ||
124 | format = format24; /* printf format string */ | ||
125 | fformat = fformat24; /* scanf format string */ | ||
126 | mnrflag = 1; /* sets interval for random numbers */ | ||
127 | etrflag = 1; | ||
128 | printf( "Testing FLOAT precision.\n" ); | ||
129 | break; | ||
130 | |||
131 | case 1: | ||
132 | #ifdef DEC | ||
133 | SPREC = 17; | ||
134 | mprec = 56; | ||
135 | m = 17; | ||
136 | n = 27; | ||
137 | k2 = -125; | ||
138 | format = format53; | ||
139 | fformat = fformat53; | ||
140 | mnrflag = 2; | ||
141 | etrflag = 1; | ||
142 | printf( "Testing DEC DOUBLE precision.\n" ); | ||
143 | break; | ||
144 | #else | ||
145 | SPREC = 16; | ||
146 | mprec = 53; | ||
147 | m = 17; | ||
148 | n = 27; | ||
149 | k2 = -1021; | ||
150 | format = format53; | ||
151 | fformat = fformat53; | ||
152 | mnrflag = 2; | ||
153 | etrflag = 2; | ||
154 | printf( "Testing DOUBLE precision.\n" ); | ||
155 | break; | ||
156 | #endif | ||
157 | case 2: | ||
158 | #if LDOUBLE | ||
159 | SPREC = 20; | ||
160 | mprec = 64; | ||
161 | m = 20; | ||
162 | n = 34; | ||
163 | k2 = -16382; | ||
164 | format = format64; | ||
165 | fformat = fformat64; | ||
166 | mnrflag = 3; | ||
167 | etrflag = 3; | ||
168 | printf( "Testing LONG DOUBLE precision.\n" ); | ||
169 | break; | ||
170 | #else | ||
171 | goto nodenorm; | ||
172 | #endif | ||
173 | } | ||
174 | |||
175 | asctoe( Ten, eten ); | ||
176 | /* 10^m - 1 */ | ||
177 | d2 = m; | ||
178 | e53toe( &d2, e1 ); | ||
179 | epow( eten, e1, maxm ); | ||
180 | esub( eone, maxm, maxm ); | ||
181 | |||
182 | /* test 1 */ | ||
183 | printf( "1. Checking 10^n - 1 for n = %d to %d.\n", -m, m ); | ||
184 | emov( eone, q5 ); | ||
185 | for( count=0; count<=m; count++ ) | ||
186 | { | ||
187 | esub( eone, q5, fullp ); | ||
188 | chkit( 1 ); | ||
189 | ediv( q5, eone, q2 ); | ||
190 | esub( eone, q2, fullp ); | ||
191 | chkit( 1 ); | ||
192 | emul( eten, q5, q5 ); | ||
193 | if( errtot >= MAXERR ) | ||
194 | { | ||
195 | printf( "%s", toomany ); | ||
196 | goto end1; | ||
197 | } | ||
198 | } | ||
199 | end1: | ||
200 | printerr(); | ||
201 | |||
202 | |||
203 | /* test 2 */ | ||
204 | printf( "2. Checking powers of 10 from 10^-%d to 10^%d.\n", n, n ); | ||
205 | emov( eone, q5 ); | ||
206 | for( count=0; count<=n; count++ ) | ||
207 | { | ||
208 | emov( q5, fullp ); | ||
209 | chkit( 2 ); | ||
210 | ediv( q5, eone, fullp ); | ||
211 | chkit( 2 ); | ||
212 | emul( eten, q5, q5 ); | ||
213 | if( errtot >= MAXERR ) | ||
214 | { | ||
215 | printf( "%s", toomany ); | ||
216 | goto end2; | ||
217 | } | ||
218 | } | ||
219 | end2: | ||
220 | printerr(); | ||
221 | |||
222 | /* test 3 */ | ||
223 | printf( "3. Checking (10^%d-1)*10^n from n = -%d to %d.\n", m, n, n ); | ||
224 | emov( eone, q5 ); | ||
225 | for( count= -n; count<=n; count++ ) | ||
226 | { | ||
227 | emul( maxm, q5, fullp ); | ||
228 | chkit( 3 ); | ||
229 | emov( q5, fullp ); | ||
230 | ediv( fullp, eone, fullp ); | ||
231 | emul( maxm, fullp, fullp ); | ||
232 | chkit( 3 ); | ||
233 | emul( eten, q5, q5 ); | ||
234 | if( errtot >= MAXERR ) | ||
235 | { | ||
236 | printf( "%s", toomany ); | ||
237 | goto end3; | ||
238 | } | ||
239 | } | ||
240 | end3: | ||
241 | printerr(); | ||
242 | |||
243 | |||
244 | |||
245 | /* test 4 */ | ||
246 | printf( "4. Checking powers of 2 from 2^-24 to 2^+56.\n" ); | ||
247 | d1 = -24.0; | ||
248 | e53toe( &d1, q1 ); | ||
249 | epow( etwo, q1, q5 ); | ||
250 | |||
251 | for( count = -24; count <= 56; count++ ) | ||
252 | { | ||
253 | emov( q5, fullp ); | ||
254 | chkit( 4 ); | ||
255 | emul( etwo, q5, q5 ); | ||
256 | if( errtot >= MAXERR ) | ||
257 | { | ||
258 | printf( "%s", toomany ); | ||
259 | goto end4; | ||
260 | } | ||
261 | } | ||
262 | end4: | ||
263 | printerr(); | ||
264 | |||
265 | |||
266 | /* test 5 */ | ||
267 | printf( "5. Checking 2^n - 1 for n = 0 to %d.\n", mprec ); | ||
268 | emov( eone, q5 ); | ||
269 | for( count=0; count<=mprec; count++ ) | ||
270 | { | ||
271 | esub( eone, q5, fullp ); | ||
272 | chkit( 5 ); | ||
273 | emul( etwo, q5, q5 ); | ||
274 | if( errtot >= MAXERR ) | ||
275 | { | ||
276 | printf( "%s", toomany ); | ||
277 | goto end5; | ||
278 | } | ||
279 | } | ||
280 | end5: | ||
281 | printerr(); | ||
282 | |||
283 | /* test 6 */ | ||
284 | printf( "6. Checking 2^n + 1 for n = 0 to %d.\n", mprec ); | ||
285 | emov( eone, q5 ); | ||
286 | for( count=0; count<=mprec; count++ ) | ||
287 | { | ||
288 | eadd( eone, q5, fullp ); | ||
289 | chkit( 6 ); | ||
290 | emul( etwo, q5, q5 ); | ||
291 | if( errtot >= MAXERR ) | ||
292 | { | ||
293 | printf( "%s", toomany ); | ||
294 | goto end6; | ||
295 | } | ||
296 | } | ||
297 | end6: | ||
298 | printerr(); | ||
299 | |||
300 | /* test 7 */ | ||
301 | printf( | ||
302 | "7. Checking %d values M * 10^N with random integer M and N,\n", | ||
303 | NRAND ); | ||
304 | printf(" 1 <= M <= 10^%d - 1 and -%d <= N <= +%d.\n", m, n, n ); | ||
305 | for( i=0; i<NRAND; i++ ) | ||
306 | { | ||
307 | mnrand( fullp ); | ||
308 | chkit( 7 ); | ||
309 | if( errtot >= MAXERR ) | ||
310 | { | ||
311 | printf( "%s", toomany ); | ||
312 | goto end7; | ||
313 | } | ||
314 | } | ||
315 | end7: | ||
316 | printerr(); | ||
317 | |||
318 | /* test 8 */ | ||
319 | printf("8. Checking critical rounding cases.\n" ); | ||
320 | for( i=0; i<20; i++ ) | ||
321 | { | ||
322 | mnrand( fullp ); | ||
323 | eabs( fullp ); | ||
324 | if( ecmp( fullp, eone ) < 0 ) | ||
325 | ediv( fullp, eone, fullp ); | ||
326 | efloor( fullp, fullp ); | ||
327 | eadd( ehalf, fullp, fullp ); | ||
328 | chkit( 8 ); | ||
329 | if( errtot >= MAXERR ) | ||
330 | { | ||
331 | printf( "%s", toomany ); | ||
332 | goto end8; | ||
333 | } | ||
334 | } | ||
335 | end8: | ||
336 | printerr(); | ||
337 | |||
338 | |||
339 | |||
340 | /* test 9 */ | ||
341 | printf("9. Testing on %d random non-denormal values.\n", NRAND ); | ||
342 | for( i=0; i<NRAND; i++ ) | ||
343 | { | ||
344 | etrand( fullp ); | ||
345 | chkit( 9 ); | ||
346 | } | ||
347 | printerr(); | ||
348 | shownoncrit(); | ||
349 | |||
350 | /* test 10 */ | ||
351 | #if 0 | ||
352 | printf( | ||
353 | "Do you want to check denormal numbers in this precision ? (y/n) " ); | ||
354 | gets( str0 ); | ||
355 | if( str0[0] != 'y' ) | ||
356 | goto nodenorm; | ||
357 | #endif | ||
358 | |||
359 | printf( "10. Checking denormal numbers.\n" ); | ||
360 | |||
361 | /* Form 2^-starting power */ | ||
362 | d1 = k2; | ||
363 | e53toe( &d1, q1 ); | ||
364 | epow( etwo, q1, e1 ); | ||
365 | |||
366 | /* Find 2^-mprec less than starting power */ | ||
367 | d1 = -mprec + 4; | ||
368 | e53toe( &d1, q1 ); | ||
369 | epow( etwo, q1, e3 ); | ||
370 | emul( e1, e3, e3 ); | ||
371 | emov( e3, e2 ); | ||
372 | ediv( etwo, e2, e2 ); | ||
373 | |||
374 | while( ecmp(e1,e2) != 0 ) | ||
375 | { | ||
376 | eadd( e1, e2, fullp ); | ||
377 | switch( mprec ) | ||
378 | { | ||
379 | #if LDOUBLE | ||
380 | case 64: | ||
381 | etoe64( e1, &sprec64 ); | ||
382 | e64toe( &sprec64, q1 ); | ||
383 | etoe64( fullp, &prec64 ); | ||
384 | e64toe( &prec64, q2 ); | ||
385 | break; | ||
386 | #endif | ||
387 | #ifdef DEC | ||
388 | case 56: | ||
389 | #endif | ||
390 | case 53: | ||
391 | etoe53( e1, &sprec53 ); | ||
392 | e53toe( &sprec53, q1 ); | ||
393 | etoe53( fullp, &prec53 ); | ||
394 | e53toe( &prec53, q2 ); | ||
395 | break; | ||
396 | |||
397 | case 24: | ||
398 | etoe24( e1, &sprec24 ); | ||
399 | e24toe( &sprec24, q1 ); | ||
400 | etoe24( fullp, &prec24 ); | ||
401 | e24toe( &prec24, q2 ); | ||
402 | break; | ||
403 | } | ||
404 | if( ecmp( q2, ezero ) == 0 ) | ||
405 | goto maxden; | ||
406 | chkit(10); | ||
407 | if( ecmp(q1,q2) == 0 ) | ||
408 | { | ||
409 | ediv( etwo, e1, e1 ); | ||
410 | emov( e3, e2 ); | ||
411 | } | ||
412 | if( errtot >= MAXERR ) | ||
413 | { | ||
414 | printf( "%s", toomany ); | ||
415 | goto maxden; | ||
416 | } | ||
417 | ediv( etwo, e2, e2 ); | ||
418 | } | ||
419 | maxden: | ||
420 | printerr(); | ||
421 | nodenorm: | ||
422 | printf( "\n" ); | ||
423 | retval |= errscan | identerr | errprint; | ||
424 | } /* loop on precision */ | ||
425 | printf( "End of test.\n" ); | ||
426 | return (retval); | ||
427 | } | ||
428 | |||
429 | #if CHKINTERNAL | ||
430 | long double xprec64; | ||
431 | double xprec53; | ||
432 | float xprec24; | ||
433 | |||
434 | /* Check binary -> printf -> scanf -> binary identity | ||
435 | * of internal routines | ||
436 | */ | ||
437 | void chkinternal( ref, tst, string ) | ||
438 | unsigned short ref[], tst[]; | ||
439 | char *string; | ||
440 | { | ||
441 | |||
442 | if( ecmp(ref,tst) != 0 ) | ||
443 | { | ||
444 | printf( "internal identity compare error!\n" ); | ||
445 | chkid( ref, tst, string ); | ||
446 | } | ||
447 | } | ||
448 | #endif | ||
449 | |||
450 | |||
451 | /* Check binary -> printf -> scanf -> binary identity | ||
452 | */ | ||
453 | void chkid( print, scan, string ) | ||
454 | unsigned short print[], scan[]; | ||
455 | char *string; | ||
456 | { | ||
457 | /* Test printf-scanf identity */ | ||
458 | if( ecmp( print, scan ) != 0 ) | ||
459 | { | ||
460 | pvec( print, NE ); | ||
461 | printf( " ->printf-> %s ->scanf->\n", string ); | ||
462 | pvec( scan, NE ); | ||
463 | printf( " is not an identity.\n" ); | ||
464 | ++identerr; | ||
465 | } | ||
466 | } | ||
467 | |||
468 | |||
469 | /* Check scanf result | ||
470 | */ | ||
471 | void chkscan( ref, tst, string ) | ||
472 | unsigned short ref[], tst[]; | ||
473 | char *string; | ||
474 | { | ||
475 | /* Test scanf() */ | ||
476 | if( ecmp( ref, tst ) != 0 ) | ||
477 | { | ||
478 | printf( "scanf(%s) -> ", string ); | ||
479 | pvec( tst, NE ); | ||
480 | printf( "\n should be " ); | ||
481 | pvec( ref, NE ); | ||
482 | printf( ".\n" ); | ||
483 | ++errscan; | ||
484 | ++errtot; | ||
485 | } | ||
486 | } | ||
487 | |||
488 | |||
489 | /* Test printf() result | ||
490 | */ | ||
491 | void chkprint( ref, tst, string ) | ||
492 | unsigned short ref[], tst[]; | ||
493 | char *string; | ||
494 | { | ||
495 | if( ecmp(ref, tst) != 0 ) | ||
496 | { | ||
497 | printf( "printf( "); | ||
498 | pvec( ref, NE ); | ||
499 | printf( ") -> %s\n", string ); | ||
500 | printf( " = " ); | ||
501 | pvec( tst, NE ); | ||
502 | printf( ".\n" ); | ||
503 | ++errprint; | ||
504 | ++errtot; | ||
505 | } | ||
506 | } | ||
507 | |||
508 | |||
509 | /* Print array of n 16-bit shorts | ||
510 | */ | ||
511 | void pvec( x, n ) | ||
512 | unsigned short x[]; | ||
513 | int n; | ||
514 | { | ||
515 | int i; | ||
516 | |||
517 | for( i=0; i<n; i++ ) | ||
518 | { | ||
519 | printf( "%04x ", x[i] ); | ||
520 | } | ||
521 | } | ||
522 | |||
523 | /* Measure worst case printf rounding error | ||
524 | */ | ||
525 | void cmpprint( ref, tst ) | ||
526 | unsigned short ref[], tst[]; | ||
527 | { | ||
528 | unsigned short e[NE]; | ||
529 | |||
530 | if( ecmp( ref, ezero ) != 0 ) | ||
531 | { | ||
532 | esub( ref, tst, e ); | ||
533 | ediv( ref, e, e ); | ||
534 | eabs( e ); | ||
535 | if( ecmp( e, rprint ) > 0 ) | ||
536 | emov( e, rprint ); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | /* Measure worst case scanf rounding error | ||
541 | */ | ||
542 | void cmpscan( ref, tst ) | ||
543 | unsigned short ref[], tst[]; | ||
544 | { | ||
545 | unsigned short er[NE]; | ||
546 | |||
547 | if( ecmp( ref, ezero ) != 0 ) | ||
548 | { | ||
549 | esub( ref, tst, er ); | ||
550 | ediv( ref, er, er ); | ||
551 | eabs( er ); | ||
552 | if( ecmp( er, rscan ) > 0 ) | ||
553 | emov( er, rscan ); | ||
554 | if( ecmp( er, ehalf ) > 0 ) | ||
555 | { | ||
556 | etoasc( tst, str1, 21 ); | ||
557 | printf( "Bad error: scanf(%s) = %s !\n", str0, str1 ); | ||
558 | } | ||
559 | } | ||
560 | } | ||
561 | |||
562 | /* Check rounded-down decimal string output of printf | ||
563 | */ | ||
564 | void cmptrunc( ref, tst ) | ||
565 | unsigned short ref[], tst[]; | ||
566 | { | ||
567 | if( ecmp( ref, tst ) != 0 ) | ||
568 | { | ||
569 | printf( "printf(%s%s%s, %s) -> %s\n", quo, tformat, quo, str1, str2 ); | ||
570 | printf( "should be %s .\n", str3 ); | ||
571 | errprint += 1; | ||
572 | } | ||
573 | } | ||
574 | |||
575 | |||
576 | void shownoncrit() | ||
577 | { | ||
578 | |||
579 | etoasc( rprint, str0, 3 ); | ||
580 | printf( "Maximum relative printf error found = %s .\n", str0 ); | ||
581 | etoasc( rscan, str0, 3 ); | ||
582 | printf( "Maximum relative scanf error found = %s .\n", str0 ); | ||
583 | } | ||
584 | |||
585 | |||
586 | |||
587 | /* Produce arguments and call comparison subroutines. | ||
588 | */ | ||
589 | void chkit( testno ) | ||
590 | int testno; | ||
591 | { | ||
592 | unsigned short t[NE], u[NE], v[NE]; | ||
593 | int j; | ||
594 | |||
595 | switch( mprec ) | ||
596 | { | ||
597 | #if LDOUBLE | ||
598 | case 64: | ||
599 | etoe64( fullp, &prec64 ); | ||
600 | e64toe( &prec64, rounded ); | ||
601 | #if CHKINTERNAL | ||
602 | e64toasc( &prec64, str1, SPREC ); | ||
603 | asctoe64( str1, &xprec64 ); | ||
604 | e64toe( &xprec64, t ); | ||
605 | chkinternal( rounded, t, str1 ); | ||
606 | #endif | ||
607 | /* check printf and scanf */ | ||
608 | sprintf( str2, format, prec64 ); | ||
609 | sscanf( str2, fformat, &sprec64 ); | ||
610 | e64toe( &sprec64, u ); | ||
611 | chkid( rounded, u, str2 ); | ||
612 | asctoe64( str2, &ssprec64 ); | ||
613 | e64toe( &ssprec64, v ); | ||
614 | chkscan( v, u, str2 ); | ||
615 | chkprint( rounded, v, str2 ); | ||
616 | if( testno < 8 ) | ||
617 | break; | ||
618 | /* rounding error measurement */ | ||
619 | etoasc( fullp, str0, 24 ); | ||
620 | etoe64( fullp, &ssprec64 ); | ||
621 | e64toe( &ssprec64, u ); | ||
622 | sprintf( str2, format, ssprec64 ); | ||
623 | asctoe( str2, t ); | ||
624 | cmpprint( u, t ); | ||
625 | sscanf( str0, fformat, &sprec64 ); | ||
626 | e64toe( &sprec64, t ); | ||
627 | cmpscan( fullp, t ); | ||
628 | if( testno < 8 ) | ||
629 | break; | ||
630 | /* strings rounded to less than maximum precision */ | ||
631 | e64toasc( &ssprec64, str1, 24 ); | ||
632 | for( j=SPREC-1; j>0; j-- ) | ||
633 | { | ||
634 | e64toasc( &ssprec64, str3, j ); | ||
635 | asctoe( str3, v ); | ||
636 | sprintf( tformat, "%s.%dLe", pct, j ); | ||
637 | sprintf( str2, tformat, ssprec64 ); | ||
638 | asctoe( str2, t ); | ||
639 | cmptrunc( v, t ); | ||
640 | } | ||
641 | break; | ||
642 | #endif | ||
643 | #ifdef DEC | ||
644 | case 56: | ||
645 | #endif | ||
646 | case 53: | ||
647 | etoe53( fullp, &prec53 ); | ||
648 | e53toe( &prec53, rounded ); | ||
649 | #if CHKINTERNAL | ||
650 | e53toasc( &prec53, str1, SPREC ); | ||
651 | asctoe53( str1, &xprec53 ); | ||
652 | e53toe( &xprec53, t ); | ||
653 | chkinternal( rounded, t, str1 ); | ||
654 | #endif | ||
655 | sprintf( str2, format, prec53 ); | ||
656 | sscanf( str2, fformat, &sprec53 ); | ||
657 | e53toe( &sprec53, u ); | ||
658 | chkid( rounded, u, str2 ); | ||
659 | asctoe53( str2, &ssprec53 ); | ||
660 | e53toe( &ssprec53, v ); | ||
661 | chkscan( v, u, str2 ); | ||
662 | chkprint( rounded, v, str2 ); | ||
663 | if( testno < 8 ) | ||
664 | break; | ||
665 | /* rounding error measurement */ | ||
666 | etoasc( fullp, str0, 24 ); | ||
667 | etoe53( fullp, &ssprec53 ); | ||
668 | e53toe( &ssprec53, u ); | ||
669 | sprintf( str2, format, ssprec53 ); | ||
670 | asctoe( str2, t ); | ||
671 | cmpprint( u, t ); | ||
672 | sscanf( str0, fformat, &sprec53 ); | ||
673 | e53toe( &sprec53, t ); | ||
674 | cmpscan( fullp, t ); | ||
675 | if( testno < 8 ) | ||
676 | break; | ||
677 | e53toasc( &ssprec53, str1, 24 ); | ||
678 | for( j=SPREC-1; j>0; j-- ) | ||
679 | { | ||
680 | e53toasc( &ssprec53, str3, j ); | ||
681 | asctoe( str3, v ); | ||
682 | sprintf( tformat, "%s.%de", pct, j ); | ||
683 | sprintf( str2, tformat, ssprec53 ); | ||
684 | asctoe( str2, t ); | ||
685 | cmptrunc( v, t ); | ||
686 | } | ||
687 | break; | ||
688 | |||
689 | case 24: | ||
690 | etoe24( fullp, &prec24 ); | ||
691 | e24toe( &prec24, rounded ); | ||
692 | #if CHKINTERNAL | ||
693 | e24toasc( &prec24, str1, SPREC ); | ||
694 | asctoe24( str1, &xprec24 ); | ||
695 | e24toe( &xprec24, t ); | ||
696 | chkinternal( rounded, t, str1 ); | ||
697 | #endif | ||
698 | sprintf( str2, format, prec24 ); | ||
699 | sscanf( str2, fformat, &sprec24 ); | ||
700 | e24toe( &sprec24, u ); | ||
701 | chkid( rounded, u, str2 ); | ||
702 | asctoe24( str2, &ssprec24 ); | ||
703 | e24toe( &ssprec24, v ); | ||
704 | chkscan( v, u, str2 ); | ||
705 | chkprint( rounded, v, str2 ); | ||
706 | if( testno < 8 ) | ||
707 | break; | ||
708 | /* rounding error measurement */ | ||
709 | etoasc( fullp, str0, 24 ); | ||
710 | etoe24( fullp, &ssprec24 ); | ||
711 | e24toe( &ssprec24, u ); | ||
712 | sprintf( str2, format, ssprec24 ); | ||
713 | asctoe( str2, t ); | ||
714 | cmpprint( u, t ); | ||
715 | sscanf( str0, fformat, &sprec24 ); | ||
716 | e24toe( &sprec24, t ); | ||
717 | cmpscan( fullp, t ); | ||
718 | /* | ||
719 | if( testno < 8 ) | ||
720 | break; | ||
721 | */ | ||
722 | e24toasc( &ssprec24, str1, 24 ); | ||
723 | for( j=SPREC-1; j>0; j-- ) | ||
724 | { | ||
725 | e24toasc( &ssprec24, str3, j ); | ||
726 | asctoe( str3, v ); | ||
727 | sprintf( tformat, "%s.%de", pct, j ); | ||
728 | sprintf( str2, tformat, ssprec24 ); | ||
729 | asctoe( str2, t ); | ||
730 | cmptrunc( v, t ); | ||
731 | } | ||
732 | break; | ||
733 | } | ||
734 | } | ||
735 | |||
736 | |||
737 | void printerr() | ||
738 | { | ||
739 | if( (errscan == 0) && (identerr == 0) && (errprint == 0) ) | ||
740 | printf( "No errors found.\n" ); | ||
741 | else | ||
742 | { | ||
743 | printf( "%d binary -> decimal errors found.\n", errprint ); | ||
744 | printf( "%d decimal -> binary errors found.\n", errscan ); | ||
745 | } | ||
746 | errscan = 0; /* reset for next test */ | ||
747 | identerr = 0; | ||
748 | errprint = 0; | ||
749 | errtot = 0; | ||
750 | } | ||
751 | |||
752 | |||
753 | /* Random number generator | ||
754 | * in the range M * 10^N, where 1 <= M <= 10^17 - 1 | ||
755 | * and -27 <= N <= +27. Test values of M are logarithmically distributed | ||
756 | * random integers; test values of N are uniformly distributed random integers. | ||
757 | */ | ||
758 | |||
759 | static char *fwidth = "1.036163291797320557783096e1"; /* log(sqrt(10^9-1)) */ | ||
760 | static char *dwidth = "1.957197329044938830915E1"; /* log(sqrt(10^17-1)) */ | ||
761 | static char *ldwidth = "2.302585092994045684017491e1"; /* log(sqrt(10^20-1)) */ | ||
762 | |||
763 | static char *a13 = "13.0"; | ||
764 | static char *a27 = "27.0"; | ||
765 | static char *a34 = "34.0"; | ||
766 | static char *a10m13 = "1.0e-13"; | ||
767 | static unsigned short LOW[ NE ], WIDTH[NE], e27[NE], e10m13[NE]; | ||
768 | |||
769 | |||
770 | void mnrand( erand ) | ||
771 | unsigned short erand[]; | ||
772 | { | ||
773 | unsigned short ea[NE], em[NE], en[NE], ex[NE]; | ||
774 | double x, a; | ||
775 | |||
776 | if( mnrflag ) | ||
777 | { | ||
778 | if( mnrflag == 3 ) | ||
779 | { | ||
780 | asctoe( ldwidth, WIDTH ); | ||
781 | asctoe( a34, e27 ); | ||
782 | } | ||
783 | if( mnrflag == 2 ) | ||
784 | { | ||
785 | asctoe( dwidth, WIDTH ); | ||
786 | asctoe( a27, e27 ); | ||
787 | } | ||
788 | if( mnrflag == 1 ) | ||
789 | { | ||
790 | asctoe( fwidth, WIDTH ); | ||
791 | asctoe( a13, e27 ); | ||
792 | } | ||
793 | asctoe( a10m13, e10m13 ); | ||
794 | mnrflag = 0; | ||
795 | } | ||
796 | drand( &x ); | ||
797 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
798 | esub( eone, ex, ex ); | ||
799 | emul( WIDTH, ex, ex ); | ||
800 | eexp( ex, ex ); /* x = exp(x); */ | ||
801 | |||
802 | drand( &a ); | ||
803 | e53toe( &a, ea ); | ||
804 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
805 | emul( e10m13, ea, ea ); | ||
806 | eabs( ea ); | ||
807 | eadd( ea, ex, ex ); /* add fuzz */ | ||
808 | emul( ex, ex, ex ); /* square it, to get range to 10^17 - 1 */ | ||
809 | efloor( ex, em ); /* this is M */ | ||
810 | |||
811 | /* Random power of 10 */ | ||
812 | drand( &a ); | ||
813 | e53toe( &a, ex ); | ||
814 | esub( eone, ex, ex ); /* y3 = 54.0 * ( y3 - 1.0 ) + 0.5; */ | ||
815 | emul( e27, ex, ex ); | ||
816 | eadd( ex, ex, ex ); | ||
817 | eadd( ehalf, ex, ex ); | ||
818 | efloor( ex, ex ); /* y3 = floor( y3 ) - 27.0; */ | ||
819 | esub( e27, ex, en ); /* this is N */ | ||
820 | epow( eten, en, ex ); | ||
821 | emul( ex, em, erand ); | ||
822 | } | ||
823 | |||
824 | /* -ln 2^16382 */ | ||
825 | char *ldemin = "-1.1355137111933024058873097E4"; | ||
826 | char *ldewid = "2.2710274223866048117746193E4"; | ||
827 | /* -ln 2^1022 */ | ||
828 | char *demin = "-7.0839641853226410622441123E2"; | ||
829 | char *dewid = "1.4167928370645282124488225E3"; | ||
830 | /* -ln 2^125 */ | ||
831 | char *femin = "-8.6643397569993163677154015E1"; | ||
832 | char *fewid = "1.7328679513998632735430803E2"; | ||
833 | |||
834 | void etrand( erand ) | ||
835 | unsigned short erand[]; | ||
836 | { | ||
837 | unsigned short ea[NE], ex[NE]; | ||
838 | double x, a; | ||
839 | |||
840 | if( etrflag ) | ||
841 | { | ||
842 | if( etrflag == 3 ) | ||
843 | { | ||
844 | asctoe( ldemin, LOW ); | ||
845 | asctoe( ldewid, WIDTH ); | ||
846 | asctoe( a34, e27 ); | ||
847 | } | ||
848 | if( etrflag == 2 ) | ||
849 | { | ||
850 | asctoe( demin, LOW ); | ||
851 | asctoe( dewid, WIDTH ); | ||
852 | asctoe( a27, e27 ); | ||
853 | } | ||
854 | if( etrflag == 1 ) | ||
855 | { | ||
856 | asctoe( femin, LOW ); | ||
857 | asctoe( fewid, WIDTH ); | ||
858 | asctoe( a13, e27 ); | ||
859 | } | ||
860 | asctoe( a10m13, e10m13 ); | ||
861 | etrflag = 0; | ||
862 | } | ||
863 | drand( &x ); | ||
864 | e53toe( &x, ex ); /* x = WIDTH * ( x - 1.0 ) + LOW; */ | ||
865 | esub( eone, ex, ex ); | ||
866 | emul( WIDTH, ex, ex ); | ||
867 | eadd( LOW, ex, ex ); | ||
868 | eexp( ex, ex ); /* x = exp(x); */ | ||
869 | |||
870 | /* add fuzz | ||
871 | */ | ||
872 | drand( &a ); | ||
873 | e53toe( &a, ea ); | ||
874 | emul( ea, ex, ea ); /* a = 1.0e-13 * x * a; */ | ||
875 | emul( e10m13, ea, ea ); | ||
876 | if( ecmp( ex, ezero ) > 0 ) | ||
877 | eneg( ea ); | ||
878 | eadd( ea, ex, erand ); | ||
879 | } | ||
880 | |||
diff --git a/src/regress/lib/libc/cephes/mconf.h b/src/regress/lib/libc/cephes/mconf.h new file mode 100644 index 0000000000..a92bd3ab64 --- /dev/null +++ b/src/regress/lib/libc/cephes/mconf.h | |||
@@ -0,0 +1,187 @@ | |||
1 | /* $OpenBSD: mconf.h,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* mconf.h | ||
20 | * | ||
21 | * Common include file for math routines | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * #include "mconf.h" | ||
28 | * | ||
29 | * | ||
30 | * | ||
31 | * DESCRIPTION: | ||
32 | * | ||
33 | * This file contains definitions for error codes that are | ||
34 | * passed to the common error handling routine mtherr() | ||
35 | * (which see). | ||
36 | * | ||
37 | * The file also includes a conditional assembly definition | ||
38 | * for the type of computer arithmetic (IEEE, DEC, Motorola | ||
39 | * IEEE, or UNKnown). | ||
40 | * | ||
41 | * For Digital Equipment PDP-11 and VAX computers, certain | ||
42 | * IBM systems, and others that use numbers with a 56-bit | ||
43 | * significand, the symbol DEC should be defined. In this | ||
44 | * mode, most floating point constants are given as arrays | ||
45 | * of octal integers to eliminate decimal to binary conversion | ||
46 | * errors that might be introduced by the compiler. | ||
47 | * | ||
48 | * For little-endian computers, such as IBM PC, that follow the | ||
49 | * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE | ||
50 | * Std 754-1985), the symbol IBMPC should be defined. These | ||
51 | * numbers have 53-bit significands. In this mode, constants | ||
52 | * are provided as arrays of hexadecimal 16 bit integers. | ||
53 | * | ||
54 | * Big-endian IEEE format is denoted MIEEE. On some RISC | ||
55 | * systems such as Sun SPARC, double precision constants | ||
56 | * must be stored on 8-byte address boundaries. Since integer | ||
57 | * arrays may be aligned differently, the MIEEE configuration | ||
58 | * may fail on such machines. | ||
59 | * | ||
60 | * To accommodate other types of computer arithmetic, all | ||
61 | * constants are also provided in a normal decimal radix | ||
62 | * which one can hope are correctly converted to a suitable | ||
63 | * format by the available C language compiler. To invoke | ||
64 | * this mode, define the symbol UNK. | ||
65 | * | ||
66 | * An important difference among these modes is a predefined | ||
67 | * set of machine arithmetic constants for each. The numbers | ||
68 | * MACHEP (the machine roundoff error), MAXNUM (largest number | ||
69 | * represented), and several other parameters are preset by | ||
70 | * the configuration symbol. Check the file const.c to | ||
71 | * ensure that these values are correct for your computer. | ||
72 | * | ||
73 | * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL | ||
74 | * may fail on many systems. Verify that they are supposed | ||
75 | * to work on your computer. | ||
76 | */ | ||
77 | |||
78 | #include <sys/types.h> | ||
79 | #include <sys/endian.h> | ||
80 | |||
81 | /* Constant definitions for math error conditions | ||
82 | */ | ||
83 | |||
84 | #define DOMAIN 1 /* argument domain error */ | ||
85 | #define SING 2 /* argument singularity */ | ||
86 | #define OVERFLOW 3 /* overflow range error */ | ||
87 | #define UNDERFLOW 4 /* underflow range error */ | ||
88 | #define TLOSS 5 /* total loss of precision */ | ||
89 | #define PLOSS 6 /* partial loss of precision */ | ||
90 | |||
91 | #define EDOM 33 | ||
92 | #define ERANGE 34 | ||
93 | |||
94 | /* Complex numeral. */ | ||
95 | typedef struct | ||
96 | { | ||
97 | double r; | ||
98 | double i; | ||
99 | } cmplx; | ||
100 | |||
101 | /* Long double complex numeral. */ | ||
102 | typedef struct | ||
103 | { | ||
104 | double r; | ||
105 | double i; | ||
106 | } cmplxl; | ||
107 | |||
108 | /* Type of computer arithmetic */ | ||
109 | |||
110 | /* PDP-11, Pro350, VAX: | ||
111 | */ | ||
112 | #ifdef __vax__ | ||
113 | #define DEC 1 | ||
114 | #endif /* __vax__ */ | ||
115 | |||
116 | /* Intel IEEE, low order words come first: | ||
117 | */ | ||
118 | /* #define IBMPC 1 */ | ||
119 | |||
120 | /* Motorola IEEE, high order words come first | ||
121 | * (Sun 680x0 workstation): | ||
122 | */ | ||
123 | /* #define MIEEE 1 */ | ||
124 | |||
125 | /* UNKnown arithmetic, invokes coefficients given in | ||
126 | * normal decimal format. Beware of range boundary | ||
127 | * problems (MACHEP, MAXLOG, etc. in const.c) and | ||
128 | * roundoff problems in pow.c: | ||
129 | * (Sun SPARCstation) | ||
130 | */ | ||
131 | #ifndef __vax__ | ||
132 | #define UNK 1 | ||
133 | #endif /* !__vax__ */ | ||
134 | |||
135 | /* If you define UNK, then be sure to set BIGENDIAN properly. */ | ||
136 | #if BYTE_ORDER == BIG_ENDIAN | ||
137 | #define BIGENDIAN 1 | ||
138 | #endif /* BYTE_ORDER == BIG_ENDIAN */ | ||
139 | |||
140 | /* Define this `volatile' if your compiler thinks | ||
141 | * that floating point arithmetic obeys the associative | ||
142 | * and distributive laws. It will defeat some optimizations | ||
143 | * (but probably not enough of them). | ||
144 | * | ||
145 | * #define VOLATILE volatile | ||
146 | */ | ||
147 | #define VOLATILE | ||
148 | |||
149 | /* For 12-byte long doubles on an i386, pad a 16-bit short 0 | ||
150 | * to the end of real constants initialized by integer arrays. | ||
151 | * | ||
152 | * #define XPD 0, | ||
153 | * | ||
154 | * Otherwise, the type is 10 bytes long and XPD should be | ||
155 | * defined blank (e.g., Microsoft C). | ||
156 | * | ||
157 | * #define XPD | ||
158 | */ | ||
159 | #define XPD 0, | ||
160 | |||
161 | /* Define to support tiny denormal numbers, else undefine. */ | ||
162 | #ifndef __vax__ | ||
163 | #define DENORMAL 1 | ||
164 | #endif /* !__vax__ */ | ||
165 | |||
166 | /* Define to ask for infinity support, else undefine. */ | ||
167 | #ifndef __vax__ | ||
168 | #define INFINITIES 1 | ||
169 | #endif /* !__vax__ */ | ||
170 | |||
171 | /* Define to ask for support of numbers that are Not-a-Number, | ||
172 | else undefine. This may automatically define INFINITIES in some files. */ | ||
173 | #ifndef __vax__ | ||
174 | #define NANS 1 | ||
175 | #endif /* !__vax__ */ | ||
176 | |||
177 | /* Define to distinguish between -0.0 and +0.0. */ | ||
178 | #define MINUSZERO 1 | ||
179 | |||
180 | /* Define 1 for ANSI C atan2() function | ||
181 | See atan.c and clog.c. */ | ||
182 | #define ANSIC 1 | ||
183 | |||
184 | int mtherr(); | ||
185 | |||
186 | /* Variable for error reporting. See mtherr.c. */ | ||
187 | extern int merror; | ||
diff --git a/src/regress/lib/libc/cephes/mtherr.c b/src/regress/lib/libc/cephes/mtherr.c new file mode 100644 index 0000000000..9a47a198bd --- /dev/null +++ b/src/regress/lib/libc/cephes/mtherr.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* $OpenBSD: mtherr.c,v 1.1 2011/07/02 18:11:01 martynas Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | /* mtherr.c | ||
20 | * | ||
21 | * Library common error handling routine | ||
22 | * | ||
23 | * | ||
24 | * | ||
25 | * SYNOPSIS: | ||
26 | * | ||
27 | * char *fctnam; | ||
28 | * int code; | ||
29 | * int mtherr(); | ||
30 | * | ||
31 | * mtherr( fctnam, code ); | ||
32 | * | ||
33 | * | ||
34 | * | ||
35 | * DESCRIPTION: | ||
36 | * | ||
37 | * This routine may be called to report one of the following | ||
38 | * error conditions (in the include file mconf.h). | ||
39 | * | ||
40 | * Mnemonic Value Significance | ||
41 | * | ||
42 | * DOMAIN 1 argument domain error | ||
43 | * SING 2 function singularity | ||
44 | * OVERFLOW 3 overflow range error | ||
45 | * UNDERFLOW 4 underflow range error | ||
46 | * TLOSS 5 total loss of precision | ||
47 | * PLOSS 6 partial loss of precision | ||
48 | * EDOM 33 Unix domain error code | ||
49 | * ERANGE 34 Unix range error code | ||
50 | * | ||
51 | * The default version of the file prints the function name, | ||
52 | * passed to it by the pointer fctnam, followed by the | ||
53 | * error condition. The display is directed to the standard | ||
54 | * output device. The routine then returns to the calling | ||
55 | * program. Users may wish to modify the program to abort by | ||
56 | * calling exit() under severe error conditions such as domain | ||
57 | * errors. | ||
58 | * | ||
59 | * Since all error conditions pass control to this function, | ||
60 | * the display may be easily changed, eliminated, or directed | ||
61 | * to an error logging device. | ||
62 | * | ||
63 | * SEE ALSO: | ||
64 | * | ||
65 | * mconf.h | ||
66 | * | ||
67 | */ | ||
68 | |||
69 | #include <stdio.h> | ||
70 | #include "mconf.h" | ||
71 | |||
72 | int merror = 0; | ||
73 | |||
74 | /* Notice: the order of appearance of the following | ||
75 | * messages is bound to the error codes defined | ||
76 | * in mconf.h. | ||
77 | */ | ||
78 | static char *ermsg[7] = { | ||
79 | "unknown", /* error code 0 */ | ||
80 | "domain", /* error code 1 */ | ||
81 | "singularity", /* et seq. */ | ||
82 | "overflow", | ||
83 | "underflow", | ||
84 | "total loss of precision", | ||
85 | "partial loss of precision" | ||
86 | }; | ||
87 | |||
88 | |||
89 | int mtherr( name, code ) | ||
90 | char *name; | ||
91 | int code; | ||
92 | { | ||
93 | |||
94 | /* Display string passed by calling program, | ||
95 | * which is supposed to be the name of the | ||
96 | * function in which the error occurred: | ||
97 | */ | ||
98 | printf( "\n%s ", name ); | ||
99 | |||
100 | /* Set global error message word */ | ||
101 | merror = code; | ||
102 | |||
103 | /* Display error message defined | ||
104 | * by the code argument. | ||
105 | */ | ||
106 | if( (code <= 0) || (code >= 7) ) | ||
107 | code = 0; | ||
108 | printf( "%s error\n", ermsg[code] ); | ||
109 | |||
110 | /* Return to calling | ||
111 | * program | ||
112 | */ | ||
113 | return( 0 ); | ||
114 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/Makefile b/src/regress/lib/libc/cxa-atexit/Makefile new file mode 100644 index 0000000000..5061ca04ac --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2010/05/10 18:20:31 drahn Exp $ | ||
2 | |||
3 | .include <bsd.own.mk> | ||
4 | |||
5 | |||
6 | .if ${COMPILER_VERSION:L} == "gcc3" || ${COMPILER_VERSION:L} == "gcc4" | ||
7 | SUBDIR+= libgd1 libgd2 test1 | ||
8 | .endif | ||
9 | |||
10 | install: | ||
11 | |||
12 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/Makefile b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile new file mode 100644 index 0000000000..958b726d28 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | LIB=gd1 | ||
4 | SRCS= gd1.C | ||
5 | NOPROFILE=yes | ||
6 | |||
7 | regress: all | ||
8 | |||
9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C new file mode 100644 index 0000000000..b3ecd56d91 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/gd1.C | |||
@@ -0,0 +1,32 @@ | |||
1 | /* $OpenBSD: gd1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | extern int check1; | ||
22 | |||
23 | struct global_destructor_test_obj1 { | ||
24 | inline ~global_destructor_test_obj1() { | ||
25 | check1 = 0; | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | extern "C" void gd_test1() | ||
30 | { | ||
31 | static global_destructor_test_obj1 gdt; | ||
32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version new file mode 100644 index 0000000000..97c9f92d6b --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd1/shlib_version | |||
@@ -0,0 +1,2 @@ | |||
1 | major=0 | ||
2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/Makefile b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile new file mode 100644 index 0000000000..7ca21d8bd2 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | LIB=gd2 | ||
4 | SRCS= gd2.C | ||
5 | NOPROFILE=yes | ||
6 | |||
7 | regress: all | ||
8 | |||
9 | .include <bsd.lib.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C new file mode 100644 index 0000000000..69e7ffb220 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/gd2.C | |||
@@ -0,0 +1,32 @@ | |||
1 | /* $OpenBSD: gd2.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | extern int check2; | ||
22 | |||
23 | struct global_destructor_test_obj2 { | ||
24 | inline ~global_destructor_test_obj2() { | ||
25 | check2 = 0; | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | extern "C" void gd_test2() | ||
30 | { | ||
31 | static global_destructor_test_obj2 gdt; | ||
32 | } | ||
diff --git a/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version new file mode 100644 index 0000000000..97c9f92d6b --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/libgd2/shlib_version | |||
@@ -0,0 +1,2 @@ | |||
1 | major=0 | ||
2 | minor=0 | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/Makefile b/src/regress/lib/libc/cxa-atexit/test1/Makefile new file mode 100644 index 0000000000..533392d144 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/test1/Makefile | |||
@@ -0,0 +1,29 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | .include <bsd.obj.mk> | ||
4 | |||
5 | GD1_DIR=${.CURDIR}/../libgd1 | ||
6 | GD1_OBJDIR!= if [ -d $(GD1_DIR)/${__objdir} ]; then \ | ||
7 | echo "$(GD1_DIR)/${__objdir}"; \ | ||
8 | else \ | ||
9 | echo "$(GD1_DIR)"; \ | ||
10 | fi | ||
11 | |||
12 | GD2_DIR=${.CURDIR}/../libgd2 | ||
13 | GD2_OBJDIR!= if [ -d $(GD2_DIR)/${__objdir} ]; then \ | ||
14 | echo "$(GD2_DIR)/${__objdir}"; \ | ||
15 | else \ | ||
16 | echo "$(GD2_DIR)"; \ | ||
17 | fi | ||
18 | |||
19 | PROG= test1 | ||
20 | |||
21 | SRCS= test1.C | ||
22 | |||
23 | CFLAGS+= -DLIBGD1="\"$(GD1_OBJDIR)/libgd1.so\"" | ||
24 | CFLAGS+= -DLIBGD2="\"$(GD2_OBJDIR)/libgd2.so\"" | ||
25 | LDFLAGS+= -Wl,-E | ||
26 | |||
27 | NOMAN= | ||
28 | |||
29 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/cxa-atexit/test1/test1.C b/src/regress/lib/libc/cxa-atexit/test1/test1.C new file mode 100644 index 0000000000..75fb967a90 --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/test1/test1.C | |||
@@ -0,0 +1,63 @@ | |||
1 | /* $OpenBSD: test1.C,v 1.1 2007/09/03 14:42:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2007 Kurt Miller <kurt@openbsd.org> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <dlfcn.h> | ||
20 | #include <err.h> | ||
21 | #include <stdio.h> | ||
22 | |||
23 | int check1, check2; | ||
24 | |||
25 | int | ||
26 | main() | ||
27 | { | ||
28 | void *libgd1, *libgd2; | ||
29 | void (*gd_test)(); | ||
30 | int i; | ||
31 | |||
32 | for (i=0; i < 50; i++) { | ||
33 | check1 = check2 = 1; | ||
34 | |||
35 | libgd1 = dlopen(LIBGD1, RTLD_LAZY); | ||
36 | if (libgd1 == NULL) | ||
37 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD1); | ||
38 | |||
39 | gd_test = (void (*)())dlsym(libgd1, "gd_test1"); | ||
40 | if (gd_test == NULL) | ||
41 | errx(1, "dlsym(libgd1, \"gd_test1\") FAILED\n"); | ||
42 | |||
43 | (*gd_test)(); | ||
44 | |||
45 | libgd2 = dlopen(LIBGD2, RTLD_LAZY); | ||
46 | if (libgd2 == NULL) | ||
47 | errx(1, "dlopen(%s, RTLD_LAZY) FAILED\n", LIBGD2); | ||
48 | |||
49 | gd_test = (void (*)())dlsym(libgd2, "gd_test2"); | ||
50 | if (gd_test == NULL) | ||
51 | errx(1, "dlsym(libgd2, \"gd_test2\") FAILED\n"); | ||
52 | |||
53 | (*gd_test)(); | ||
54 | |||
55 | dlclose(libgd1); | ||
56 | dlclose(libgd2); | ||
57 | |||
58 | if (check1 || check2) | ||
59 | errx(1, "global destructors not called\n"); | ||
60 | } | ||
61 | |||
62 | return (0); | ||
63 | } | ||
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile index 5bf343bf64..7d2882594d 100644 --- a/src/regress/lib/libc/db/Makefile +++ b/src/regress/lib/libc/db/Makefile | |||
@@ -1,17 +1,22 @@ | |||
1 | # $NetBSD: Makefile,v 1.10 1995/04/20 22:39:11 cgd Exp $ | 1 | # $OpenBSD: Makefile,v 1.10 2002/09/02 20:01:43 avsm Exp $ |
2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | 2 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ |
3 | 3 | ||
4 | PROG= dbtest | 4 | PROG= dbtest |
5 | 5 | ||
6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | 6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that |
7 | # for this to work, libc must be compiled with -DSTATISTICS as well | 7 | # for this to work, libc must be compiled with -DSTATISTICS as well |
8 | CFLAGS= -g -D__DBINTERFACE_PRIVATE -DDEBUG | 8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG |
9 | NOMAN= noman | 9 | CLEANFILES+= t1 t2 t3 log |
10 | CLEANFILES+= t1 t2 t3 | ||
11 | 10 | ||
12 | install: | 11 | DBTARGETS=1 2 3 4 5 6 7 8 9 10 11 12 13 20 |
13 | 12 | ||
14 | regress: | 13 | .for DT in ${DBTARGETS} |
15 | sh ${.CURDIR}/run.test | 14 | db-${DT}: ${PROG} |
15 | sh ${.CURDIR}/run.test ${DT} | ||
16 | REGRESS_TARGETS+=db-${DT} | ||
17 | .PHONY: db-${DT} | ||
18 | .endfor | ||
16 | 19 | ||
17 | .include <bsd.prog.mk> | 20 | REGRESS_SLOW_TARGETS+=db-3 db-12 db-20 |
21 | |||
22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README index 3b290b09d8..23a1b77221 100644 --- a/src/regress/lib/libc/db/README +++ b/src/regress/lib/libc/db/README | |||
@@ -1,5 +1,6 @@ | |||
1 | # $NetBSD: README,v 1.4 1995/04/20 22:39:18 cgd Exp $ | 1 | # $OpenBSD: README,v 1.3 2001/01/29 02:05:40 niklas Exp $ |
2 | # @(#)README 8.4 (Berkeley) 6/20/94 | 2 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ |
3 | # @(#)README 8.8 (Berkeley) 7/31/94 | ||
3 | 4 | ||
4 | To run the tests, enter "make regress". | 5 | To run the tests, enter "make regress". |
5 | 6 | ||
@@ -9,8 +10,11 @@ the test runs, and even larger files (the database files) are created in | |||
9 | variable TMPDIR to a directory where the files can be built. | 10 | variable TMPDIR to a directory where the files can be built. |
10 | 11 | ||
11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | 12 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
12 | The script file consists of lines with a initial character which is | 13 | The script file consists of lines with an initial character which is |
13 | the "command" for that line. Legal characters are as follows: | 14 | the command for that line, or an initial character indicating a key |
15 | or data entry for a previous command. | ||
16 | |||
17 | Legal command characters are as follows: | ||
14 | 18 | ||
15 | c: compare a record | 19 | c: compare a record |
16 | + must be followed by [kK][dD]; the data value in the database | 20 | + must be followed by [kK][dD]; the data value in the database |
@@ -19,17 +23,24 @@ c: compare a record | |||
19 | e: echo a string | 23 | e: echo a string |
20 | + writes out the rest of the line into the output file; if the | 24 | + writes out the rest of the line into the output file; if the |
21 | last character is not a carriage-return, a newline is appended. | 25 | last character is not a carriage-return, a newline is appended. |
26 | f: set the flags for the next command | ||
27 | + no value zero's the flags | ||
22 | g: do a get command | 28 | g: do a get command |
23 | + must be followed by [kK] | 29 | + must be followed by [kK] |
24 | + writes out the retrieved data DBT. | 30 | + writes out the retrieved data DBT. |
31 | o [r]: dump [reverse] | ||
32 | + dump the database out, if 'r' is set, in reverse order. | ||
25 | p: do a put command | 33 | p: do a put command |
26 | + must be followed by [kK][dD] | 34 | + must be followed by [kK][dD] |
27 | r: do a del command | 35 | r: do a del command |
28 | + must be followed by [kK] | 36 | + must be followed by [kK] unless R_CURSOR flag set. |
37 | S: sync the database | ||
29 | s: do a seq command | 38 | s: do a seq command |
39 | + must be followed by [kK] if R_CURSOR flag set. | ||
30 | + writes out the retrieved data DBT. | 40 | + writes out the retrieved data DBT. |
31 | f: set the flags for the next command | 41 | |
32 | + no value zero's the flags | 42 | Legal key/data characters are as follows: |
43 | |||
33 | D [file]: data file | 44 | D [file]: data file |
34 | + set the current data value to the contents of the file | 45 | + set the current data value to the contents of the file |
35 | d [data]: | 46 | d [data]: |
@@ -38,17 +49,21 @@ K [file]: key file | |||
38 | + set the current key value to the contents of the file | 49 | + set the current key value to the contents of the file |
39 | k [data]: | 50 | k [data]: |
40 | + set the current key value to the contents of the line. | 51 | + set the current key value to the contents of the line. |
41 | o [r]: dump [reverse] | 52 | |
42 | + dump the database out, if 'r' is set, in reverse order. | 53 | Blank lines, lines with leading white space, and lines with leading |
54 | hash marks (#) are ignored. | ||
43 | 55 | ||
44 | Options to dbtest are as follows: | 56 | Options to dbtest are as follows: |
45 | 57 | ||
58 | -d: Set the DB_LOCK flag. | ||
46 | -f: Use the file argument as the database file. | 59 | -f: Use the file argument as the database file. |
47 | -i: Use the rest of the argument to set elements in the info | 60 | -i: Use the rest of the argument to set elements in the info |
48 | structure. If the type is btree, then "-i cachesize=10240" | 61 | structure. If the type is btree, then "-i cachesize=10240" |
49 | will set BTREEINFO.cachesize to 10240. | 62 | will set BTREEINFO.cachesize to 10240. |
50 | -o: The rest of the argument is the output file instead of | 63 | -o: The rest of the argument is the output file instead of |
51 | using stdout. | 64 | using stdout. |
65 | -s: Don't delete the database file before opening it, i.e. | ||
66 | use the database file from a previous run. | ||
52 | 67 | ||
53 | Dbtest requires two arguments, the type of access "hash", "recno" or | 68 | Dbtest requires two arguments, the type of access "hash", "recno" |
54 | "btree", and the script name. | 69 | or "btree", and the script name or "-" to indicate stdin. |
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c index 1fcf09af97..c28ec0db5e 100644 --- a/src/regress/lib/libc/db/dbtest.c +++ b/src/regress/lib/libc/db/dbtest.c | |||
@@ -1,7 +1,8 @@ | |||
1 | /* $NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $ */ | 1 | /* $OpenBSD: dbtest.c,v 1.12 2009/10/27 23:59:32 deraadt Exp $ */ |
2 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | ||
2 | 3 | ||
3 | /*- | 4 | /*- |
4 | * Copyright (c) 1992, 1993 | 5 | * Copyright (c) 1992, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | 6 | * The Regents of the University of California. All rights reserved. |
6 | * | 7 | * |
7 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -12,11 +13,7 @@ | |||
12 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. |
15 | * 3. All advertising materials mentioning features or use of this software | 16 | * 3. Neither the name of the University nor the names of its contributors |
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by the University of | ||
18 | * California, Berkeley and its contributors. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | 17 | * may be used to endorse or promote products derived from this software |
21 | * without specific prior written permission. | 18 | * without specific prior written permission. |
22 | * | 19 | * |
@@ -33,20 +30,6 @@ | |||
33 | * SUCH DAMAGE. | 30 | * SUCH DAMAGE. |
34 | */ | 31 | */ |
35 | 32 | ||
36 | #ifndef lint | ||
37 | static char copyright[] = | ||
38 | "@(#) Copyright (c) 1992, 1993\n\ | ||
39 | The Regents of the University of California. All rights reserved.\n"; | ||
40 | #endif /* not lint */ | ||
41 | |||
42 | #ifndef lint | ||
43 | #if 0 | ||
44 | static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; | ||
45 | #else | ||
46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | ||
47 | #endif | ||
48 | #endif /* not lint */ | ||
49 | |||
50 | #include <sys/param.h> | 33 | #include <sys/param.h> |
51 | #include <sys/stat.h> | 34 | #include <sys/stat.h> |
52 | 35 | ||
@@ -57,39 +40,41 @@ static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | |||
57 | #include <stdio.h> | 40 | #include <stdio.h> |
58 | #include <stdlib.h> | 41 | #include <stdlib.h> |
59 | #include <string.h> | 42 | #include <string.h> |
43 | #include <stdarg.h> | ||
60 | #include <unistd.h> | 44 | #include <unistd.h> |
61 | 45 | ||
62 | #include <db.h> | 46 | #include <db.h> |
63 | 47 | ||
64 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | 48 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; |
65 | 49 | ||
66 | void compare __P((DBT *, DBT *)); | 50 | void compare(DBT *, DBT *); |
67 | DBTYPE dbtype __P((char *)); | 51 | DBTYPE dbtype(char *); |
68 | void dump __P((DB *, int)); | 52 | void dump(DB *, int); |
69 | void err __P((const char *, ...)); | 53 | void dberr(const char *, ...); |
70 | void get __P((DB *, DBT *)); | 54 | void get(DB *, DBT *); |
71 | void getdata __P((DB *, DBT *, DBT *)); | 55 | void getdata(DB *, DBT *, DBT *); |
72 | void put __P((DB *, DBT *, DBT *)); | 56 | void put(DB *, DBT *, DBT *); |
73 | void rem __P((DB *, DBT *)); | 57 | void rem(DB *, DBT *); |
74 | void *rfile __P((char *, size_t *)); | 58 | char *sflags(int); |
75 | void seq __P((DB *, DBT *)); | 59 | void synk(DB *); |
76 | u_int setflags __P((char *)); | 60 | void *rfile(char *, size_t *); |
77 | void *setinfo __P((DBTYPE, char *)); | 61 | void seq(DB *, DBT *); |
78 | void usage __P((void)); | 62 | u_int setflags(char *); |
79 | void *xmalloc __P((char *, size_t)); | 63 | void *setinfo(DBTYPE, char *); |
80 | 64 | void usage(void); | |
81 | DBTYPE type; | 65 | void *xmalloc(char *, size_t); |
82 | void *infop; | 66 | |
83 | u_long lineno; | 67 | DBTYPE type; /* Database type. */ |
84 | u_int flags; | 68 | void *infop; /* Iflags. */ |
85 | int ofd = STDOUT_FILENO; | 69 | u_long lineno; /* Current line in test script. */ |
70 | u_int flags; /* Current DB flags. */ | ||
71 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
86 | 72 | ||
87 | DB *XXdbp; /* Global for gdb. */ | 73 | DB *XXdbp; /* Global for gdb. */ |
74 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
88 | 75 | ||
89 | int | 76 | int |
90 | main(argc, argv) | 77 | main(int argc, char *argv[]) |
91 | int argc; | ||
92 | char *argv[]; | ||
93 | { | 78 | { |
94 | extern int optind; | 79 | extern int optind; |
95 | extern char *optarg; | 80 | extern char *optarg; |
@@ -97,14 +82,15 @@ main(argc, argv) | |||
97 | DB *dbp; | 82 | DB *dbp; |
98 | DBT data, key, keydata; | 83 | DBT data, key, keydata; |
99 | size_t len; | 84 | size_t len; |
100 | int ch, oflags; | 85 | int ch, oflags, sflag; |
101 | char *fname, *infoarg, *p, buf[8 * 1024]; | 86 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; |
102 | 87 | ||
103 | infoarg = NULL; | 88 | infoarg = NULL; |
104 | fname = NULL; | 89 | fname = NULL; |
105 | oflags = O_CREAT | O_RDWR; | 90 | oflags = O_CREAT | O_RDWR; |
106 | while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) | 91 | sflag = 0; |
107 | switch(ch) { | 92 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) |
93 | switch (ch) { | ||
108 | case 'f': | 94 | case 'f': |
109 | fname = optarg; | 95 | fname = optarg; |
110 | break; | 96 | break; |
@@ -117,7 +103,10 @@ main(argc, argv) | |||
117 | case 'o': | 103 | case 'o': |
118 | if ((ofd = open(optarg, | 104 | if ((ofd = open(optarg, |
119 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 105 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
120 | err("%s: %s", optarg, strerror(errno)); | 106 | dberr("%s: %s", optarg, strerror(errno)); |
107 | break; | ||
108 | case 's': | ||
109 | sflag = 1; | ||
121 | break; | 110 | break; |
122 | case '?': | 111 | case '?': |
123 | default: | 112 | default: |
@@ -133,8 +122,8 @@ main(argc, argv) | |||
133 | type = dbtype(*argv++); | 122 | type = dbtype(*argv++); |
134 | 123 | ||
135 | /* Open the descriptor file. */ | 124 | /* Open the descriptor file. */ |
136 | if (freopen(*argv, "r", stdin) == NULL) | 125 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) |
137 | err("%s: %s", *argv, strerror(errno)); | 126 | dberr("%s: %s", *argv, strerror(errno)); |
138 | 127 | ||
139 | /* Set up the db structure as necessary. */ | 128 | /* Set up the db structure as necessary. */ |
140 | if (infoarg == NULL) | 129 | if (infoarg == NULL) |
@@ -145,61 +134,93 @@ main(argc, argv) | |||
145 | if (*p != '\0') | 134 | if (*p != '\0') |
146 | infop = setinfo(type, p); | 135 | infop = setinfo(type, p); |
147 | 136 | ||
148 | /* Open the DB. */ | 137 | /* |
138 | * Open the DB. Delete any preexisting copy, you almost never | ||
139 | * want it around, and it often screws up tests. | ||
140 | */ | ||
149 | if (fname == NULL) { | 141 | if (fname == NULL) { |
150 | p = getenv("TMPDIR"); | 142 | p = getenv("TMPDIR"); |
151 | if (p == NULL) | 143 | if (p == NULL) |
152 | p = "/var/tmp"; | 144 | p = "/var/tmp"; |
153 | (void)sprintf(buf, "%s/__dbtest", p); | 145 | (void)snprintf(buf, sizeof buf, "%s/__dbtest", p); |
154 | fname = buf; | 146 | fname = buf; |
155 | (void)unlink(buf); | 147 | (void)unlink(buf); |
156 | } | 148 | } else if (!sflag) |
149 | (void)unlink(fname); | ||
150 | |||
157 | if ((dbp = dbopen(fname, | 151 | if ((dbp = dbopen(fname, |
158 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | 152 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) |
159 | err("dbopen: %s", strerror(errno)); | 153 | dberr("dbopen: %s", strerror(errno)); |
160 | XXdbp = dbp; | 154 | XXdbp = dbp; |
161 | 155 | ||
162 | state = COMMAND; | 156 | state = COMMAND; |
163 | for (lineno = 1; | 157 | for (lineno = 1; |
164 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | 158 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { |
165 | len = strlen(buf); | 159 | /* Delete the newline, displaying the key/data is easier. */ |
166 | switch(*p) { | 160 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) |
161 | *t = '\0'; | ||
162 | if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') | ||
163 | continue; | ||
164 | |||
165 | /* Convenient gdb break point. */ | ||
166 | if (XXlineno == lineno) | ||
167 | XXlineno = 1; | ||
168 | switch (*p) { | ||
167 | case 'c': /* compare */ | 169 | case 'c': /* compare */ |
168 | if (state != COMMAND) | 170 | if (state != COMMAND) |
169 | err("line %lu: not expecting command", lineno); | 171 | dberr("line %lu: not expecting command", |
172 | lineno); | ||
170 | state = KEY; | 173 | state = KEY; |
171 | command = COMPARE; | 174 | command = COMPARE; |
172 | break; | 175 | break; |
173 | case 'e': /* echo */ | 176 | case 'e': /* echo */ |
174 | if (state != COMMAND) | 177 | if (state != COMMAND) |
175 | err("line %lu: not expecting command", lineno); | 178 | dberr("line %lu: not expecting command", |
179 | lineno); | ||
176 | /* Don't display the newline, if CR at EOL. */ | 180 | /* Don't display the newline, if CR at EOL. */ |
177 | if (p[len - 2] == '\r') | 181 | if (p[len - 2] == '\r') |
178 | --len; | 182 | --len; |
179 | if (write(ofd, p + 1, len - 1) != len - 1) | 183 | if (write(ofd, p + 1, len - 1) != len - 1 || |
180 | err("write: %s", strerror(errno)); | 184 | write(ofd, "\n", 1) != 1) |
185 | dberr("write: %s", strerror(errno)); | ||
181 | break; | 186 | break; |
182 | case 'g': /* get */ | 187 | case 'g': /* get */ |
183 | if (state != COMMAND) | 188 | if (state != COMMAND) |
184 | err("line %lu: not expecting command", lineno); | 189 | dberr("line %lu: not expecting command", |
190 | lineno); | ||
185 | state = KEY; | 191 | state = KEY; |
186 | command = GET; | 192 | command = GET; |
187 | break; | 193 | break; |
188 | case 'p': /* put */ | 194 | case 'p': /* put */ |
189 | if (state != COMMAND) | 195 | if (state != COMMAND) |
190 | err("line %lu: not expecting command", lineno); | 196 | dberr("line %lu: not expecting command", |
197 | lineno); | ||
191 | state = KEY; | 198 | state = KEY; |
192 | command = PUT; | 199 | command = PUT; |
193 | break; | 200 | break; |
194 | case 'r': /* remove */ | 201 | case 'r': /* remove */ |
195 | if (state != COMMAND) | 202 | if (state != COMMAND) |
196 | err("line %lu: not expecting command", lineno); | 203 | dberr("line %lu: not expecting command", |
197 | state = KEY; | 204 | lineno); |
198 | command = REMOVE; | 205 | if (flags == R_CURSOR) { |
206 | rem(dbp, &key); | ||
207 | state = COMMAND; | ||
208 | } else { | ||
209 | state = KEY; | ||
210 | command = REMOVE; | ||
211 | } | ||
212 | break; | ||
213 | case 'S': /* sync */ | ||
214 | if (state != COMMAND) | ||
215 | dberr("line %lu: not expecting command", | ||
216 | lineno); | ||
217 | synk(dbp); | ||
218 | state = COMMAND; | ||
199 | break; | 219 | break; |
200 | case 's': /* seq */ | 220 | case 's': /* seq */ |
201 | if (state != COMMAND) | 221 | if (state != COMMAND) |
202 | err("line %lu: not expecting command", lineno); | 222 | dberr("line %lu: not expecting command", |
223 | lineno); | ||
203 | if (flags == R_CURSOR) { | 224 | if (flags == R_CURSOR) { |
204 | state = KEY; | 225 | state = KEY; |
205 | command = SEQ; | 226 | command = SEQ; |
@@ -211,15 +232,15 @@ main(argc, argv) | |||
211 | break; | 232 | break; |
212 | case 'D': /* data file */ | 233 | case 'D': /* data file */ |
213 | if (state != DATA) | 234 | if (state != DATA) |
214 | err("line %lu: not expecting data", lineno); | 235 | dberr("line %lu: not expecting data", lineno); |
215 | data.data = rfile(p + 1, &data.size); | 236 | data.data = rfile(p + 1, &data.size); |
216 | goto ldata; | 237 | goto ldata; |
217 | case 'd': /* data */ | 238 | case 'd': /* data */ |
218 | if (state != DATA) | 239 | if (state != DATA) |
219 | err("line %lu: not expecting data", lineno); | 240 | dberr("line %lu: not expecting data", lineno); |
220 | data.data = xmalloc(p + 1, len - 1); | 241 | data.data = xmalloc(p + 1, len - 1); |
221 | data.size = len - 1; | 242 | data.size = len - 1; |
222 | ldata: switch(command) { | 243 | ldata: switch (command) { |
223 | case COMPARE: | 244 | case COMPARE: |
224 | compare(&keydata, &data); | 245 | compare(&keydata, &data); |
225 | break; | 246 | break; |
@@ -227,7 +248,7 @@ ldata: switch(command) { | |||
227 | put(dbp, &key, &data); | 248 | put(dbp, &key, &data); |
228 | break; | 249 | break; |
229 | default: | 250 | default: |
230 | err("line %lu: command doesn't take data", | 251 | dberr("line %lu: command doesn't take data", |
231 | lineno); | 252 | lineno); |
232 | } | 253 | } |
233 | if (type != DB_RECNO) | 254 | if (type != DB_RECNO) |
@@ -237,15 +258,15 @@ ldata: switch(command) { | |||
237 | break; | 258 | break; |
238 | case 'K': /* key file */ | 259 | case 'K': /* key file */ |
239 | if (state != KEY) | 260 | if (state != KEY) |
240 | err("line %lu: not expecting a key", lineno); | 261 | dberr("line %lu: not expecting a key", lineno); |
241 | if (type == DB_RECNO) | 262 | if (type == DB_RECNO) |
242 | err("line %lu: 'K' not available for recno", | 263 | dberr("line %lu: 'K' not available for recno", |
243 | lineno); | 264 | lineno); |
244 | key.data = rfile(p + 1, &key.size); | 265 | key.data = rfile(p + 1, &key.size); |
245 | goto lkey; | 266 | goto lkey; |
246 | case 'k': /* key */ | 267 | case 'k': /* key */ |
247 | if (state != KEY) | 268 | if (state != KEY) |
248 | err("line %lu: not expecting a key", lineno); | 269 | dberr("line %lu: not expecting a key", lineno); |
249 | if (type == DB_RECNO) { | 270 | if (type == DB_RECNO) { |
250 | static recno_t recno; | 271 | static recno_t recno; |
251 | recno = atoi(p + 1); | 272 | recno = atoi(p + 1); |
@@ -255,7 +276,7 @@ ldata: switch(command) { | |||
255 | key.data = xmalloc(p + 1, len - 1); | 276 | key.data = xmalloc(p + 1, len - 1); |
256 | key.size = len - 1; | 277 | key.size = len - 1; |
257 | } | 278 | } |
258 | lkey: switch(command) { | 279 | lkey: switch (command) { |
259 | case COMPARE: | 280 | case COMPARE: |
260 | getdata(dbp, &key, &keydata); | 281 | getdata(dbp, &key, &keydata); |
261 | state = DATA; | 282 | state = DATA; |
@@ -271,18 +292,18 @@ lkey: switch(command) { | |||
271 | break; | 292 | break; |
272 | case REMOVE: | 293 | case REMOVE: |
273 | rem(dbp, &key); | 294 | rem(dbp, &key); |
274 | if (type != DB_RECNO) | 295 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
275 | free(key.data); | 296 | free(key.data); |
276 | state = COMMAND; | 297 | state = COMMAND; |
277 | break; | 298 | break; |
278 | case SEQ: | 299 | case SEQ: |
279 | seq(dbp, &key); | 300 | seq(dbp, &key); |
280 | if (type != DB_RECNO) | 301 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
281 | free(key.data); | 302 | free(key.data); |
282 | state = COMMAND; | 303 | state = COMMAND; |
283 | break; | 304 | break; |
284 | default: | 305 | default: |
285 | err("line %lu: command doesn't take a key", | 306 | dberr("line %lu: command doesn't take a key", |
286 | lineno); | 307 | lineno); |
287 | } | 308 | } |
288 | break; | 309 | break; |
@@ -290,22 +311,25 @@ lkey: switch(command) { | |||
290 | dump(dbp, p[1] == 'r'); | 311 | dump(dbp, p[1] == 'r'); |
291 | break; | 312 | break; |
292 | default: | 313 | default: |
293 | err("line %lu: %s: unknown command character", | 314 | dberr("line %lu: %s: unknown command character", |
294 | p, lineno); | 315 | lineno, p); |
295 | } | 316 | } |
296 | } | 317 | } |
297 | #ifdef STATISTICS | 318 | #ifdef STATISTICS |
298 | if (type == DB_BTREE) | 319 | /* |
320 | * -l must be used (DB_LOCK must be set) for this to be | ||
321 | * used, otherwise a page will be locked and it will fail. | ||
322 | */ | ||
323 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
299 | __bt_stat(dbp); | 324 | __bt_stat(dbp); |
300 | #endif | 325 | #endif |
301 | if (dbp->close(dbp)) | 326 | if (dbp->close(dbp)) |
302 | err("db->close: %s", strerror(errno)); | 327 | dberr("db->close: %s", strerror(errno)); |
303 | (void)close(ofd); | 328 | (void)close(ofd); |
304 | exit(0); | 329 | exit(0); |
305 | } | 330 | } |
306 | 331 | ||
307 | #define NOOVERWRITE "put failed, would overwrite key\n" | 332 | #define NOOVERWRITE "put failed, would overwrite key\n" |
308 | #define NOSUCHKEY "get failed, no such key\n" | ||
309 | 333 | ||
310 | void | 334 | void |
311 | compare(db1, db2) | 335 | compare(db1, db2) |
@@ -334,17 +358,23 @@ get(dbp, kp) | |||
334 | { | 358 | { |
335 | DBT data; | 359 | DBT data; |
336 | 360 | ||
337 | switch(dbp->get(dbp, kp, &data, flags)) { | 361 | switch (dbp->get(dbp, kp, &data, flags)) { |
338 | case 0: | 362 | case 0: |
339 | (void)write(ofd, data.data, data.size); | 363 | (void)write(ofd, data.data, data.size); |
364 | if (ofd == STDOUT_FILENO) | ||
365 | (void)write(ofd, "\n", 1); | ||
340 | break; | 366 | break; |
341 | case -1: | 367 | case -1: |
342 | err("line %lu: get: %s", lineno, strerror(errno)); | 368 | dberr("line %lu: get: %s", lineno, strerror(errno)); |
343 | /* NOTREACHED */ | 369 | /* NOTREACHED */ |
344 | case 1: | 370 | case 1: |
345 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 371 | #define NOSUCHKEY "get failed, no such key\n" |
346 | (void)fprintf(stderr, "%d: %.*s: %s\n", | 372 | if (ofd != STDOUT_FILENO) |
347 | lineno, kp->size, kp->data, NOSUCHKEY); | 373 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); |
374 | else | ||
375 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
376 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
377 | #undef NOSUCHKEY | ||
348 | break; | 378 | break; |
349 | } | 379 | } |
350 | } | 380 | } |
@@ -354,14 +384,14 @@ getdata(dbp, kp, dp) | |||
354 | DB *dbp; | 384 | DB *dbp; |
355 | DBT *kp, *dp; | 385 | DBT *kp, *dp; |
356 | { | 386 | { |
357 | switch(dbp->get(dbp, kp, dp, flags)) { | 387 | switch (dbp->get(dbp, kp, dp, flags)) { |
358 | case 0: | 388 | case 0: |
359 | return; | 389 | return; |
360 | case -1: | 390 | case -1: |
361 | err("line %lu: getdata: %s", lineno, strerror(errno)); | 391 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); |
362 | /* NOTREACHED */ | 392 | /* NOTREACHED */ |
363 | case 1: | 393 | case 1: |
364 | err("line %lu: get failed, no such key", lineno); | 394 | dberr("line %lu: getdata failed, no such key", lineno); |
365 | /* NOTREACHED */ | 395 | /* NOTREACHED */ |
366 | } | 396 | } |
367 | } | 397 | } |
@@ -371,11 +401,11 @@ put(dbp, kp, dp) | |||
371 | DB *dbp; | 401 | DB *dbp; |
372 | DBT *kp, *dp; | 402 | DBT *kp, *dp; |
373 | { | 403 | { |
374 | switch(dbp->put(dbp, kp, dp, flags)) { | 404 | switch (dbp->put(dbp, kp, dp, flags)) { |
375 | case 0: | 405 | case 0: |
376 | break; | 406 | break; |
377 | case -1: | 407 | case -1: |
378 | err("line %lu: put: %s", lineno, strerror(errno)); | 408 | dberr("line %lu: put: %s", lineno, strerror(errno)); |
379 | /* NOTREACHED */ | 409 | /* NOTREACHED */ |
380 | case 1: | 410 | case 1: |
381 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | 411 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); |
@@ -388,15 +418,37 @@ rem(dbp, kp) | |||
388 | DB *dbp; | 418 | DB *dbp; |
389 | DBT *kp; | 419 | DBT *kp; |
390 | { | 420 | { |
391 | switch(dbp->del(dbp, kp, flags)) { | 421 | switch (dbp->del(dbp, kp, flags)) { |
392 | case 0: | 422 | case 0: |
393 | break; | 423 | break; |
394 | case -1: | 424 | case -1: |
395 | err("line %lu: get: %s", lineno, strerror(errno)); | 425 | dberr("line %lu: rem: %s", lineno, strerror(errno)); |
396 | /* NOTREACHED */ | 426 | /* NOTREACHED */ |
397 | case 1: | 427 | case 1: |
398 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 428 | #define NOSUCHKEY "rem failed, no such key\n" |
429 | if (ofd != STDOUT_FILENO) | ||
430 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
431 | else if (flags != R_CURSOR) | ||
432 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
433 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
434 | else | ||
435 | (void)fprintf(stderr, | ||
436 | "%d: rem of cursor failed\n", lineno); | ||
437 | #undef NOSUCHKEY | ||
438 | break; | ||
439 | } | ||
440 | } | ||
441 | |||
442 | void | ||
443 | synk(dbp) | ||
444 | DB *dbp; | ||
445 | { | ||
446 | switch (dbp->sync(dbp, flags)) { | ||
447 | case 0: | ||
399 | break; | 448 | break; |
449 | case -1: | ||
450 | dberr("line %lu: synk: %s", lineno, strerror(errno)); | ||
451 | /* NOTREACHED */ | ||
400 | } | 452 | } |
401 | } | 453 | } |
402 | 454 | ||
@@ -407,15 +459,26 @@ seq(dbp, kp) | |||
407 | { | 459 | { |
408 | DBT data; | 460 | DBT data; |
409 | 461 | ||
410 | switch(dbp->seq(dbp, kp, &data, flags)) { | 462 | switch (dbp->seq(dbp, kp, &data, flags)) { |
411 | case 0: | 463 | case 0: |
412 | (void)write(ofd, data.data, data.size); | 464 | (void)write(ofd, data.data, data.size); |
465 | if (ofd == STDOUT_FILENO) | ||
466 | (void)write(ofd, "\n", 1); | ||
413 | break; | 467 | break; |
414 | case -1: | 468 | case -1: |
415 | err("line %lu: seq: %s", lineno, strerror(errno)); | 469 | dberr("line %lu: seq: %s", lineno, strerror(errno)); |
416 | /* NOTREACHED */ | 470 | /* NOTREACHED */ |
417 | case 1: | 471 | case 1: |
418 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 472 | #define NOSUCHKEY "seq failed, no such key\n" |
473 | if (ofd != STDOUT_FILENO) | ||
474 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
475 | else if (flags == R_CURSOR) | ||
476 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
477 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
478 | else | ||
479 | (void)fprintf(stderr, | ||
480 | "%d: seq (%s) failed\n", lineno, sflags(flags)); | ||
481 | #undef NOSUCHKEY | ||
419 | break; | 482 | break; |
420 | } | 483 | } |
421 | } | 484 | } |
@@ -436,14 +499,16 @@ dump(dbp, rev) | |||
436 | nflags = R_NEXT; | 499 | nflags = R_NEXT; |
437 | } | 500 | } |
438 | for (;; flags = nflags) | 501 | for (;; flags = nflags) |
439 | switch(dbp->seq(dbp, &key, &data, flags)) { | 502 | switch (dbp->seq(dbp, &key, &data, flags)) { |
440 | case 0: | 503 | case 0: |
441 | (void)write(ofd, data.data, data.size); | 504 | (void)write(ofd, data.data, data.size); |
505 | if (ofd == STDOUT_FILENO) | ||
506 | (void)write(ofd, "\n", 1); | ||
442 | break; | 507 | break; |
443 | case 1: | 508 | case 1: |
444 | goto done; | 509 | goto done; |
445 | case -1: | 510 | case -1: |
446 | err("line %lu: (dump) seq: %s", | 511 | dberr("line %lu: (dump) seq: %s", |
447 | lineno, strerror(errno)); | 512 | lineno, strerror(errno)); |
448 | /* NOTREACHED */ | 513 | /* NOTREACHED */ |
449 | } | 514 | } |
@@ -454,34 +519,45 @@ u_int | |||
454 | setflags(s) | 519 | setflags(s) |
455 | char *s; | 520 | char *s; |
456 | { | 521 | { |
457 | char *p, *index(); | 522 | char *p; |
458 | 523 | ||
459 | for (; isspace(*s); ++s); | 524 | for (; isspace(*s); ++s); |
460 | if (*s == '\n') | 525 | if (*s == '\n' || *s == '\0') |
461 | return (0); | 526 | return (0); |
462 | if ((p = index(s, '\n')) != NULL) | 527 | if ((p = strchr(s, '\n')) != NULL) |
463 | *p = '\0'; | 528 | *p = '\0'; |
464 | if (!strcmp(s, "R_CURSOR")) | 529 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); |
465 | return (R_CURSOR); | 530 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); |
466 | if (!strcmp(s, "R_FIRST")) | 531 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); |
467 | return (R_FIRST); | 532 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); |
468 | if (!strcmp(s, "R_IAFTER")) | 533 | if (!strcmp(s, "R_LAST")) return (R_LAST); |
469 | return (R_IAFTER); | 534 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); |
470 | if (!strcmp(s, "R_IBEFORE")) | 535 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); |
471 | return (R_IBEFORE); | 536 | if (!strcmp(s, "R_PREV")) return (R_PREV); |
472 | if (!strcmp(s, "R_LAST")) | 537 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); |
473 | return (R_LAST); | 538 | |
474 | if (!strcmp(s, "R_NEXT")) | 539 | dberr("line %lu: %s: unknown flag", lineno, s); |
475 | return (R_NEXT); | ||
476 | if (!strcmp(s, "R_NOOVERWRITE")) | ||
477 | return (R_NOOVERWRITE); | ||
478 | if (!strcmp(s, "R_PREV")) | ||
479 | return (R_PREV); | ||
480 | if (!strcmp(s, "R_SETCURSOR")) | ||
481 | return (R_SETCURSOR); | ||
482 | err("line %lu: %s: unknown flag", lineno, s); | ||
483 | /* NOTREACHED */ | 540 | /* NOTREACHED */ |
484 | } | 541 | } |
542 | |||
543 | char * | ||
544 | sflags(flags) | ||
545 | int flags; | ||
546 | { | ||
547 | switch (flags) { | ||
548 | case R_CURSOR: return ("R_CURSOR"); | ||
549 | case R_FIRST: return ("R_FIRST"); | ||
550 | case R_IAFTER: return ("R_IAFTER"); | ||
551 | case R_IBEFORE: return ("R_IBEFORE"); | ||
552 | case R_LAST: return ("R_LAST"); | ||
553 | case R_NEXT: return ("R_NEXT"); | ||
554 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
555 | case R_PREV: return ("R_PREV"); | ||
556 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
557 | } | ||
558 | |||
559 | return ("UNKNOWN!"); | ||
560 | } | ||
485 | 561 | ||
486 | DBTYPE | 562 | DBTYPE |
487 | dbtype(s) | 563 | dbtype(s) |
@@ -493,7 +569,7 @@ dbtype(s) | |||
493 | return (DB_HASH); | 569 | return (DB_HASH); |
494 | if (!strcmp(s, "recno")) | 570 | if (!strcmp(s, "recno")) |
495 | return (DB_RECNO); | 571 | return (DB_RECNO); |
496 | err("%s: unknown type (use btree, hash or recno)", s); | 572 | dberr("%s: unknown type (use btree, hash or recno)", s); |
497 | /* NOTREACHED */ | 573 | /* NOTREACHED */ |
498 | } | 574 | } |
499 | 575 | ||
@@ -505,15 +581,15 @@ setinfo(type, s) | |||
505 | static BTREEINFO ib; | 581 | static BTREEINFO ib; |
506 | static HASHINFO ih; | 582 | static HASHINFO ih; |
507 | static RECNOINFO rh; | 583 | static RECNOINFO rh; |
508 | char *eq, *index(); | 584 | char *eq; |
509 | 585 | ||
510 | if ((eq = index(s, '=')) == NULL) | 586 | if ((eq = strchr(s, '=')) == NULL) |
511 | err("%s: illegal structure set statement", s); | 587 | dberr("%s: illegal structure set statement", s); |
512 | *eq++ = '\0'; | 588 | *eq++ = '\0'; |
513 | if (!isdigit(*eq)) | 589 | if (!isdigit(*eq)) |
514 | err("%s: structure set statement must be a number", s); | 590 | dberr("%s: structure set statement must be a number", s); |
515 | 591 | ||
516 | switch(type) { | 592 | switch (type) { |
517 | case DB_BTREE: | 593 | case DB_BTREE: |
518 | if (!strcmp("flags", s)) { | 594 | if (!strcmp("flags", s)) { |
519 | ib.flags = atoi(eq); | 595 | ib.flags = atoi(eq); |
@@ -589,7 +665,7 @@ setinfo(type, s) | |||
589 | } | 665 | } |
590 | break; | 666 | break; |
591 | } | 667 | } |
592 | err("%s: unknown structure value", s); | 668 | dberr("%s: unknown structure value", s); |
593 | /* NOTREACHED */ | 669 | /* NOTREACHED */ |
594 | } | 670 | } |
595 | 671 | ||
@@ -601,20 +677,20 @@ rfile(name, lenp) | |||
601 | struct stat sb; | 677 | struct stat sb; |
602 | void *p; | 678 | void *p; |
603 | int fd; | 679 | int fd; |
604 | char *np, *index(); | 680 | char *np; |
605 | 681 | ||
606 | for (; isspace(*name); ++name); | 682 | for (; isspace(*name); ++name); |
607 | if ((np = index(name, '\n')) != NULL) | 683 | if ((np = strchr(name, '\n')) != NULL) |
608 | *np = '\0'; | 684 | *np = '\0'; |
609 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | 685 | if ((fd = open(name, O_RDONLY, 0)) < 0 || |
610 | fstat(fd, &sb)) | 686 | fstat(fd, &sb)) |
611 | err("%s: %s\n", name, strerror(errno)); | 687 | dberr("%s: %s\n", name, strerror(errno)); |
612 | #ifdef NOT_PORTABLE | 688 | #ifdef NOT_PORTABLE |
613 | if (sb.st_size > (off_t)SIZE_T_MAX) | 689 | if (sb.st_size > (off_t)SIZE_T_MAX) |
614 | err("%s: %s\n", name, strerror(E2BIG)); | 690 | dberr("%s: %s\n", name, strerror(E2BIG)); |
615 | #endif | 691 | #endif |
616 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | 692 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) |
617 | err("%s", strerror(errno)); | 693 | dberr("%s", strerror(errno)); |
618 | (void)read(fd, p, (int)sb.st_size); | 694 | (void)read(fd, p, (int)sb.st_size); |
619 | *lenp = sb.st_size; | 695 | *lenp = sb.st_size; |
620 | (void)close(fd); | 696 | (void)close(fd); |
@@ -629,7 +705,7 @@ xmalloc(text, len) | |||
629 | void *p; | 705 | void *p; |
630 | 706 | ||
631 | if ((p = (void *)malloc(len)) == NULL) | 707 | if ((p = (void *)malloc(len)) == NULL) |
632 | err("%s", strerror(errno)); | 708 | dberr("%s", strerror(errno)); |
633 | memmove(p, text, len); | 709 | memmove(p, text, len); |
634 | return (p); | 710 | return (p); |
635 | } | 711 | } |
@@ -642,27 +718,12 @@ usage() | |||
642 | exit(1); | 718 | exit(1); |
643 | } | 719 | } |
644 | 720 | ||
645 | #if __STDC__ | ||
646 | #include <stdarg.h> | ||
647 | #else | ||
648 | #include <varargs.h> | ||
649 | #endif | ||
650 | |||
651 | void | 721 | void |
652 | #if __STDC__ | 722 | dberr(const char *fmt, ...) |
653 | err(const char *fmt, ...) | ||
654 | #else | ||
655 | err(fmt, va_alist) | ||
656 | char *fmt; | ||
657 | va_dcl | ||
658 | #endif | ||
659 | { | 723 | { |
660 | va_list ap; | 724 | va_list ap; |
661 | #if __STDC__ | 725 | |
662 | va_start(ap, fmt); | 726 | va_start(ap, fmt); |
663 | #else | ||
664 | va_start(ap); | ||
665 | #endif | ||
666 | (void)fprintf(stderr, "dbtest: "); | 727 | (void)fprintf(stderr, "dbtest: "); |
667 | (void)vfprintf(stderr, fmt, ap); | 728 | (void)vfprintf(stderr, fmt, ap); |
668 | va_end(ap); | 729 | va_end(ap); |
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test index 4073310a31..0d6837e360 100644 --- a/src/regress/lib/libc/db/run.test +++ b/src/regress/lib/libc/db/run.test | |||
@@ -1,19 +1,28 @@ | |||
1 | #!/bin/sh - | 1 | #!/bin/sh - |
2 | # $NetBSD: run.test,v 1.7 1995/04/20 22:39:27 cgd Exp $ | ||
3 | # | 2 | # |
4 | # @(#)run.test 8.8 (Berkeley) 6/16/94 | 3 | # $OpenBSD: run.test,v 1.3 2001/01/29 02:05:41 niklas Exp $ |
4 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ | ||
5 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
5 | # | 6 | # |
6 | 7 | ||
7 | # db regression tests | 8 | # db regression tests |
8 | main() | 9 | main() |
9 | { | 10 | { |
10 | 11 | ||
11 | DICT=/usr/share/dict/web2 | 12 | PROG=./dbtest |
12 | PROG=./dbtest | 13 | TMP1=t1 |
13 | TMP1=t1 | 14 | TMP2=t2 |
14 | TMP2=t2 | 15 | TMP3=t3 |
15 | TMP3=t3 | ||
16 | 16 | ||
17 | if [ -f /usr/share/dict/words ]; then | ||
18 | DICT=/usr/share/dict/words | ||
19 | elif [ -f /usr/dict/words ]; then | ||
20 | DICT=/usr/dict/words | ||
21 | else | ||
22 | echo 'run.test: no dictionary' | ||
23 | exit 1 | ||
24 | fi | ||
25 | |||
17 | if [ $# -eq 0 ]; then | 26 | if [ $# -eq 0 ]; then |
18 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | 27 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do |
19 | test$t | 28 | test$t |
@@ -345,7 +354,7 @@ test7() | |||
345 | for (i = 1; i <= 120; ++i) | 354 | for (i = 1; i <= 120; ++i) |
346 | printf("%05d: input key %d: %s\n", i, i, $0); | 355 | printf("%05d: input key %d: %s\n", i, i, $0); |
347 | printf("%05d: input key %d: %s\n", 120, 120, $0); | 356 | printf("%05d: input key %d: %s\n", 120, 120, $0); |
348 | printf("get failed, no such key\n"); | 357 | printf("seq failed, no such key\n"); |
349 | printf("%05d: input key %d: %s\n", 1, 1, $0); | 358 | printf("%05d: input key %d: %s\n", 1, 1, $0); |
350 | printf("%05d: input key %d: %s\n", 2, 2, $0); | 359 | printf("%05d: input key %d: %s\n", 2, 2, $0); |
351 | exit; | 360 | exit; |
@@ -364,10 +373,10 @@ test7() | |||
364 | for (i = 1; i <= 120; ++i) | 373 | for (i = 1; i <= 120; ++i) |
365 | printf("s\n"); | 374 | printf("s\n"); |
366 | printf("fR_CURSOR\ns\nk120\n"); | 375 | printf("fR_CURSOR\ns\nk120\n"); |
367 | printf("r\nk120\n"); | 376 | printf("r\n"); |
368 | printf("fR_NEXT\ns\n"); | 377 | printf("fR_NEXT\ns\n"); |
369 | printf("fR_CURSOR\ns\nk1\n"); | 378 | printf("fR_CURSOR\ns\nk1\n"); |
370 | printf("r\nk1\n"); | 379 | printf("r\n"); |
371 | printf("fR_FIRST\ns\n"); | 380 | printf("fR_FIRST\ns\n"); |
372 | }' > $TMP2 | 381 | }' > $TMP2 |
373 | $PROG -o $TMP3 recno $TMP2 | 382 | $PROG -o $TMP3 recno $TMP2 |
@@ -397,8 +406,6 @@ test8() | |||
397 | printf("e\t%d of 10 \n", i); | 406 | printf("e\t%d of 10 \n", i); |
398 | printf("r\nkkey1\nr\nkkey2\n"); | 407 | printf("r\nkkey1\nr\nkkey2\n"); |
399 | } | 408 | } |
400 | printf("e\n"); | ||
401 | printf("eend of test8 run\n"); | ||
402 | }' > $TMP1 | 409 | }' > $TMP1 |
403 | $PROG btree $TMP1 | 410 | $PROG btree $TMP1 |
404 | # $PROG hash $TMP1 | 411 | # $PROG hash $TMP1 |
@@ -459,7 +466,7 @@ test10() | |||
459 | printf("p\nk%d\nd%s\n", ++i, $0); | 466 | printf("p\nk%d\nd%s\n", ++i, $0); |
460 | } | 467 | } |
461 | END { | 468 | END { |
462 | printf("fR_CURSOR\nr\nk1\n"); | 469 | printf("fR_CURSOR\nr\n"); |
463 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | 470 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); |
464 | }' > $TMP2 | 471 | }' > $TMP2 |
465 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | 472 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 |
@@ -573,7 +580,8 @@ test13() | |||
573 | echo g | 580 | echo g |
574 | echo k$i | 581 | echo k$i |
575 | done > $TMP2 | 582 | done > $TMP2 |
576 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | 583 | $PROG -s \ |
584 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
577 | if (cmp -s $TMP1 $TMP3) ; then : | 585 | if (cmp -s $TMP1 $TMP3) ; then : |
578 | else | 586 | else |
579 | echo "test13: $type/$order get failed" | 587 | echo "test13: $type/$order get failed" |
diff --git a/src/regress/lib/libc/dirname/Makefile b/src/regress/lib/libc/dirname/Makefile new file mode 100644 index 0000000000..fc152df954 --- /dev/null +++ b/src/regress/lib/libc/dirname/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | PROG=dirname_test | ||
2 | |||
3 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/dirname/dirname_test.c b/src/regress/lib/libc/dirname/dirname_test.c new file mode 100644 index 0000000000..add76980cf --- /dev/null +++ b/src/regress/lib/libc/dirname/dirname_test.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2007 Bret S. Lambert <blambert@gsipt.net> | ||
3 | * | ||
4 | * Public domain. | ||
5 | */ | ||
6 | |||
7 | #include <sys/param.h> | ||
8 | |||
9 | #include <libgen.h> | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <limits.h> | ||
13 | #include <errno.h> | ||
14 | |||
15 | int | ||
16 | main(void) | ||
17 | { | ||
18 | char path[2 * MAXPATHLEN]; | ||
19 | char dname[128]; | ||
20 | const char *dir = "junk"; | ||
21 | const char *fname = "/file.name.ext"; | ||
22 | char *str; | ||
23 | int i; | ||
24 | |||
25 | /* Test normal functioning */ | ||
26 | strlcpy(path, "/", sizeof(path)); | ||
27 | strlcpy(dname, "/", sizeof(dname)); | ||
28 | strlcat(path, dir, sizeof(path)); | ||
29 | strlcat(dname, dir, sizeof(dname)); | ||
30 | strlcat(path, fname, sizeof(path)); | ||
31 | str = dirname(path); | ||
32 | if (strcmp(str, dname) != 0) | ||
33 | errx(1, "0: dirname(%s) = %s != %s", path, str, dname); | ||
34 | |||
35 | /* | ||
36 | * There are four states that require special handling: | ||
37 | * | ||
38 | * 1) path is NULL | ||
39 | * 2) path is the empty string | ||
40 | * 3) path is composed entirely of slashes | ||
41 | * 4) the resulting name is larger than MAXPATHLEN | ||
42 | * | ||
43 | * The first two cases require that a pointer | ||
44 | * to the string "." be returned. | ||
45 | * | ||
46 | * The third case requires that a pointer | ||
47 | * to the string "/" be returned. | ||
48 | * | ||
49 | * The final case requires that NULL be returned | ||
50 | * and errno * be set to ENAMETOOLONG. | ||
51 | */ | ||
52 | /* Case 1 */ | ||
53 | str = dirname(NULL); | ||
54 | if (strcmp(str, ".") != 0) | ||
55 | errx(1, "1: dirname(NULL) = %s != .", str); | ||
56 | |||
57 | /* Case 2 */ | ||
58 | strlcpy(path, "", sizeof(path)); | ||
59 | str = dirname(path); | ||
60 | if (strcmp(str, ".") != 0) | ||
61 | errx(1, "2: dirname(%s) = %s != .", path, str); | ||
62 | |||
63 | /* Case 3 */ | ||
64 | for (i = 0; i < MAXPATHLEN - 1; i++) | ||
65 | strlcat(path, "/", sizeof(path)); /* path cleared above */ | ||
66 | str = dirname(path); | ||
67 | if (strcmp(str, "/") != 0) | ||
68 | errx(1, "3: dirname(%s) = %s != /", path, str); | ||
69 | |||
70 | /* Case 4 */ | ||
71 | strlcpy(path, "/", sizeof(path)); /* reset path */ | ||
72 | for (i = 0; i <= MAXPATHLEN; i += strlen(dir)) | ||
73 | strlcat(path, dir, sizeof(path)); | ||
74 | strlcat(path, fname, sizeof(path)); | ||
75 | str = dirname(path); | ||
76 | if (str != NULL) | ||
77 | errx(1, "4: dirname(%s) = %s != NULL", path, str); | ||
78 | if (errno != ENAMETOOLONG) | ||
79 | errx(1, "4: dirname(%s) sets errno to %d", path, errno); | ||
80 | |||
81 | return (0); | ||
82 | } | ||
diff --git a/src/regress/lib/libc/env/Makefile b/src/regress/lib/libc/env/Makefile new file mode 100644 index 0000000000..92e04369f4 --- /dev/null +++ b/src/regress/lib/libc/env/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/08/23 22:34:37 millert Exp $ | ||
2 | |||
3 | PROG= envtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/env/envtest.c b/src/regress/lib/libc/env/envtest.c new file mode 100644 index 0000000000..33fc463404 --- /dev/null +++ b/src/regress/lib/libc/env/envtest.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /* $OpenBSD: envtest.c,v 1.1 2010/08/23 22:34:37 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | extern char **environ; | ||
27 | |||
28 | static int | ||
29 | count_instances(const char *name) | ||
30 | { | ||
31 | int count = 0; | ||
32 | size_t namelen; | ||
33 | char **ep; | ||
34 | |||
35 | namelen = strlen(name); | ||
36 | for (ep = environ; *ep != NULL; ep++) { | ||
37 | if (strncmp(name, *ep, namelen) == 0 && (*ep)[namelen] == '=') | ||
38 | count++; | ||
39 | } | ||
40 | |||
41 | return count; | ||
42 | } | ||
43 | |||
44 | static void | ||
45 | fake_env(void) | ||
46 | { | ||
47 | static char *fakenv[7]; | ||
48 | |||
49 | fakenv[0] = "HOME=/root"; | ||
50 | fakenv[1] = "USER=root"; | ||
51 | fakenv[2] = "LOGNAME=root"; | ||
52 | fakenv[3] = "SHELL=/bin/sh"; | ||
53 | fakenv[4] = "USER=root"; | ||
54 | fakenv[5] = NULL; | ||
55 | |||
56 | environ = fakenv; | ||
57 | } | ||
58 | |||
59 | int | ||
60 | main(int argc, char *argv[]) | ||
61 | { | ||
62 | char *buf; | ||
63 | int n, failures = 0; | ||
64 | size_t len, bufsize; | ||
65 | |||
66 | /* Enable malloc security options. */ | ||
67 | setenv("MALLOC_OPTIONS", "S", 0); | ||
68 | |||
69 | fake_env(); | ||
70 | n = count_instances("USER"); | ||
71 | if (n != 2) { | ||
72 | fprintf(stderr, "initial: %d instances of USER, expected %d\n", | ||
73 | n, 2); | ||
74 | failures++; | ||
75 | } | ||
76 | |||
77 | if (unsetenv("USER") != 0) { | ||
78 | fprintf(stderr, "unsetenv: failed to remove USER\n"); | ||
79 | failures++; | ||
80 | } | ||
81 | n = count_instances("USER"); | ||
82 | if (n != 0) { | ||
83 | fprintf(stderr, "unsetenv: %d instances of USER, expected %d\n", | ||
84 | n, 0); | ||
85 | failures++; | ||
86 | } | ||
87 | |||
88 | fake_env(); | ||
89 | if (setenv("USER", "nobody", 0) != 0) { | ||
90 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
91 | failures++; | ||
92 | } | ||
93 | n = count_instances("USER"); | ||
94 | if (n != 2) { | ||
95 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
96 | n, 2); | ||
97 | failures++; | ||
98 | } | ||
99 | |||
100 | fake_env(); | ||
101 | if (setenv("USER", "nobody", 1) != 0) { | ||
102 | fprintf(stderr, "setenv: failed to set USER\n"); | ||
103 | failures++; | ||
104 | } | ||
105 | n = count_instances("USER"); | ||
106 | if (n != 1) { | ||
107 | fprintf(stderr, "setenv: %d instances of USER, expected %d\n", | ||
108 | n, 1); | ||
109 | failures++; | ||
110 | } | ||
111 | |||
112 | fake_env(); | ||
113 | if (putenv("USER=nobody") != 0) { | ||
114 | fprintf(stderr, "putenv: failed to set USER\n"); | ||
115 | failures++; | ||
116 | } | ||
117 | n = count_instances("USER"); | ||
118 | if (n != 1) { | ||
119 | fprintf(stderr, "putenv: %d instances of USER, expected %d\n", | ||
120 | n, 1); | ||
121 | failures++; | ||
122 | } | ||
123 | |||
124 | return failures; | ||
125 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile new file mode 100644 index 0000000000..4acdd351bc --- /dev/null +++ b/src/regress/lib/libc/fnmatch/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2011/09/17 15:12:38 stsp Exp $ | ||
2 | |||
3 | PROG= fnm_test | ||
4 | LDADD+= -lutil | ||
5 | DPADD+= ${LIBUTIL} | ||
6 | |||
7 | run-regress-${PROG}: | ||
8 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.c b/src/regress/lib/libc/fnmatch/fnm_test.c new file mode 100644 index 0000000000..f5958837e2 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* $OpenBSD: fnm_test.c,v 1.2 2011/09/17 15:12:38 stsp Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <fnmatch.h> | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <util.h> | ||
12 | |||
13 | int | ||
14 | main(int argc, char **argv) | ||
15 | { | ||
16 | FILE *fp = stdin; | ||
17 | char pattern[1024], string[1024]; | ||
18 | char *line; | ||
19 | const char delim[3] = {'\0', '\0', '#'}; | ||
20 | int errors = 0, flags, got, want; | ||
21 | |||
22 | if (argc > 1) { | ||
23 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
24 | err(1, "%s", argv[1]); | ||
25 | } | ||
26 | |||
27 | /* | ||
28 | * Read in test file, which is formatted thusly: | ||
29 | * | ||
30 | * pattern string flags expected_result | ||
31 | * | ||
32 | * lines starting with '#' are comments | ||
33 | */ | ||
34 | for (;;) { | ||
35 | line = fparseln(fp, NULL, NULL, delim, 0); | ||
36 | if (!line) | ||
37 | break; | ||
38 | got = sscanf(line, "%s %s 0x%x %d", pattern, string, &flags, | ||
39 | &want); | ||
40 | if (got == EOF) { | ||
41 | free(line); | ||
42 | break; | ||
43 | } | ||
44 | if (pattern[0] == '#') { | ||
45 | free(line); | ||
46 | continue; | ||
47 | } | ||
48 | if (got == 4) { | ||
49 | got = fnmatch(pattern, string, flags); | ||
50 | if (got != want) { | ||
51 | warnx("%s %s %d: want %d, got %d", pattern, | ||
52 | string, flags, want, got); | ||
53 | errors++; | ||
54 | } | ||
55 | } else { | ||
56 | warnx("unrecognized line '%s'\n", line); | ||
57 | errors++; | ||
58 | } | ||
59 | free(line); | ||
60 | } | ||
61 | exit(errors); | ||
62 | } | ||
diff --git a/src/regress/lib/libc/fnmatch/fnm_test.in b/src/regress/lib/libc/fnmatch/fnm_test.in new file mode 100644 index 0000000000..c20077966d --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.in | |||
@@ -0,0 +1,259 @@ | |||
1 | /bin/[[:alpha:][:alnum:]]* /bin/ls 0x2 0 | ||
2 | /bin/[[:upper:]][[:alnum:]] /bin/ls 0x10 0 | ||
3 | /bin/[[:opper:][:alnum:]]* /bin/ls 0x0 1 | ||
4 | [[:alpha:][:alnum:]]*.c foo1.c 0x4 0 | ||
5 | [[:upper:]]* FOO 0x0 0 | ||
6 | # 'te\st' 'test'; no match if FNM_NOESCAPE | ||
7 | te\st test 0x0 0 | ||
8 | te\st test 0x1 1 | ||
9 | te\st test 0x1e 0 | ||
10 | # 'te\\st' 'te\st'; no match if FNM_NOESCAPE | ||
11 | te\\st te\st 0x0 0 | ||
12 | te\\st te\st 0x1 1 | ||
13 | te\\st te\st 0x1e 0 | ||
14 | # 'te\*t' 'te*t'; no match if FNM_NOESCAPE | ||
15 | te\*t te*t 0x0 0 | ||
16 | te\*t te*t 0x1 1 | ||
17 | te\*t te*t 0x1e 0 | ||
18 | # 'te\*t' 'test'; no match | ||
19 | te\*t test 0x0 1 | ||
20 | te\*t test 0x1f 1 | ||
21 | # 'te\?t' 'te?t'; no match if FNM_NOESCAPE | ||
22 | te\?t te?t 0x0 0 | ||
23 | te\?t te?t 0x1 1 | ||
24 | te\?t te?t 0x1e 0 | ||
25 | # 'te\?t' 'test'; no match | ||
26 | te\?t test 0x0 1 | ||
27 | te\?t test 0x1f 1 | ||
28 | # 'tesT' 'test'; match if FNM_CASEFOLD | ||
29 | tesT test 0x0 1 | ||
30 | tesT test 0xf 1 | ||
31 | tesT test 0x10 0 | ||
32 | # 'test' 'Test'; match if FNM_CASEFOLD | ||
33 | test Test 0x0 1 | ||
34 | test Test 0xf 1 | ||
35 | test Test 0x10 0 | ||
36 | # 'tEst' 'teSt'; match if FNM_CASEFOLD | ||
37 | tEst teSt 0x0 1 | ||
38 | tEst teSt 0xf 1 | ||
39 | tEst teSt 0x10 0 | ||
40 | # '?est' 'test'; match always | ||
41 | ?est test 0x0 0 | ||
42 | ?est test 0x1f 0 | ||
43 | # 'te?t' 'test'; match always | ||
44 | te?t test 0x0 0 | ||
45 | te?t test 0x1f 0 | ||
46 | # 'tes?' 'test'; match always | ||
47 | tes? test 0x0 0 | ||
48 | tes? test 0x1f 0 | ||
49 | # 'test?' 'test'; no match | ||
50 | test? test 0x0 1 | ||
51 | test? test 0x1f 1 | ||
52 | # '*' always matches anything | ||
53 | * test 0x0 0 | ||
54 | * test 0x1f 0 | ||
55 | # '*test' 'test'; match always | ||
56 | *test test 0x0 0 | ||
57 | *test test 0x1f 0 | ||
58 | # '*est' 'test'; match always | ||
59 | *est test 0x0 0 | ||
60 | *est test 0x1f 0 | ||
61 | # '*st' 'test'; match always | ||
62 | *st test 0x0 0 | ||
63 | *st test 0x1f 0 | ||
64 | # 't*t' 'test'; match always | ||
65 | t*t test 0x0 0 | ||
66 | t*t test 0x1f 0 | ||
67 | # 'te*t' 'test'; match always | ||
68 | te*t test 0x0 0 | ||
69 | te*t test 0x1f 0 | ||
70 | # 'te*st' 'test'; match always | ||
71 | te*st test 0x0 0 | ||
72 | te*st test 0x1f 0 | ||
73 | # 'te*' 'test'; match always | ||
74 | te* test 0x0 0 | ||
75 | te* test 0x1f 0 | ||
76 | # 'tes*' 'test'; match always | ||
77 | tes* test 0x0 0 | ||
78 | tes* test 0x1f 0 | ||
79 | # 'test*' 'test'; match always | ||
80 | test* test 0x0 0 | ||
81 | test* test 0x1f 0 | ||
82 | # '.[\-\t]' '.t'; match always | ||
83 | .[\-\t] .t 0x0 0 | ||
84 | .[\-\t] .t 0x1f 0 | ||
85 | # 'test*?*[a-z]*' 'testgoop'; match always | ||
86 | test*?*[a-z]* testgoop 0x0 0 | ||
87 | test*?*[a-z]* testgoop 0x1f 0 | ||
88 | # 'te[^abc]t' 'test'; match always | ||
89 | te[^abc]t test 0x0 0 | ||
90 | te[^abc]t test 0x1f 0 | ||
91 | # 'te[^x]t' 'test'; match always | ||
92 | te[^x]t test 0x0 0 | ||
93 | te[^x]t test 0x1f 0 | ||
94 | # 'te[!x]t' 'test'; match always | ||
95 | te[!x]t test 0x0 0 | ||
96 | te[^x]t test 0x1f 0 | ||
97 | # 'te[^x]t' 'text'; no match | ||
98 | te[^x]t text 0x0 1 | ||
99 | te[^x]t text 0x1f 1 | ||
100 | # 'te[^\x]t' 'text'; no match | ||
101 | te[^\x]t text 0x0 1 | ||
102 | te[^\x]t text 0x1f 1 | ||
103 | # 'te[^\x' 'text'; no match | ||
104 | te[^\x text 0x0 1 | ||
105 | te[^\x text 0x1f 1 | ||
106 | # 'te[/]t' 'text'; no match | ||
107 | te[/]t text 0x0 1 | ||
108 | te[/]t text 0x1f 1 | ||
109 | # 'te[S]t' 'test'; match if FNM_CASEFOLD | ||
110 | te[S]t test 0x0 1 | ||
111 | te[S]t test 0xf 1 | ||
112 | te[S]t test 0x10 0 | ||
113 | # 'te[r-t]t' 'test'; match always | ||
114 | te[r-t]t test 0x0 0 | ||
115 | te[r-t]t test 0x1f 0 | ||
116 | # 'te[r-t]t' 'teSt'; match if FNM_CASEFOLD | ||
117 | te[r-t]t teSt 0x0 1 | ||
118 | te[r-t]t teSt 0xf 1 | ||
119 | te[r-t]t teSt 0x10 0 | ||
120 | # 'te[r-T]t' 'test'; match if FNM_CASEFOLD | ||
121 | te[r-T]t test 0x0 1 | ||
122 | te[r-T]t test 0xf 1 | ||
123 | te[r-T]t test 0x10 0 | ||
124 | # 'te[R-T]t' 'test'; match if FNM_CASEFOLD | ||
125 | te[R-T]t test 0x0 1 | ||
126 | te[R-T]t test 0xf 1 | ||
127 | te[R-T]t test 0x10 0 | ||
128 | # 'te[r-Tz]t' 'tezt'; match always | ||
129 | te[r-Tz]t tezt 0x0 0 | ||
130 | te[r-Tz]t tezt 0x1f 0 | ||
131 | # 'te[R-T]t' 'tent'; no match | ||
132 | te[R-T]t tent 0x0 1 | ||
133 | te[R-T]t tent 0x1f 1 | ||
134 | # 'tes[]t]' 'test'; match always | ||
135 | tes[]t] test 0x0 0 | ||
136 | tes[]t] test 0x1f 0 | ||
137 | # 'tes[t-]' 'test'; match always | ||
138 | tes[t-] test 0x0 0 | ||
139 | tes[t-] test 0x1f 0 | ||
140 | # 'tes[t-]]' 'test]'; match always | ||
141 | tes[t-]] test] 0x0 0 | ||
142 | tes[t-]] test] 0x1f 0 | ||
143 | # 'tes[t-]]' 'test'; no match | ||
144 | tes[t-]] test 0x0 1 | ||
145 | tes[t-]] test 0x1f 1 | ||
146 | # 'tes[u-]' 'test'; no match | ||
147 | tes[u-] test 0x0 1 | ||
148 | tes[u-] test 0x1f 1 | ||
149 | # 'tes[t-]' 'tes[t-]'; no match | ||
150 | tes[t-] test[t-] 0x0 1 | ||
151 | tes[t-] test[t-] 0x1f 1 | ||
152 | # 'test[/-/]' 'test[/-/]'; no match | ||
153 | test[/-/] test/-/ 0x0 1 | ||
154 | test[/-/] test/-/ 0x1f 1 | ||
155 | # 'test[\/-/]' 'test[/-/]'; no match | ||
156 | test[\/-/] test/-/ 0x0 1 | ||
157 | test[\/-/] test/-/ 0x1f 1 | ||
158 | # 'test[/-\/]' 'test[/-/]'; no match | ||
159 | test[/-\/] test/-/ 0x0 1 | ||
160 | test[/-\/] test/-/ 0x1f 1 | ||
161 | # 'test[/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
162 | test[/-/] test/ 0x0 0 | ||
163 | test[/-/] test/ 0x2 1 | ||
164 | test[/-/] test/ 0x1d 0 | ||
165 | # 'test[\/-/]' 'test/'; no match if APR_FNM_PATHNAME | ||
166 | test[\/-/] test/ 0x0 0 | ||
167 | test[\/-/] test/ 0x2 1 | ||
168 | test[\/-/] test/ 0x1d 0 | ||
169 | # 'test[/-\/]' 'test/'; no match if APR_FNM_PATHNAME | ||
170 | test[/-\/] test/ 0x0 0 | ||
171 | test[/-\/] test/ 0x2 1 | ||
172 | test[/-\/] test/ 0x1d 0 | ||
173 | # '/test' 'test'; no match | ||
174 | /test test 0x0 1 | ||
175 | /test test 0x1f 1 | ||
176 | # 'test' '/test'; no match | ||
177 | test /test 0x0 1 | ||
178 | test /test 0x1f 1 | ||
179 | # 'test/' 'test'; no match | ||
180 | test/ test 0x0 1 | ||
181 | test/ test 0x1f 1 | ||
182 | # 'test' 'test/'; match if FNM_LEADING_DIR | ||
183 | test test/ 0x0 1 | ||
184 | test test/ 0x17 1 | ||
185 | test test/ 0x8 0 | ||
186 | # '\/test' '/test'; match unless FNM_NOESCAPE | ||
187 | \/test /test 0x0 0 | ||
188 | \/test /test 0x1 1 | ||
189 | \/test /test 0x1e 0 | ||
190 | # '*test' '/test'; match unless FNM_PATHNAME | ||
191 | *test /test 0x0 0 | ||
192 | *test /test 0x2 1 | ||
193 | *test /test 0x1d 0 | ||
194 | # '/*/test' '/test'; no match | ||
195 | /*/test /test 0x0 1 | ||
196 | /*/test /test 0x1f 1 | ||
197 | # '/*/test' '/test/test'; match always | ||
198 | /*/test /test/test 0x0 0 | ||
199 | /*/test /test/test 0x1f 0 | ||
200 | # 'test/this' 'test/'; match never | ||
201 | test/this test/ 0x0 1 | ||
202 | test/this test/ 0x1f 1 | ||
203 | # 'test/' 'test/this'; match never | ||
204 | test/ test/this 0x0 1 | ||
205 | test/ test/this 0x1f 1 | ||
206 | # 'test*/this' 'test/this'; match always | ||
207 | test*/this test/this 0x0 0 | ||
208 | test*/this test/this 0x1f 0 | ||
209 | # 'test*/this' 'test/that'; match never | ||
210 | test*/this test/that 0x0 1 | ||
211 | test*/this test/that 0x1f 1 | ||
212 | # 'test/*this' 'test/this'; match always | ||
213 | test/*this test/this 0x0 0 | ||
214 | test/*this test/this 0x1f 0 | ||
215 | # '.*' '.this'; match always | ||
216 | .* .this 0x0 0 | ||
217 | .* .this 0x1f 0 | ||
218 | # '*' '.this'; fails if FNM_PERIOD | ||
219 | * .this 0x0 0 | ||
220 | * .this 0x4 1 | ||
221 | * .this 0x1b 0 | ||
222 | # '?this' '.this'; fails if FNM_PERIOD | ||
223 | ?this .this 0x0 0 | ||
224 | ?this .this 0x4 1 | ||
225 | ?this .this 0x1b 0 | ||
226 | # '[.]this' '.this'; fails if FNM_PERIOD | ||
227 | [.]this .this 0x0 0 | ||
228 | [.]this .this 0x4 1 | ||
229 | [.]this .this 0x1b 0 | ||
230 | # 'test/this' 'test/this'; match always | ||
231 | test/this test/this 0x0 0 | ||
232 | test/this test/this 0x1f 0 | ||
233 | # 'test?this' 'test/this'; fails if FNM_PATHNAME | ||
234 | test?this test/this 0x0 0 | ||
235 | test?this test/this 0x2 1 | ||
236 | test?this test/this 0x1d 0 | ||
237 | # 'test*this' 'test/this'; fails if FNM_PATHNAME | ||
238 | test*this test/this 0x0 0 | ||
239 | test*this test/this 0x2 1 | ||
240 | test*this test/this 0x1d 0 | ||
241 | # 'test[/]this' 'test/this'; fails if FNM_PATHNAME | ||
242 | test[/]this test/this 0x0 0 | ||
243 | test[/]this test/this 0x2 1 | ||
244 | test[/]this test/this 0x1d 0 | ||
245 | # 'test/.*' 'test/.this'; match always | ||
246 | test/.* test/.this 0x0 0 | ||
247 | test/.* test/.this 0x1f 0 | ||
248 | # 'test/*' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
249 | test/* test/.this 0x0 0 | ||
250 | test/* test/.this 0x6 1 | ||
251 | test/* test/.this 0x19 0 | ||
252 | # 'test/?' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
253 | test/?this test/.this 0x0 0 | ||
254 | test/?this test/.this 0x6 1 | ||
255 | test/?this test/.this 0x19 0 | ||
256 | # 'test/[.]this' 'test/.this'; fails if FNM_PERIOD and FNM_PATHNAME | ||
257 | test/[.]this test/.this 0x0 0 | ||
258 | test/[.]this test/.this 0x6 1 | ||
259 | test/[.]this test/.this 0x19 0 | ||
diff --git a/src/regress/lib/libc/fpclassify/Makefile b/src/regress/lib/libc/fpclassify/Makefile new file mode 100644 index 0000000000..96916d20e7 --- /dev/null +++ b/src/regress/lib/libc/fpclassify/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
2 | |||
3 | PROG= fpclassify | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/fpclassify/fpclassify.c b/src/regress/lib/libc/fpclassify/fpclassify.c new file mode 100644 index 0000000000..174c04d983 --- /dev/null +++ b/src/regress/lib/libc/fpclassify/fpclassify.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* $OpenBSD: fpclassify.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | * | ||
27 | * $FreeBSD: src/tools/regression/lib/libc/gen/test-fpclassify.c,v 1.3 2003/03/27 05:32:28 das Exp $ | ||
28 | */ | ||
29 | |||
30 | #include <assert.h> | ||
31 | #include <float.h> | ||
32 | #include <math.h> | ||
33 | #include <stdlib.h> | ||
34 | |||
35 | int | ||
36 | main(void) | ||
37 | { | ||
38 | |||
39 | assert(fpclassify((float)0) == FP_ZERO); | ||
40 | assert(fpclassify((float)-0.0) == FP_ZERO); | ||
41 | assert(fpclassify((float)1) == FP_NORMAL); | ||
42 | assert(fpclassify((float)1000) == FP_NORMAL); | ||
43 | #ifndef __alpha__ | ||
44 | assert(fpclassify(0x1.2p-150f) == FP_SUBNORMAL); | ||
45 | #endif /* !__alpha__ */ | ||
46 | assert(fpclassify(HUGE_VALF) == FP_INFINITE); | ||
47 | assert(fpclassify((float)HUGE_VAL) == FP_INFINITE); | ||
48 | assert(fpclassify((float)HUGE_VALL) == FP_INFINITE); | ||
49 | assert(fpclassify(NAN) == FP_NAN); | ||
50 | |||
51 | assert(fpclassify((double)0) == FP_ZERO); | ||
52 | assert(fpclassify((double)-0) == FP_ZERO); | ||
53 | assert(fpclassify((double)1) == FP_NORMAL); | ||
54 | assert(fpclassify((double)1000) == FP_NORMAL); | ||
55 | #ifndef __alpha__ | ||
56 | assert(fpclassify(0x1.2p-1075) == FP_SUBNORMAL); | ||
57 | #endif /* !__alpha__ */ | ||
58 | assert(fpclassify(HUGE_VAL) == FP_INFINITE); | ||
59 | assert(fpclassify((double)HUGE_VALF) == FP_INFINITE); | ||
60 | assert(fpclassify((double)HUGE_VALL) == FP_INFINITE); | ||
61 | assert(fpclassify((double)NAN) == FP_NAN); | ||
62 | |||
63 | assert(fpclassify((long double)0) == FP_ZERO); | ||
64 | assert(fpclassify((long double)-0.0) == FP_ZERO); | ||
65 | assert(fpclassify((long double)1) == FP_NORMAL); | ||
66 | assert(fpclassify((long double)1000) == FP_NORMAL); | ||
67 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) | ||
68 | assert(fpclassify(0x1.2p-16383L) == FP_SUBNORMAL); | ||
69 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) */ | ||
70 | assert(fpclassify(HUGE_VALL) == FP_INFINITE); | ||
71 | assert(fpclassify((long double)HUGE_VALF) == FP_INFINITE); | ||
72 | assert(fpclassify((long double)HUGE_VAL) == FP_INFINITE); | ||
73 | assert(fpclassify((long double)NAN) == FP_NAN); | ||
74 | |||
75 | return (0); | ||
76 | } | ||
diff --git a/src/regress/lib/libc/gcvt/Makefile b/src/regress/lib/libc/gcvt/Makefile new file mode 100644 index 0000000000..d8efaa9362 --- /dev/null +++ b/src/regress/lib/libc/gcvt/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/09/17 19:51:38 millert Exp $ | ||
2 | |||
3 | PROG= gcvt_test | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/gcvt/gcvt_test.c b/src/regress/lib/libc/gcvt/gcvt_test.c new file mode 100644 index 0000000000..164d600cd2 --- /dev/null +++ b/src/regress/lib/libc/gcvt/gcvt_test.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* $OpenBSD: gcvt_test.c,v 1.4 2010/09/18 20:29:15 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2010, Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | */ | ||
6 | |||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | static struct test_vector { | ||
12 | double d; | ||
13 | int ndig; | ||
14 | char *expect; | ||
15 | } test_vectors[] = { | ||
16 | /* adapted from perl's Configure test */ | ||
17 | { 0.1, 8, "0.1" }, | ||
18 | { 0.01, 8, "0.01" }, | ||
19 | { 0.001, 8, "0.001" }, | ||
20 | { 0.0001, 8, "0.0001" }, | ||
21 | { 0.00009, 8, "9e-05" }, | ||
22 | { 1.0, 8, "1" }, | ||
23 | { 1.1, 8, "1.1" }, | ||
24 | { 1.01, 8, "1.01" }, | ||
25 | { 1.001, 8, "1.001" }, | ||
26 | { 1.0001, 8, "1.0001" }, | ||
27 | { 1.00001, 8, "1.00001" }, | ||
28 | { 1.000001, 8, "1.000001" }, | ||
29 | { 0.0, 8, "0" }, | ||
30 | { -1.0, 8, "-1" }, | ||
31 | { 100000.0, 8, "100000" }, | ||
32 | { -100000.0, 8, "-100000" }, | ||
33 | { 123.456, 8, "123.456" }, | ||
34 | { 1e34, 8, "1e+34" }, | ||
35 | /* adapted from emx */ | ||
36 | { 0.0, -1, "0" }, | ||
37 | { 0.0, 0, "0" }, | ||
38 | { 0.0, 1, "0" }, | ||
39 | { 0.0, 2, "0" }, | ||
40 | { 1.0, -1, "1" }, | ||
41 | { 1.0, 0, "1" }, | ||
42 | { 1.0, 2, "1" }, | ||
43 | { 1.0, 10, "1" }, | ||
44 | { 1.236, -1, "1.236" }, | ||
45 | { 1.236, 0, "1" }, | ||
46 | { 1.236, 1, "1" }, | ||
47 | { 1.236, 2, "1.2" }, | ||
48 | { 1.236, 3, "1.24" }, | ||
49 | { 1.236, 4, "1.236" }, | ||
50 | { 1.236, 5, "1.236" }, | ||
51 | { 1.236, 6, "1.236" }, | ||
52 | { 12.36, -1, "12.36" }, | ||
53 | { 12.36, 0, "1e+01" }, | ||
54 | { 12.36, 1, "1e+01" }, | ||
55 | { 12.36, 2, "12" }, | ||
56 | { 12.36, 3, "12.4" }, | ||
57 | { 12.36, 4, "12.36" }, | ||
58 | { 12.36, 5, "12.36" }, | ||
59 | { 12.36, 6, "12.36" }, | ||
60 | { 123.6, -1, "123.6" }, | ||
61 | { 123.6, 0, "1e+02" }, | ||
62 | { 123.6, 1, "1e+02" }, | ||
63 | { 123.6, 2, "1.2e+02" }, | ||
64 | { 123.6, 3, "124" }, | ||
65 | { 123.6, 4, "123.6" }, | ||
66 | { 123.6, 5, "123.6" }, | ||
67 | { 123.6, 6, "123.6" }, | ||
68 | { 1236.0, -1, "1236" }, | ||
69 | { 1236.0, 0, "1e+03" }, | ||
70 | { 1236.0, 1, "1e+03" }, | ||
71 | { 1236.0, 2, "1.2e+03" }, | ||
72 | { 1236.0, 3, "1.24e+03" }, | ||
73 | { 1236.0, 4, "1236" }, | ||
74 | { 1236.0, 5, "1236" }, | ||
75 | { 1236.0, 6, "1236" }, | ||
76 | { 1e100, 10, "1e+100" }, | ||
77 | { 1e100, 20, "1.0000000000000000159e+100" }, | ||
78 | { 0.01236, -1, "0.01236" }, | ||
79 | { 0.01236, 0, "0.01" }, | ||
80 | { 0.01236, 1, "0.01" }, | ||
81 | { 0.01236, 2, "0.012" }, | ||
82 | { 0.01236, 3, "0.0124" }, | ||
83 | { 0.01236, 4, "0.01236" }, | ||
84 | { 1e-100, 20, "1.00000000000000002e-100" }, | ||
85 | { 1e-100, -1, "1e-100" }, | ||
86 | { -1.2, 5, "-1.2" }, | ||
87 | { -0.03, 5, "-0.03" }, | ||
88 | { 0.1, 1, "0.1" }, | ||
89 | { 0.1, 0, "0.1" }, | ||
90 | { 0.099999, 10, "0.099999" }, | ||
91 | { 0.99999, 10, "0.99999" }, | ||
92 | }; | ||
93 | |||
94 | #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) | ||
95 | |||
96 | static int | ||
97 | dotest(struct test_vector *tv) | ||
98 | { | ||
99 | char buf[256], *got; | ||
100 | |||
101 | got = gcvt(tv->d, tv->ndig, buf); | ||
102 | if (strcmp(tv->expect, got) != 0) { | ||
103 | fprintf(stderr, "%g @ %d: expected %s, got %s\n", | ||
104 | tv->d, tv->ndig, tv->expect, got); | ||
105 | return 1; | ||
106 | } | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | int | ||
111 | main(int argc, char *argv[]) | ||
112 | { | ||
113 | int i, failures = 0; | ||
114 | |||
115 | for (i = 0; i < NTESTVEC; i++) { | ||
116 | failures += dotest(&test_vectors[i]); | ||
117 | } | ||
118 | |||
119 | return failures; | ||
120 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile new file mode 100644 index 0000000000..d93494cc1c --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/Makefile | |||
@@ -0,0 +1,19 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2011/07/07 21:00:59 deraadt Exp $ | ||
2 | |||
3 | PROG= gaitest | ||
4 | SRCS= gaitest.c | ||
5 | NOMAN= # defined | ||
6 | CLEANFILES+= out | ||
7 | |||
8 | REGRESS_TARGETS=do-test | ||
9 | |||
10 | do-test: ${PROG} | ||
11 | sh ${.CURDIR}/testsuite.sh >out 2>&1 | ||
12 | @if diff -u10 out ${.CURDIR}/answer; then \ | ||
13 | echo SUCCESS; \ | ||
14 | else \ | ||
15 | echo FAIL; \ | ||
16 | exit 1; \ | ||
17 | fi | ||
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getaddrinfo/answer b/src/regress/lib/libc/getaddrinfo/answer new file mode 100644 index 0000000000..778fc64baa --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/answer | |||
@@ -0,0 +1,110 @@ | |||
1 | == basic ones | ||
2 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http | ||
3 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
4 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http | ||
5 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
6 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
7 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
8 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
9 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp | ||
10 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
11 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp | ||
12 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
13 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp | ||
14 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
15 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
16 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo | ||
17 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
18 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
19 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo | ||
20 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
21 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
22 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo | ||
23 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
24 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
25 | ai3: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
26 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
27 | |||
28 | == specific address family | ||
29 | arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
30 | ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
31 | arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http | ||
32 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
33 | |||
34 | == empty hostname | ||
35 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
36 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
37 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
38 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
39 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
40 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
41 | ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
42 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7 | ||
43 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
44 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
45 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 | ||
46 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
47 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
48 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
49 | ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
50 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
51 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
52 | ai1: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
53 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
54 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
55 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7 | ||
56 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7 | ||
57 | ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7 | ||
58 | ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7 | ||
59 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
60 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69 | ||
61 | ai2: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69 | ||
62 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
63 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 80 | ||
64 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
65 | ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 80 | ||
66 | ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
67 | arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 | ||
68 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
69 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
70 | arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 | ||
71 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
72 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
73 | |||
74 | == empty servname | ||
75 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) | ||
76 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
77 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
78 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) | ||
79 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
80 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
81 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
82 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
83 | ai2: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
84 | ai3: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
85 | ai4: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
86 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) | ||
87 | name or service is not known | ||
88 | |||
89 | == sock_raw | ||
90 | arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) | ||
91 | ai1: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 | ||
92 | ai2: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 | ||
93 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) | ||
94 | ai1: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 | ||
95 | ai2: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
96 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 | ||
97 | service not supported for ai_socktype | ||
98 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www | ||
99 | service not supported for ai_socktype | ||
100 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) | ||
101 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
102 | |||
103 | == unsupported family | ||
104 | arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
105 | ai_family not supported | ||
106 | |||
107 | == the following items are specified in jinmei scopeaddr format doc. | ||
108 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http | ||
109 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80 | ||
110 | |||
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c new file mode 100644 index 0000000000..12a4498459 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/gaitest.c | |||
@@ -0,0 +1,195 @@ | |||
1 | /* $OpenBSD: gaitest.c,v 1.6 2009/06/09 18:15:08 phessler Exp $ */ | ||
2 | /* $NetBSD: gaitest.c,v 1.3 2002/07/05 15:47:43 itojun Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. Neither the name of the project nor the names of its contributors | ||
17 | * may be used to endorse or promote products derived from this software | ||
18 | * without specific prior written permission. | ||
19 | * | ||
20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | * SUCH DAMAGE. | ||
31 | */ | ||
32 | |||
33 | /* | ||
34 | * Please note: the order of the responses (and the regress test) | ||
35 | * is dependent on the "family" keywords in resolv.conf. | ||
36 | * | ||
37 | * This expects the default behaviour of "family inet4 inet6" | ||
38 | */ | ||
39 | |||
40 | #include <sys/types.h> | ||
41 | #include <sys/socket.h> | ||
42 | #include <netinet/in.h> | ||
43 | #include <arpa/inet.h> | ||
44 | #include <netdb.h> | ||
45 | #include <stdio.h> | ||
46 | #include <stdlib.h> | ||
47 | #include <string.h> | ||
48 | #include <unistd.h> | ||
49 | |||
50 | struct addrinfo ai; | ||
51 | |||
52 | char host[NI_MAXHOST]; | ||
53 | char serv[NI_MAXSERV]; | ||
54 | int vflag = 0; | ||
55 | |||
56 | static void usage(void); | ||
57 | static void print1(const char *, const struct addrinfo *, char *, char *); | ||
58 | int main(int, char *[]); | ||
59 | |||
60 | static void | ||
61 | usage() | ||
62 | { | ||
63 | fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | print1(title, res, h, s) | ||
68 | const char *title; | ||
69 | const struct addrinfo *res; | ||
70 | char *h; | ||
71 | char *s; | ||
72 | { | ||
73 | char *start, *end; | ||
74 | int error; | ||
75 | const int niflag = NI_NUMERICHOST | NI_NUMERICSERV; | ||
76 | |||
77 | if (res->ai_addr) { | ||
78 | error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, | ||
79 | host, sizeof(host), serv, sizeof(serv), | ||
80 | niflag); | ||
81 | h = host; | ||
82 | s = serv; | ||
83 | } else | ||
84 | error = 0; | ||
85 | |||
86 | if (vflag) { | ||
87 | start = "\t"; | ||
88 | end = "\n"; | ||
89 | } else { | ||
90 | start = " "; | ||
91 | end = ""; | ||
92 | } | ||
93 | printf("%s%s", title, end); | ||
94 | printf("%sflags 0x%x%s", start, res->ai_flags, end); | ||
95 | printf("%sfamily %d%s", start, res->ai_family, end); | ||
96 | printf("%ssocktype %d%s", start, res->ai_socktype, end); | ||
97 | printf("%sprotocol %d%s", start, res->ai_protocol, end); | ||
98 | printf("%saddrlen %d%s", start, res->ai_addrlen, end); | ||
99 | if (error) | ||
100 | printf("%serror %d%s", start, error, end); | ||
101 | else { | ||
102 | printf("%shost %s%s", start, h, end); | ||
103 | printf("%sserv %s%s", start, s, end); | ||
104 | } | ||
105 | #if 0 | ||
106 | if (res->ai_canonname) | ||
107 | printf("%scname \"%s\"%s", start, res->ai_canonname, end); | ||
108 | #endif | ||
109 | if (!vflag) | ||
110 | printf("\n"); | ||
111 | |||
112 | } | ||
113 | |||
114 | int | ||
115 | main(argc, argv) | ||
116 | int argc; | ||
117 | char *argv[]; | ||
118 | { | ||
119 | struct addrinfo *res; | ||
120 | int error, i; | ||
121 | char *p, *q; | ||
122 | extern int optind; | ||
123 | extern char *optarg; | ||
124 | int c; | ||
125 | char nbuf[10]; | ||
126 | |||
127 | memset(&ai, 0, sizeof(ai)); | ||
128 | ai.ai_family = PF_UNSPEC; | ||
129 | ai.ai_flags |= AI_CANONNAME; | ||
130 | while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { | ||
131 | switch (c) { | ||
132 | case 'D': | ||
133 | ai.ai_socktype = SOCK_DGRAM; | ||
134 | break; | ||
135 | case 'f': | ||
136 | ai.ai_family = atoi(optarg); | ||
137 | break; | ||
138 | case 'p': | ||
139 | ai.ai_protocol = atoi(optarg); | ||
140 | break; | ||
141 | case 'P': | ||
142 | ai.ai_flags |= AI_PASSIVE; | ||
143 | break; | ||
144 | case 'R': | ||
145 | ai.ai_socktype = SOCK_RAW; | ||
146 | break; | ||
147 | case 's': | ||
148 | ai.ai_socktype = atoi(optarg); | ||
149 | break; | ||
150 | case 'S': | ||
151 | ai.ai_socktype = SOCK_STREAM; | ||
152 | break; | ||
153 | case 'v': | ||
154 | vflag++; | ||
155 | break; | ||
156 | case '4': | ||
157 | ai.ai_family = PF_INET; | ||
158 | break; | ||
159 | case '6': | ||
160 | ai.ai_family = PF_INET6; | ||
161 | break; | ||
162 | default: | ||
163 | usage(); | ||
164 | exit(1); | ||
165 | } | ||
166 | } | ||
167 | argc -= optind; | ||
168 | argv += optind; | ||
169 | |||
170 | if (argc != 2){ | ||
171 | usage(); | ||
172 | exit(1); | ||
173 | } | ||
174 | |||
175 | p = *argv[0] ? argv[0] : NULL; | ||
176 | q = *argv[1] ? argv[1] : NULL; | ||
177 | |||
178 | print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)"); | ||
179 | |||
180 | error = getaddrinfo(p, q, &ai, &res); | ||
181 | if (error) { | ||
182 | printf("%s\n", gai_strerror(error)); | ||
183 | exit(1); | ||
184 | } | ||
185 | |||
186 | i = 1; | ||
187 | do { | ||
188 | snprintf(nbuf, sizeof(nbuf), "ai%d:", i); | ||
189 | print1(nbuf, res, NULL, NULL); | ||
190 | |||
191 | i++; | ||
192 | } while ((res = res->ai_next) != NULL); | ||
193 | |||
194 | exit(0); | ||
195 | } | ||
diff --git a/src/regress/lib/libc/getaddrinfo/testsuite.sh b/src/regress/lib/libc/getaddrinfo/testsuite.sh new file mode 100644 index 0000000000..1e4e524054 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/testsuite.sh | |||
@@ -0,0 +1,89 @@ | |||
1 | # $OpenBSD: testsuite.sh,v 1.1 2002/07/05 15:54:30 itojun Exp $ | ||
2 | # $NetBSD: testsuite.sh,v 1.3 2002/07/05 15:49:11 itojun Exp $ | ||
3 | |||
4 | # | ||
5 | # Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. | ||
6 | # All rights reserved. | ||
7 | # | ||
8 | # Redistribution and use in source and binary forms, with or without | ||
9 | # modification, are permitted provided that the following conditions | ||
10 | # are met: | ||
11 | # 1. Redistributions of source code must retain the above copyright | ||
12 | # notice, this list of conditions and the following disclaimer. | ||
13 | # 2. Redistributions in binary form must reproduce the above copyright | ||
14 | # notice, this list of conditions and the following disclaimer in the | ||
15 | # documentation and/or other materials provided with the distribution. | ||
16 | # 3. Neither the name of the project nor the names of its contributors | ||
17 | # may be used to endorse or promote products derived from this software | ||
18 | # without specific prior written permission. | ||
19 | # | ||
20 | # THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND | ||
21 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | ||
24 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | # SUCH DAMAGE. | ||
31 | # | ||
32 | |||
33 | TEST=./gaitest | ||
34 | #TEST='./test -v' | ||
35 | #IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'` | ||
36 | |||
37 | echo '== basic ones' | ||
38 | $TEST ::1 http | ||
39 | $TEST 127.0.0.1 http | ||
40 | $TEST localhost http | ||
41 | $TEST ::1 tftp | ||
42 | $TEST 127.0.0.1 tftp | ||
43 | $TEST localhost tftp | ||
44 | $TEST ::1 echo | ||
45 | $TEST 127.0.0.1 echo | ||
46 | $TEST localhost echo | ||
47 | echo | ||
48 | |||
49 | echo '== specific address family' | ||
50 | $TEST -4 localhost http | ||
51 | $TEST -6 localhost http | ||
52 | echo | ||
53 | |||
54 | echo '== empty hostname' | ||
55 | $TEST '' http | ||
56 | $TEST '' echo | ||
57 | $TEST '' tftp | ||
58 | $TEST '' 80 | ||
59 | $TEST -P '' http | ||
60 | $TEST -P '' echo | ||
61 | $TEST -P '' tftp | ||
62 | $TEST -P '' 80 | ||
63 | $TEST -S '' 80 | ||
64 | $TEST -D '' 80 | ||
65 | echo | ||
66 | |||
67 | echo '== empty servname' | ||
68 | $TEST ::1 '' | ||
69 | $TEST 127.0.0.1 '' | ||
70 | $TEST localhost '' | ||
71 | $TEST '' '' | ||
72 | echo | ||
73 | |||
74 | echo '== sock_raw' | ||
75 | $TEST -R -p 0 localhost '' | ||
76 | $TEST -R -p 59 localhost '' | ||
77 | $TEST -R -p 59 localhost 80 | ||
78 | $TEST -R -p 59 localhost www | ||
79 | $TEST -R -p 59 ::1 '' | ||
80 | echo | ||
81 | |||
82 | echo '== unsupported family' | ||
83 | $TEST -f 99 localhost '' | ||
84 | echo | ||
85 | |||
86 | echo '== the following items are specified in jinmei scopeaddr format doc.' | ||
87 | $TEST fe80::1%lo0 http | ||
88 | #$TEST fe80::1%$IF http | ||
89 | echo | ||
diff --git a/src/regress/lib/libc/getcap/Makefile b/src/regress/lib/libc/getcap/Makefile new file mode 100644 index 0000000000..7b7ae394ff --- /dev/null +++ b/src/regress/lib/libc/getcap/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2009/06/09 18:16:40 phessler Exp $ | ||
2 | |||
3 | PROG= getcaptest | ||
4 | |||
5 | REGRESS_TARGETS=shortcap | ||
6 | |||
7 | shortcap: getcaptest | ||
8 | ./getcaptest ${.CURDIR}/shortcap.in | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getcap/getcaptest.c b/src/regress/lib/libc/getcap/getcaptest.c new file mode 100644 index 0000000000..0f4464b6c5 --- /dev/null +++ b/src/regress/lib/libc/getcap/getcaptest.c | |||
@@ -0,0 +1,26 @@ | |||
1 | /* $OpenBSD: getcaptest.c,v 1.1 2006/03/10 05:28:57 ray Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Written by Raymond Lai <ray@cyth.net>. | ||
5 | * Public domain. | ||
6 | */ | ||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | |||
11 | int | ||
12 | main(int argc, char *argv[]) | ||
13 | { | ||
14 | char *buf, *db_array[2]; | ||
15 | |||
16 | if (argc != 2) | ||
17 | return (1); | ||
18 | |||
19 | db_array[0] = argv[1]; | ||
20 | db_array[1] = NULL; | ||
21 | |||
22 | while (cgetnext(&buf, db_array) > 0) | ||
23 | puts(buf); | ||
24 | |||
25 | return (0); | ||
26 | } | ||
diff --git a/src/regress/lib/libc/getcap/shortcap.in b/src/regress/lib/libc/getcap/shortcap.in new file mode 100644 index 0000000000..573541ac97 --- /dev/null +++ b/src/regress/lib/libc/getcap/shortcap.in | |||
@@ -0,0 +1 @@ | |||
0 | |||
diff --git a/src/regress/lib/libc/getopt_long/Makefile b/src/regress/lib/libc/getopt_long/Makefile new file mode 100644 index 0000000000..13a187e190 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/Makefile | |||
@@ -0,0 +1,32 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/12/08 19:25:08 millert Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=getopt_long_test | ||
5 | CLEANFILES+=test.out | ||
6 | |||
7 | # test getopt_long and getopt_long_only | ||
8 | run-regress-${PROG}: ${PROG} | ||
9 | @( test -n "$$POSIXLY_CORRECT" && unset POSIXLY_CORRECT; \ | ||
10 | test -n "$$LONG_ONLY" && unset LONG_ONLY; \ | ||
11 | ./${PROG} myfile --force -f infile -9 ; \ | ||
12 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
13 | ./${PROG} -1bfast - ; \ | ||
14 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
15 | export POSIXLY_CORRECT=1 ; \ | ||
16 | ./${PROG} myfile --force -f infile -9 ; \ | ||
17 | ./${PROG} onefile twofile --best -Williterate -i foo.in threefile ; \ | ||
18 | ./${PROG} -1bfast - ; \ | ||
19 | ./${PROG} --fast --drinking=guiness -i foo.in somefile ; \ | ||
20 | unset POSIXLY_CORRECT ; export LONG_ONLY=1 ; \ | ||
21 | ./${PROG} myfile -force -f infile -9 ; \ | ||
22 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
23 | ./${PROG} -1bfast - ; \ | ||
24 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ; \ | ||
25 | export POSIXLY_CORRECT=1 ; \ | ||
26 | ./${PROG} myfile -force -f infile -9 ; \ | ||
27 | ./${PROG} onefile twofile -best -Williterate -i foo.in threefile ; \ | ||
28 | ./${PROG} -1bfast - ; \ | ||
29 | ./${PROG} --fast -drinking=guiness -i foo.in somefile ) >test.out 2>&1 | ||
30 | cmp -s ${.OBJDIR}/test.out ${.CURDIR}/test.ok | ||
31 | |||
32 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt_long/getopt_long_test.c b/src/regress/lib/libc/getopt_long/getopt_long_test.c new file mode 100644 index 0000000000..9f6f603702 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/getopt_long_test.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | * | ||
16 | * Sponsored in part by the Defense Advanced Research Projects | ||
17 | * Agency (DARPA) and Air Force Research Laboratory, Air Force | ||
18 | * Materiel Command, USAF, under agreement number F39502-99-1-0512. | ||
19 | */ | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <getopt.h> | ||
24 | |||
25 | /* | ||
26 | * Simple getopt_long() and getopt_long_only() excerciser. | ||
27 | * ENVIRONMENT: | ||
28 | * LONG_ONLY : use getopt_long_only() (default is getopt_long()) | ||
29 | * POSIXLY_CORRECT : don't permute args | ||
30 | */ | ||
31 | |||
32 | int | ||
33 | main(int argc, char **argv) | ||
34 | { | ||
35 | int ch, idx, goggles; | ||
36 | int (*gl)(int, char * const *, const char *, const struct option *, int *); | ||
37 | struct option longopts[] = { | ||
38 | { "force", no_argument, 0, 0 }, | ||
39 | { "fast", no_argument, 0, '1' }, | ||
40 | { "best", no_argument, 0, '9' }, | ||
41 | { "input", required_argument, 0, 'i' }, | ||
42 | { "illiterate", no_argument, 0, 0 }, | ||
43 | { "drinking", required_argument, &goggles, 42 }, | ||
44 | { "help", no_argument, 0, 'h' }, | ||
45 | { 0, 0, 0, 0 }, | ||
46 | }; | ||
47 | |||
48 | if (getenv("LONG_ONLY")) { | ||
49 | gl = getopt_long_only; | ||
50 | printf("getopt_long_only"); | ||
51 | } else { | ||
52 | gl = getopt_long; | ||
53 | printf("getopt_long"); | ||
54 | } | ||
55 | if (getenv("POSIXLY_CORRECT")) | ||
56 | printf(" (POSIXLY_CORRECT)"); | ||
57 | printf(": "); | ||
58 | for (idx = 1; idx < argc; idx++) | ||
59 | printf("%s ", argv[idx]); | ||
60 | printf("\n"); | ||
61 | |||
62 | goggles = 0; | ||
63 | for (;;) { | ||
64 | idx = -1; | ||
65 | ch = gl(argc, argv, "19bf:i:hW;-", longopts, &idx); | ||
66 | if (ch == -1) | ||
67 | break; | ||
68 | switch (ch) { | ||
69 | case 0: | ||
70 | case '1': | ||
71 | case '9': | ||
72 | case 'h': | ||
73 | case 'b': | ||
74 | case '-': | ||
75 | if (idx != -1) { | ||
76 | if (goggles == 42) | ||
77 | printf("option %s, arg %s\n", | ||
78 | longopts[idx].name, optarg); | ||
79 | else | ||
80 | printf("option %s\n", | ||
81 | longopts[idx].name); | ||
82 | } else | ||
83 | printf("option %c\n", ch); | ||
84 | break; | ||
85 | case 'f': | ||
86 | case 'i': | ||
87 | if (idx != -1) | ||
88 | printf("option %s, arg %s\n", | ||
89 | longopts[idx].name, optarg); | ||
90 | else | ||
91 | printf("option %c, arg %s\n", ch, optarg); | ||
92 | break; | ||
93 | |||
94 | case '?': | ||
95 | break; | ||
96 | |||
97 | default: | ||
98 | printf("unexpected return value: %c\n", ch); | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | argc -= optind; | ||
103 | argv += optind; | ||
104 | |||
105 | if (argc > 0) { | ||
106 | printf("remaining ARGV: "); | ||
107 | while (argc--) | ||
108 | printf("%s ", *argv++); | ||
109 | printf("\n"); | ||
110 | } | ||
111 | printf("\n"); | ||
112 | |||
113 | exit (0); | ||
114 | } | ||
diff --git a/src/regress/lib/libc/getopt_long/test.ok b/src/regress/lib/libc/getopt_long/test.ok new file mode 100644 index 0000000000..9782087f40 --- /dev/null +++ b/src/regress/lib/libc/getopt_long/test.ok | |||
@@ -0,0 +1,84 @@ | |||
1 | getopt_long: myfile --force -f infile -9 | ||
2 | option force | ||
3 | option f, arg infile | ||
4 | option 9 | ||
5 | remaining ARGV: myfile | ||
6 | |||
7 | getopt_long: onefile twofile --best -Williterate -i foo.in threefile | ||
8 | option best | ||
9 | option illiterate | ||
10 | option i, arg foo.in | ||
11 | remaining ARGV: onefile twofile threefile | ||
12 | |||
13 | getopt_long: -1bfast - | ||
14 | option 1 | ||
15 | option b | ||
16 | option f, arg ast | ||
17 | option - | ||
18 | |||
19 | getopt_long: --fast --drinking=guiness -i foo.in somefile | ||
20 | option fast | ||
21 | option drinking, arg guiness | ||
22 | option i, arg foo.in | ||
23 | remaining ARGV: somefile | ||
24 | |||
25 | getopt_long (POSIXLY_CORRECT): myfile --force -f infile -9 | ||
26 | remaining ARGV: myfile --force -f infile -9 | ||
27 | |||
28 | getopt_long (POSIXLY_CORRECT): onefile twofile --best -Williterate -i foo.in threefile | ||
29 | remaining ARGV: onefile twofile --best -Williterate -i foo.in threefile | ||
30 | |||
31 | getopt_long (POSIXLY_CORRECT): -1bfast - | ||
32 | option 1 | ||
33 | option b | ||
34 | option f, arg ast | ||
35 | option - | ||
36 | |||
37 | getopt_long (POSIXLY_CORRECT): --fast --drinking=guiness -i foo.in somefile | ||
38 | option fast | ||
39 | option drinking, arg guiness | ||
40 | option i, arg foo.in | ||
41 | remaining ARGV: somefile | ||
42 | |||
43 | getopt_long_only: myfile -force -f infile -9 | ||
44 | option force | ||
45 | option f, arg infile | ||
46 | option 9 | ||
47 | remaining ARGV: myfile | ||
48 | |||
49 | getopt_long_only: onefile twofile -best -Williterate -i foo.in threefile | ||
50 | option best | ||
51 | option illiterate | ||
52 | option i, arg foo.in | ||
53 | remaining ARGV: onefile twofile threefile | ||
54 | |||
55 | getopt_long_only: -1bfast - | ||
56 | option 1 | ||
57 | option b | ||
58 | option fast | ||
59 | option - | ||
60 | |||
61 | getopt_long_only: --fast -drinking=guiness -i foo.in somefile | ||
62 | option fast | ||
63 | option drinking, arg guiness | ||
64 | option i, arg foo.in | ||
65 | remaining ARGV: somefile | ||
66 | |||
67 | getopt_long_only (POSIXLY_CORRECT): myfile -force -f infile -9 | ||
68 | remaining ARGV: myfile -force -f infile -9 | ||
69 | |||
70 | getopt_long_only (POSIXLY_CORRECT): onefile twofile -best -Williterate -i foo.in threefile | ||
71 | remaining ARGV: onefile twofile -best -Williterate -i foo.in threefile | ||
72 | |||
73 | getopt_long_only (POSIXLY_CORRECT): -1bfast - | ||
74 | option 1 | ||
75 | option b | ||
76 | option fast | ||
77 | option - | ||
78 | |||
79 | getopt_long_only (POSIXLY_CORRECT): --fast -drinking=guiness -i foo.in somefile | ||
80 | option fast | ||
81 | option drinking, arg guiness | ||
82 | option i, arg foo.in | ||
83 | remaining ARGV: somefile | ||
84 | |||
diff --git a/src/regress/lib/libc/glob/Makefile b/src/regress/lib/libc/glob/Makefile new file mode 100644 index 0000000000..b3f9567833 --- /dev/null +++ b/src/regress/lib/libc/glob/Makefile | |||
@@ -0,0 +1,16 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2011/05/01 04:25:40 guenther Exp $ | ||
2 | |||
3 | PROG= globtest | ||
4 | |||
5 | run-regress-${PROG}: | ||
6 | mkdir -m 755 -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` | ||
7 | umask 022; touch `cat ${.CURDIR}/files` | ||
8 | chmod 0755 `grep '/r[^/]*$$' ${.CURDIR}/files` | ||
9 | chmod 0444 `grep '/s[^/]*$$' ${.CURDIR}/files` | ||
10 | chmod 0711 `grep '/t[^/]*$$' ${.CURDIR}/files` | ||
11 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
12 | |||
13 | clean: | ||
14 | rm -rf fake ${PROG} ${OBJS} *.core | ||
15 | |||
16 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/glob/files b/src/regress/lib/libc/glob/files new file mode 100644 index 0000000000..c5e92aacd5 --- /dev/null +++ b/src/regress/lib/libc/glob/files | |||
@@ -0,0 +1,47 @@ | |||
1 | fake/bin/[ | ||
2 | fake/bin/cat | ||
3 | fake/bin/chgrp | ||
4 | fake/bin/chio | ||
5 | fake/bin/chmod | ||
6 | fake/bin/cksum | ||
7 | fake/bin/cp | ||
8 | fake/bin/cpio | ||
9 | fake/bin/csh | ||
10 | fake/bin/date | ||
11 | fake/bin/dd | ||
12 | fake/bin/df | ||
13 | fake/bin/domainname | ||
14 | fake/bin/echo | ||
15 | fake/bin/ed | ||
16 | fake/bin/eject | ||
17 | fake/bin/expr | ||
18 | fake/bin/hostname | ||
19 | fake/bin/kill | ||
20 | fake/bin/ksh | ||
21 | fake/bin/ln | ||
22 | fake/bin/ls | ||
23 | fake/bin/md5 | ||
24 | fake/bin/mkdir | ||
25 | fake/bin/mt | ||
26 | fake/bin/mv | ||
27 | fake/bin/pax | ||
28 | fake/bin/ps | ||
29 | fake/bin/pwd | ||
30 | fake/bin/rcp | ||
31 | fake/bin/rksh | ||
32 | fake/bin/rm | ||
33 | fake/bin/rmail | ||
34 | fake/bin/rmd160 | ||
35 | fake/bin/rmdir | ||
36 | fake/bin/sh | ||
37 | fake/bin/sha1 | ||
38 | fake/bin/sha256 | ||
39 | fake/bin/sha384 | ||
40 | fake/bin/sha512 | ||
41 | fake/bin/sleep | ||
42 | fake/bin/stty | ||
43 | fake/bin/sum | ||
44 | fake/bin/sync | ||
45 | fake/bin/systrace | ||
46 | fake/bin/tar | ||
47 | fake/bin/test | ||
diff --git a/src/regress/lib/libc/glob/globtest.c b/src/regress/lib/libc/glob/globtest.c new file mode 100644 index 0000000000..325a7750f0 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* $OpenBSD: globtest.c,v 1.3 2011/01/07 19:45:44 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <glob.h> | ||
9 | #include <stdio.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | #define MAX_RESULTS 256 | ||
14 | |||
15 | struct gl_entry { | ||
16 | int flags; | ||
17 | int nresults; | ||
18 | char pattern[1024]; | ||
19 | char *results[MAX_RESULTS]; | ||
20 | mode_t modes[MAX_RESULTS]; | ||
21 | }; | ||
22 | |||
23 | int test_glob(struct gl_entry *); | ||
24 | |||
25 | int | ||
26 | main(int argc, char **argv) | ||
27 | { | ||
28 | FILE *fp = stdin; | ||
29 | char *buf, *cp; | ||
30 | int errors = 0, lineno, mode; | ||
31 | struct gl_entry entry; | ||
32 | size_t len; | ||
33 | |||
34 | if (argc > 1) { | ||
35 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
36 | err(1, "%s", argv[1]); | ||
37 | } | ||
38 | |||
39 | /* | ||
40 | * Read in test file, which is formatted thusly: | ||
41 | * | ||
42 | * [pattern] <flags> | ||
43 | * result1 [mode] | ||
44 | * result2 [mode] | ||
45 | * result3 [mode] | ||
46 | * ... | ||
47 | * | ||
48 | */ | ||
49 | lineno = 0; | ||
50 | memset(&entry, 0, sizeof(entry)); | ||
51 | while ((buf = fgetln(fp, &len)) != NULL) { | ||
52 | lineno++; | ||
53 | if (buf[len - 1] != '\n') | ||
54 | errx(1, "missing newline at EOF"); | ||
55 | buf[--len] = '\0'; | ||
56 | if (len == 0) | ||
57 | continue; /* blank line */ | ||
58 | |||
59 | if (buf[0] == '[') { | ||
60 | /* check previous pattern */ | ||
61 | if (entry.pattern[0]) | ||
62 | errors += test_glob(&entry); | ||
63 | |||
64 | /* start new entry */ | ||
65 | if ((cp = strrchr(buf + 1, ']')) == NULL) | ||
66 | errx(1, "invalid entry on line %d", lineno); | ||
67 | len = cp - buf - 1; | ||
68 | if (len >= sizeof(entry.pattern)) | ||
69 | errx(1, "pattern too big on line %d", lineno); | ||
70 | memcpy(entry.pattern, buf + 1, len); | ||
71 | entry.pattern[len] = '\0'; | ||
72 | |||
73 | buf = cp + 2; | ||
74 | if (*buf++ != '<') | ||
75 | errx(1, "invalid entry on line %d", lineno); | ||
76 | if ((cp = strchr(buf, '>')) == NULL) | ||
77 | errx(1, "invalid entry on line %d", lineno); | ||
78 | entry.flags = (int)strtol(buf, &cp, 0); | ||
79 | if (*cp != '>' || entry.flags < 0 || entry.flags > 0x4000) | ||
80 | errx(1, "invalid flags: %s", buf); | ||
81 | entry.nresults = 0; | ||
82 | continue; | ||
83 | } | ||
84 | if (!entry.pattern[0]) | ||
85 | errx(1, "missing entry on line %d", lineno); | ||
86 | |||
87 | if (entry.nresults + 1 > MAX_RESULTS) { | ||
88 | errx(1, "too many results for %s, max %d", | ||
89 | entry.pattern, MAX_RESULTS); | ||
90 | } | ||
91 | if ((cp = strchr(buf, ' ')) != NULL) { | ||
92 | *cp++ = '\0'; | ||
93 | mode = strtol(cp, NULL, 8); | ||
94 | } else | ||
95 | mode = -1; | ||
96 | entry.modes[entry.nresults] = (mode_t)mode; | ||
97 | entry.results[entry.nresults++] = strdup(buf); | ||
98 | } | ||
99 | if (entry.pattern[0]) | ||
100 | errors += test_glob(&entry); /* test last pattern */ | ||
101 | exit(errors); | ||
102 | } | ||
103 | |||
104 | int test_glob(struct gl_entry *entry) | ||
105 | { | ||
106 | glob_t gl; | ||
107 | int i = 0; | ||
108 | |||
109 | if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) | ||
110 | errx(1, "glob failed: %s", entry->pattern); | ||
111 | |||
112 | if (gl.gl_matchc != entry->nresults) | ||
113 | goto mismatch; | ||
114 | |||
115 | for (i = 0; i < gl.gl_matchc; i++) { | ||
116 | if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) | ||
117 | goto mismatch; | ||
118 | if ((entry->flags & GLOB_KEEPSTAT) != 0) { | ||
119 | if (entry->modes[i] == -1 || | ||
120 | gl.gl_statv[i] == NULL || | ||
121 | entry->modes[i] != gl.gl_statv[i]->st_mode) | ||
122 | goto badmode; | ||
123 | } | ||
124 | free(entry->results[i]); | ||
125 | } | ||
126 | return (0); | ||
127 | badmode: | ||
128 | warnx("mismatch mode for pattern %s, flags 0x%x, file \"%s\" " | ||
129 | "(found %07o, expected %07o)", entry->pattern, entry->flags, | ||
130 | gl.gl_pathv[i], gl.gl_statv[i] ? gl.gl_statv[i]->st_mode : 0, | ||
131 | entry->modes[i]); | ||
132 | goto cleanup; | ||
133 | mismatch: | ||
134 | warnx("mismatch for pattern %s, flags 0x%x " | ||
135 | "(found \"%s\", expected \"%s\")", entry->pattern, entry->flags, | ||
136 | gl.gl_pathv[i], entry->results[i]); | ||
137 | cleanup: | ||
138 | while (i < gl.gl_matchc) { | ||
139 | free(entry->results[i++]); | ||
140 | } | ||
141 | return (1); | ||
142 | } | ||
diff --git a/src/regress/lib/libc/glob/globtest.in b/src/regress/lib/libc/glob/globtest.in new file mode 100644 index 0000000000..2ae3b4dfb2 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.in | |||
@@ -0,0 +1,116 @@ | |||
1 | [fake/bin/[[:alpha:]]*] <0x0> | ||
2 | fake/bin/cat | ||
3 | fake/bin/chgrp | ||
4 | fake/bin/chio | ||
5 | fake/bin/chmod | ||
6 | fake/bin/cksum | ||
7 | fake/bin/cp | ||
8 | fake/bin/cpio | ||
9 | fake/bin/csh | ||
10 | fake/bin/date | ||
11 | fake/bin/dd | ||
12 | fake/bin/df | ||
13 | fake/bin/domainname | ||
14 | fake/bin/echo | ||
15 | fake/bin/ed | ||
16 | fake/bin/eject | ||
17 | fake/bin/expr | ||
18 | fake/bin/hostname | ||
19 | fake/bin/kill | ||
20 | fake/bin/ksh | ||
21 | fake/bin/ln | ||
22 | fake/bin/ls | ||
23 | fake/bin/md5 | ||
24 | fake/bin/mkdir | ||
25 | fake/bin/mt | ||
26 | fake/bin/mv | ||
27 | fake/bin/pax | ||
28 | fake/bin/ps | ||
29 | fake/bin/pwd | ||
30 | fake/bin/rcp | ||
31 | fake/bin/rksh | ||
32 | fake/bin/rm | ||
33 | fake/bin/rmail | ||
34 | fake/bin/rmd160 | ||
35 | fake/bin/rmdir | ||
36 | fake/bin/sh | ||
37 | fake/bin/sha1 | ||
38 | fake/bin/sha256 | ||
39 | fake/bin/sha384 | ||
40 | fake/bin/sha512 | ||
41 | fake/bin/sleep | ||
42 | fake/bin/stty | ||
43 | fake/bin/sum | ||
44 | fake/bin/sync | ||
45 | fake/bin/systrace | ||
46 | fake/bin/tar | ||
47 | fake/bin/test | ||
48 | |||
49 | [fake/bin/[[:alpha:]]*] <0x4000> | ||
50 | fake/bin/cat 0100644 | ||
51 | fake/bin/chgrp 0100644 | ||
52 | fake/bin/chio 0100644 | ||
53 | fake/bin/chmod 0100644 | ||
54 | fake/bin/cksum 0100644 | ||
55 | fake/bin/cp 0100644 | ||
56 | fake/bin/cpio 0100644 | ||
57 | fake/bin/csh 0100644 | ||
58 | fake/bin/date 0100644 | ||
59 | fake/bin/dd 0100644 | ||
60 | fake/bin/df 0100644 | ||
61 | fake/bin/domainname 0100644 | ||
62 | fake/bin/echo 0100644 | ||
63 | fake/bin/ed 0100644 | ||
64 | fake/bin/eject 0100644 | ||
65 | fake/bin/expr 0100644 | ||
66 | fake/bin/hostname 0100644 | ||
67 | fake/bin/kill 0100644 | ||
68 | fake/bin/ksh 0100644 | ||
69 | fake/bin/ln 0100644 | ||
70 | fake/bin/ls 0100644 | ||
71 | fake/bin/md5 0100644 | ||
72 | fake/bin/mkdir 0100644 | ||
73 | fake/bin/mt 0100644 | ||
74 | fake/bin/mv 0100644 | ||
75 | fake/bin/pax 0100644 | ||
76 | fake/bin/ps 0100644 | ||
77 | fake/bin/pwd 0100644 | ||
78 | fake/bin/rcp 0100755 | ||
79 | fake/bin/rksh 0100755 | ||
80 | fake/bin/rm 0100755 | ||
81 | fake/bin/rmail 0100755 | ||
82 | fake/bin/rmd160 0100755 | ||
83 | fake/bin/rmdir 0100755 | ||
84 | fake/bin/sh 0100444 | ||
85 | fake/bin/sha1 0100444 | ||
86 | fake/bin/sha256 0100444 | ||
87 | fake/bin/sha384 0100444 | ||
88 | fake/bin/sha512 0100444 | ||
89 | fake/bin/sleep 0100444 | ||
90 | fake/bin/stty 0100444 | ||
91 | fake/bin/sum 0100444 | ||
92 | fake/bin/sync 0100444 | ||
93 | fake/bin/systrace 0100444 | ||
94 | fake/bin/tar 0100711 | ||
95 | fake/bin/test 0100711 | ||
96 | |||
97 | [fake/bin/rm{,dir,ail}] <0x80> | ||
98 | fake/bin/rm | ||
99 | fake/bin/rmdir | ||
100 | fake/bin/rmail | ||
101 | |||
102 | [fake/bin/sha[[:digit:]]] <0x0> | ||
103 | fake/bin/sha1 | ||
104 | |||
105 | [fake/bin/sha[[:digit:]]*] <0x0> | ||
106 | fake/bin/sha1 | ||
107 | fake/bin/sha256 | ||
108 | fake/bin/sha384 | ||
109 | fake/bin/sha512 | ||
110 | |||
111 | [fake/bin/ca[a-z]] <0x0> | ||
112 | fake/bin/cat | ||
113 | |||
114 | [fake/b[a-z]*] <0x4000> | ||
115 | fake/bin 0040755 | ||
116 | |||
diff --git a/src/regress/lib/libc/hsearch/Makefile b/src/regress/lib/libc/hsearch/Makefile new file mode 100644 index 0000000000..cddc8ac0c4 --- /dev/null +++ b/src/regress/lib/libc/hsearch/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/06/24 04:33:07 millert Exp $ | ||
2 | |||
3 | PROG= hsearchtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/hsearch/hsearchtest.c b/src/regress/lib/libc/hsearch/hsearchtest.c new file mode 100644 index 0000000000..8659ef7e77 --- /dev/null +++ b/src/regress/lib/libc/hsearch/hsearchtest.c | |||
@@ -0,0 +1,122 @@ | |||
1 | /* $OpenBSD: hsearchtest.c,v 1.2 2009/10/27 23:59:32 deraadt Exp $ */ | ||
2 | /* $NetBSD: hsearchtest.c,v 1.5 2003/07/26 19:38:46 salo Exp $ */ | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 2001 Christopher G. Demetriou | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * 3. All advertising materials mentioning features or use of this software | ||
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed for the | ||
19 | * NetBSD Project. See http://www.NetBSD.org/ for | ||
20 | * information about NetBSD. | ||
21 | * 4. The name of the author may not be used to endorse or promote products | ||
22 | * derived from this software without specific prior written permission. | ||
23 | * | ||
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
34 | * | ||
35 | * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> | ||
36 | */ | ||
37 | |||
38 | /* | ||
39 | * Test program for hsearch() et al. | ||
40 | */ | ||
41 | |||
42 | #include <search.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <stdio.h> | ||
45 | #include <string.h> | ||
46 | |||
47 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)) | ||
48 | |||
49 | static void | ||
50 | testfail(const char *file, unsigned long line, const char *expression) | ||
51 | { | ||
52 | |||
53 | fprintf(stderr, "TEST FAILED: %s: file %s, line %ld\n", | ||
54 | expression, file, line); | ||
55 | exit(1); | ||
56 | } | ||
57 | |||
58 | int | ||
59 | main(int argc, char *argv[]) | ||
60 | { | ||
61 | ENTRY e, *ep, *ep2; | ||
62 | int created_ok; | ||
63 | char ch[2]; | ||
64 | int i; | ||
65 | |||
66 | created_ok = hcreate(16); | ||
67 | TEST(created_ok); | ||
68 | |||
69 | /* ch[1] should be constant from here on down. */ | ||
70 | ch[1] = '\0'; | ||
71 | |||
72 | /* Basic insertions. Check enough that there'll be collisions. */ | ||
73 | for (i = 0; i < 26; i++) { | ||
74 | ch[0] = 'a' + i; | ||
75 | e.key = strdup(ch); /* ptr to provided key is kept! */ | ||
76 | TEST(e.key != NULL); | ||
77 | e.data = (void *)(long)i; | ||
78 | ep = hsearch(e, ENTER); | ||
79 | TEST(ep != NULL); | ||
80 | TEST(strcmp(ep->key, ch) == 0); | ||
81 | TEST((long)ep->data == i); | ||
82 | } | ||
83 | |||
84 | /* e.key should be constant from here on down. */ | ||
85 | e.key = ch; | ||
86 | |||
87 | /* Basic lookups. */ | ||
88 | for (i = 0; i < 26; i++) { | ||
89 | ch[0] = 'a' + i; | ||
90 | ep = hsearch(e, FIND); | ||
91 | TEST(ep != NULL); | ||
92 | TEST(strcmp(ep->key, ch) == 0); | ||
93 | TEST((long)ep->data == i); | ||
94 | } | ||
95 | |||
96 | /* Check duplicate entry. Should _not_ overwrite existing data. */ | ||
97 | ch[0] = 'a'; | ||
98 | e.data = (void *)(long)12345; | ||
99 | ep = hsearch(e, FIND); | ||
100 | TEST(ep != NULL); | ||
101 | TEST(strcmp(ep->key, ch) == 0); | ||
102 | TEST((long)ep->data == 0); | ||
103 | |||
104 | /* Check for something that's not there. */ | ||
105 | ch[0] = 'A'; | ||
106 | ep = hsearch(e, FIND); | ||
107 | TEST(ep == NULL); | ||
108 | |||
109 | /* Check two at once. */ | ||
110 | ch[0] = 'a'; | ||
111 | ep = hsearch(e, FIND); | ||
112 | ch[0] = 'b'; | ||
113 | ep2 = hsearch(e, FIND); | ||
114 | TEST(ep != NULL); | ||
115 | TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); | ||
116 | TEST(ep2 != NULL); | ||
117 | TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); | ||
118 | |||
119 | hdestroy(); | ||
120 | |||
121 | exit(0); | ||
122 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/Makefile b/src/regress/lib/libc/ieeefp/Makefile index 4e2e517b03..89ff51a2e7 100644 --- a/src/regress/lib/libc/ieeefp/Makefile +++ b/src/regress/lib/libc/ieeefp/Makefile | |||
@@ -1,12 +1,7 @@ | |||
1 | # $NetBSD: Makefile,v 1.4 1995/10/03 21:59:36 phil Exp $ | 1 | # $OpenBSD: Makefile,v 1.6 2004/01/15 18:53:23 miod Exp $ |
2 | # $NetBSD: Makefile,v 1.5 1996/04/09 16:54:18 phil Exp $ | ||
2 | 3 | ||
3 | .if ${MACHINE} == "pc532" | 4 | SUBDIR+= except inf infinity round |
4 | SUBDIR+= round | ||
5 | .else | ||
6 | SUBDIR+= except round | ||
7 | .endif | ||
8 | |||
9 | regress: _SUBDIRUSE | ||
10 | 5 | ||
11 | install: | 6 | install: |
12 | 7 | ||
diff --git a/src/regress/lib/libc/ieeefp/except/Makefile b/src/regress/lib/libc/ieeefp/except/Makefile index 91f24f15f6..205331548f 100644 --- a/src/regress/lib/libc/ieeefp/except/Makefile +++ b/src/regress/lib/libc/ieeefp/except/Makefile | |||
@@ -1,12 +1,19 @@ | |||
1 | # $NetBSD: Makefile,v 1.1 1995/04/26 00:27:25 jtc Exp $ | 1 | # $OpenBSD: Makefile,v 1.5 2004/07/22 19:29:42 kettenis Exp $ |
2 | 2 | ||
3 | PROG= except | 3 | PROG=except |
4 | SRCS= except.c | ||
5 | NOMAN= | ||
6 | 4 | ||
7 | install: | 5 | REGRESS_TARGETS+= fltdiv fltinv fltovf fltund |
8 | 6 | ||
9 | regress: ${PROG} | 7 | fltdiv: ${PROG} |
10 | ./${PROG} | 8 | ./${PROG} fltdiv |
11 | 9 | ||
12 | .include <bsd.prog.mk> | 10 | fltinv: ${PROG} |
11 | ./${PROG} fltinv | ||
12 | |||
13 | fltovf: ${PROG} | ||
14 | ./${PROG} fltovf | ||
15 | |||
16 | fltund: ${PROG} | ||
17 | ./${PROG} fltund | ||
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/except/except.c b/src/regress/lib/libc/ieeefp/except/except.c index 0ffdcdd468..cc3dcf8e44 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
@@ -1,21 +1,48 @@ | |||
1 | /* $OpenBSD: except.c,v 1.12 2010/05/08 19:16:33 naddy Exp $ */ | ||
2 | |||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
1 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
2 | #include <signal.h> | 8 | #include <signal.h> |
3 | #include <assert.h> | 9 | #include <assert.h> |
4 | #include <ieeefp.h> | 10 | #include <ieeefp.h> |
5 | #include <float.h> | 11 | #include <float.h> |
12 | #include <err.h> | ||
6 | 13 | ||
7 | void sigfpe(); | 14 | volatile sig_atomic_t signal_status; |
8 | volatile sig_atomic_t signal_cought; | ||
9 | 15 | ||
10 | static volatile const double one = 1.0; | 16 | volatile const double one = 1.0; |
11 | static volatile const double zero = 0.0; | 17 | volatile const double zero = 0.0; |
12 | static volatile const double huge = DBL_MAX; | 18 | volatile const double huge = DBL_MAX; |
13 | static volatile const double tiny = DBL_MIN; | 19 | volatile const double tiny = DBL_MIN; |
14 | 20 | ||
15 | main() | 21 | void |
22 | sigfpe(int sig, siginfo_t *si, void *v) | ||
16 | { | 23 | { |
24 | char buf[132]; | ||
25 | |||
26 | if (si) { | ||
27 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
28 | si->si_addr, si->si_code); | ||
29 | write(1, buf, strlen(buf)); | ||
30 | } | ||
31 | _exit(signal_status); | ||
32 | } | ||
33 | |||
34 | |||
35 | int | ||
36 | main(int argc, char *argv[]) | ||
37 | { | ||
38 | struct sigaction sa; | ||
17 | volatile double x; | 39 | volatile double x; |
18 | 40 | ||
41 | if (argc != 2) { | ||
42 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
43 | exit(1); | ||
44 | } | ||
45 | |||
19 | /* | 46 | /* |
20 | * check to make sure that all exceptions are masked and | 47 | * check to make sure that all exceptions are masked and |
21 | * that the accumulated exception status is clear. | 48 | * that the accumulated exception status is clear. |
@@ -23,65 +50,61 @@ main() | |||
23 | assert(fpgetmask() == 0); | 50 | assert(fpgetmask() == 0); |
24 | assert(fpgetsticky() == 0); | 51 | assert(fpgetsticky() == 0); |
25 | 52 | ||
26 | /* set up signal handler */ | 53 | memset(&sa, 0, sizeof(sa)); |
27 | signal (SIGFPE, sigfpe); | 54 | sa.sa_sigaction = sigfpe; |
28 | signal_cought = 0; | 55 | sa.sa_flags = SA_SIGINFO; |
29 | 56 | sigaction(SIGFPE, &sa, NULL); | |
30 | /* trip divide by zero */ | 57 | signal_status = 1; |
31 | x = one / zero; | ||
32 | assert (fpgetsticky() & FP_X_DZ); | ||
33 | assert (signal_cought == 0); | ||
34 | fpsetsticky(0); | ||
35 | |||
36 | /* trip invalid operation */ | ||
37 | x = zero / zero; | ||
38 | assert (fpgetsticky() & FP_X_INV); | ||
39 | assert (signal_cought == 0); | ||
40 | fpsetsticky(0); | ||
41 | |||
42 | /* trip overflow */ | ||
43 | x = huge * huge; | ||
44 | assert (fpgetsticky() & FP_X_OFL); | ||
45 | assert (signal_cought == 0); | ||
46 | fpsetsticky(0); | ||
47 | |||
48 | /* trip underflow */ | ||
49 | x = tiny * tiny; | ||
50 | assert (fpgetsticky() & FP_X_UFL); | ||
51 | assert (signal_cought == 0); | ||
52 | fpsetsticky(0); | ||
53 | |||
54 | #if 0 | ||
55 | /* unmask and then trip divide by zero */ | ||
56 | fpsetmask(FP_X_DZ); | ||
57 | x = one / zero; | ||
58 | assert (signal_cought == 1); | ||
59 | signal_cought = 0; | ||
60 | |||
61 | /* unmask and then trip invalid operation */ | ||
62 | fpsetmask(FP_X_INV); | ||
63 | x = zero / zero; | ||
64 | assert (signal_cought == 1); | ||
65 | signal_cought = 0; | ||
66 | |||
67 | /* unmask and then trip overflow */ | ||
68 | fpsetmask(FP_X_OFL); | ||
69 | x = huge * huge; | ||
70 | assert (signal_cought == 1); | ||
71 | signal_cought = 0; | ||
72 | |||
73 | /* unmask and then trip underflow */ | ||
74 | fpsetmask(FP_X_UFL); | ||
75 | x = tiny * tiny; | ||
76 | assert (signal_cought == 1); | ||
77 | signal_cought = 0; | ||
78 | #endif | ||
79 | |||
80 | exit(0); | ||
81 | } | ||
82 | 58 | ||
83 | void | 59 | if (strcmp(argv[1], "fltdiv") == 0) { |
84 | sigfpe() | 60 | /* trip divide by zero */ |
85 | { | 61 | x = one / zero; |
86 | signal_cought = 1; | 62 | assert(fpgetsticky() & FP_X_DZ); |
63 | fpsetsticky(0); | ||
64 | |||
65 | /* and now unmask to get a signal */ | ||
66 | signal_status = 0; | ||
67 | fpsetmask(FP_X_DZ); | ||
68 | x = one / zero; | ||
69 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
70 | /* trip invalid operation */ | ||
71 | x = zero / zero; | ||
72 | assert(fpgetsticky() & FP_X_INV); | ||
73 | fpsetsticky(0); | ||
74 | |||
75 | /* and now unmask to get a signal */ | ||
76 | signal_status = 0; | ||
77 | fpsetmask(FP_X_INV); | ||
78 | x = zero / zero; | ||
79 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
80 | /* trip overflow */ | ||
81 | x = huge * huge; | ||
82 | assert(fpgetsticky() & FP_X_OFL); | ||
83 | fpsetsticky(0); | ||
84 | |||
85 | /* and now unmask to get a signal */ | ||
86 | signal_status = 0; | ||
87 | fpsetmask(FP_X_OFL); | ||
88 | x = huge * huge; | ||
89 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
90 | /* trip underflow */ | ||
91 | x = tiny * tiny; | ||
92 | assert(fpgetsticky() & FP_X_UFL); | ||
93 | fpsetsticky(0); | ||
94 | |||
95 | /* and now unmask to get a signal */ | ||
96 | signal_status = 0; | ||
97 | fpsetmask(FP_X_UFL); | ||
98 | x = tiny * tiny; | ||
99 | } else { | ||
100 | errx(1, "unrecognized condition %s", argv[1]); | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | * attempt to trigger the exception on machines where | ||
105 | * floating-point exceptions are deferred. | ||
106 | */ | ||
107 | x = one * one; | ||
108 | |||
109 | errx(1, "signal wasn't caught"); | ||
87 | } | 110 | } |
diff --git a/src/regress/lib/libc/ieeefp/inf/Makefile b/src/regress/lib/libc/ieeefp/inf/Makefile new file mode 100644 index 0000000000..b9a50e0ce6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 17:22:16 pvalchev Exp $ | ||
2 | |||
3 | PROG= inf | ||
4 | SRCS= inf.c | ||
5 | |||
6 | LDADD+= -lm | ||
7 | DPADD+= ${LIBM} | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/inf/inf.c b/src/regress/lib/libc/ieeefp/inf/inf.c new file mode 100644 index 0000000000..a1956145a6 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/inf/inf.c | |||
@@ -0,0 +1,16 @@ | |||
1 | /* $OpenBSD: inf.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Peter Valchev <pvalchev@openbsd.org> Public Domain, 2002. | ||
5 | */ | ||
6 | |||
7 | #include <math.h> | ||
8 | |||
9 | int | ||
10 | main(int argc, char *argv[]) | ||
11 | { | ||
12 | if (isinf(HUGE_VAL)) | ||
13 | return 0; | ||
14 | |||
15 | return 1; | ||
16 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/Makefile b/src/regress/lib/libc/ieeefp/infinity/Makefile new file mode 100644 index 0000000000..ac102d8a63 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/Makefile | |||
@@ -0,0 +1,22 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2004/01/16 19:34:37 miod Exp $ | ||
2 | |||
3 | PROG= infinity | ||
4 | |||
5 | DPADD+= ${LIBM} | ||
6 | LDADD+= -lm | ||
7 | |||
8 | REGRESS_TARGETS+= add mult neg pumpkin | ||
9 | |||
10 | add: ${PROG} | ||
11 | ./${PROG} -a | ||
12 | |||
13 | mult: ${PROG} | ||
14 | ./${PROG} -m | ||
15 | |||
16 | neg: ${PROG} | ||
17 | ./${PROG} -n | ||
18 | |||
19 | pumpkin: ${PROG} | ||
20 | ./${PROG} -p | ||
21 | |||
22 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/infinity/infinity.c b/src/regress/lib/libc/ieeefp/infinity/infinity.c new file mode 100644 index 0000000000..3b1b71ec90 --- /dev/null +++ b/src/regress/lib/libc/ieeefp/infinity/infinity.c | |||
@@ -0,0 +1,77 @@ | |||
1 | /* $OpenBSD: infinity.c,v 1.2 2004/01/16 19:34:37 miod Exp $ */ | ||
2 | /* | ||
3 | * Written by Miodrag Vallat, 2004 - Public Domain | ||
4 | * Inspired from Perl's t/op/arith test #134 | ||
5 | */ | ||
6 | |||
7 | #include <math.h> | ||
8 | #include <signal.h> | ||
9 | #include <unistd.h> | ||
10 | |||
11 | void | ||
12 | sigfpe(int signum) | ||
13 | { | ||
14 | /* looks like we don't handle fp overflow correctly... */ | ||
15 | _exit(1); | ||
16 | } | ||
17 | |||
18 | int | ||
19 | main(int argc, char *argv[]) | ||
20 | { | ||
21 | int opt; | ||
22 | double d, two; | ||
23 | int i; | ||
24 | char method = 'a'; | ||
25 | |||
26 | while ((opt = getopt(argc, argv, "amnp")) != -1) | ||
27 | method = (char)opt; | ||
28 | |||
29 | signal(SIGFPE, sigfpe); | ||
30 | |||
31 | switch (method) { | ||
32 | case 'a': | ||
33 | /* try to produce +Inf through addition */ | ||
34 | d = 1.0; | ||
35 | for (i = 2000; i != 0; i--) { | ||
36 | d = d + d; | ||
37 | } | ||
38 | /* result should be _positive_ infinity */ | ||
39 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
40 | return (1); | ||
41 | break; | ||
42 | case 'm': | ||
43 | /* try to produce +Inf through multiplication */ | ||
44 | d = 1.0; | ||
45 | two = 2.0; | ||
46 | for (i = 2000; i != 0; i--) { | ||
47 | d = d * two; | ||
48 | } | ||
49 | /* result should be _positive_ infinity */ | ||
50 | if (!isinf(d) || copysign(1.0, d) < 0.0) | ||
51 | return (1); | ||
52 | break; | ||
53 | case 'n': | ||
54 | /* try to produce -Inf through subtraction */ | ||
55 | d = -1.0; | ||
56 | for (i = 2000; i != 0; i--) { | ||
57 | d = d + d; | ||
58 | } | ||
59 | /* result should be _negative_ infinity */ | ||
60 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
61 | return (1); | ||
62 | break; | ||
63 | case 'p': | ||
64 | /* try to produce -Inf through multiplication */ | ||
65 | d = -1.0; | ||
66 | two = 2.0; | ||
67 | for (i = 2000; i != 0; i--) { | ||
68 | d = d * two; | ||
69 | } | ||
70 | /* result should be _negative_ infinity */ | ||
71 | if (!isinf(d) || copysign(1.0, d) > 0.0) | ||
72 | return (1); | ||
73 | break; | ||
74 | } | ||
75 | |||
76 | return (0); | ||
77 | } | ||
diff --git a/src/regress/lib/libc/ieeefp/round/Makefile b/src/regress/lib/libc/ieeefp/round/Makefile index 571133436c..9ea6dd8c39 100644 --- a/src/regress/lib/libc/ieeefp/round/Makefile +++ b/src/regress/lib/libc/ieeefp/round/Makefile | |||
@@ -1,12 +1,5 @@ | |||
1 | # $NetBSD: Makefile,v 1.1 1995/04/26 00:27:27 jtc Exp $ | 1 | # $OpenBSD: Makefile,v 1.4 2002/02/18 11:25:34 art Exp $ |
2 | 2 | ||
3 | PROG= round | 3 | PROG= round |
4 | SRCS= round.c | ||
5 | NOMAN= | ||
6 | 4 | ||
7 | install: | 5 | .include <bsd.regress.mk> |
8 | |||
9 | regress: ${PROG} | ||
10 | ./${PROG} | ||
11 | |||
12 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/ieeefp/round/round.c b/src/regress/lib/libc/ieeefp/round/round.c index b9fcd9771e..807941ea56 100644 --- a/src/regress/lib/libc/ieeefp/round/round.c +++ b/src/regress/lib/libc/ieeefp/round/round.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */ | ||
1 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ | 2 | /* $NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $ */ |
2 | 3 | ||
3 | /* | 4 | /* |
@@ -11,7 +12,7 @@ | |||
11 | #include <float.h> | 12 | #include <float.h> |
12 | 13 | ||
13 | int | 14 | int |
14 | main() | 15 | main(int argc, char *argv[]) |
15 | { | 16 | { |
16 | /* | 17 | /* |
17 | * This test would be better if it actually performed some | 18 | * This test would be better if it actually performed some |
diff --git a/src/regress/lib/libc/locale/Makefile b/src/regress/lib/libc/locale/Makefile new file mode 100644 index 0000000000..c182172ba2 --- /dev/null +++ b/src/regress/lib/libc/locale/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
2 | |||
3 | SUBDIR+= check_isw | ||
4 | |||
5 | install: | ||
6 | |||
7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/Makefile b/src/regress/lib/libc/locale/check_isw/Makefile new file mode 100644 index 0000000000..0885968fd1 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/Makefile | |||
@@ -0,0 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/11 21:57:02 espie Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=check_isw | ||
5 | |||
6 | run-regress-check_isw: ${PROG} | ||
7 | ./${PROG} >/dev/null | ||
8 | |||
9 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/locale/check_isw/check_isw.c b/src/regress/lib/libc/locale/check_isw/check_isw.c new file mode 100644 index 0000000000..9386267f61 --- /dev/null +++ b/src/regress/lib/libc/locale/check_isw/check_isw.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* $OpenBSD: check_isw.c,v 1.1 2005/08/11 21:57:02 espie Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2005 Marc Espie <espie@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | /* This checks consistency of the isw* functions with the default <ctype> | ||
19 | * functions. | ||
20 | */ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <wchar.h> | ||
26 | #include <wctype.h> | ||
27 | |||
28 | int bad = 0; | ||
29 | |||
30 | void | ||
31 | check_bool(int v1, int v2, char msg) | ||
32 | { | ||
33 | if (!v1 != !v2) { | ||
34 | printf("%c", msg); | ||
35 | bad++; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void | ||
40 | check_value(int v1, int v2, char msg) | ||
41 | { | ||
42 | if (v1 != v2) { | ||
43 | printf("%c", msg); | ||
44 | bad++; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | void | ||
49 | test1() | ||
50 | { | ||
51 | int i; | ||
52 | |||
53 | for (i = 0; i < 256; i++) { | ||
54 | printf(" %02x: ", i); | ||
55 | check_bool(isalnum(i), iswalnum(i), '1'); | ||
56 | check_bool(isalpha(i), iswalpha(i), '2'); | ||
57 | check_bool(isblank(i), iswblank(i), '3'); | ||
58 | check_bool(iscntrl(i), iswcntrl(i), '4'); | ||
59 | check_bool(isdigit(i), iswdigit(i), '5'); | ||
60 | check_bool(isgraph(i), iswgraph(i), '6'); | ||
61 | check_bool(islower(i), iswlower(i), '6'); | ||
62 | check_bool(isprint(i), iswprint(i), '7'); | ||
63 | check_bool(ispunct(i), iswpunct(i), '8'); | ||
64 | check_bool(isspace(i), iswspace(i), '9'); | ||
65 | check_bool(isupper(i), iswupper(i), 'a'); | ||
66 | check_bool(isxdigit(i), iswxdigit(i), 'b'); | ||
67 | check_value(tolower(i), towlower(i), 'c'); | ||
68 | check_value(toupper(i), towupper(i), 'd'); | ||
69 | if (i % 8 == 7) | ||
70 | printf("\n"); | ||
71 | } | ||
72 | printf("%\n"); | ||
73 | } | ||
74 | |||
75 | void | ||
76 | test2() | ||
77 | { | ||
78 | unsigned char *s; | ||
79 | unsigned char *buf; | ||
80 | int i, j; | ||
81 | size_t n; | ||
82 | wchar_t c, d; | ||
83 | mbstate_t state; | ||
84 | |||
85 | s = malloc(256); | ||
86 | if (!s) { | ||
87 | bad++; | ||
88 | return; | ||
89 | } | ||
90 | buf = malloc(MB_CUR_MAX); | ||
91 | if (!buf) { | ||
92 | bad++; | ||
93 | free(s); | ||
94 | return; | ||
95 | } | ||
96 | for (i = 0; i < 256; i++) | ||
97 | s[i] = i+1; | ||
98 | |||
99 | j = 0; | ||
100 | mbrtowc(NULL, NULL, 1, &state); | ||
101 | printf(" %02x: ", 0); | ||
102 | |||
103 | while ((n = mbrtowc(&c, s+j, 256-j, &state)) == 1) { | ||
104 | printf(" %02x: ", s[j]); | ||
105 | check_bool(isalnum(s[j]), iswalnum(c), '1'); | ||
106 | check_bool(isalpha(s[j]), iswalpha(c), '2'); | ||
107 | check_bool(isblank(s[j]), iswblank(c), '3'); | ||
108 | check_bool(iscntrl(s[j]), iswcntrl(c), '4'); | ||
109 | check_bool(isdigit(s[j]), iswdigit(c), '5'); | ||
110 | check_bool(isgraph(s[j]), iswgraph(c), '6'); | ||
111 | check_bool(islower(s[j]), iswlower(c), '6'); | ||
112 | check_bool(isprint(s[j]), iswprint(c), '7'); | ||
113 | check_bool(ispunct(s[j]), iswpunct(c), '8'); | ||
114 | check_bool(isspace(s[j]), iswspace(c), '9'); | ||
115 | check_bool(isupper(s[j]), iswupper(c), 'a'); | ||
116 | check_bool(isxdigit(s[j]), iswxdigit(c), 'b'); | ||
117 | d = towlower(c); | ||
118 | if (wctomb(buf, d) == 1) { | ||
119 | check_value(tolower(s[j]), buf[0], 'c'); | ||
120 | } else { | ||
121 | bad++; | ||
122 | } | ||
123 | d = towupper(c); | ||
124 | if (wctomb(buf, d) == 1) { | ||
125 | check_value(toupper(s[j]), buf[0], 'c'); | ||
126 | } else { | ||
127 | bad++; | ||
128 | } | ||
129 | if (s[j] % 8 == 7) | ||
130 | printf("\n"); | ||
131 | j++; | ||
132 | } | ||
133 | if (n != 0 || j != 255) { | ||
134 | bad++; | ||
135 | } | ||
136 | free(s); | ||
137 | free(buf); | ||
138 | } | ||
139 | |||
140 | |||
141 | int | ||
142 | main() | ||
143 | { | ||
144 | test1(); | ||
145 | test2(); | ||
146 | return bad !=0; | ||
147 | } | ||
diff --git a/src/regress/lib/libc/longjmp/Makefile b/src/regress/lib/libc/longjmp/Makefile new file mode 100644 index 0000000000..825e0f86d9 --- /dev/null +++ b/src/regress/lib/libc/longjmp/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # $OpenBSD: Makefile,v 1.4 2002/09/02 20:01:43 avsm Exp $ | ||
2 | PROG= longjmp | ||
3 | |||
4 | do-longjmp: ${PROG} | ||
5 | ./longjmp | ||
6 | |||
7 | do-_longjmp: ${PROG} | ||
8 | ./longjmp -_ | ||
9 | |||
10 | REGRESS_TARGETS=do-longjmp do-_longjmp | ||
11 | .PHONY: ${REGRESS_TARGETS} | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/longjmp/longjmp.c b/src/regress/lib/libc/longjmp/longjmp.c new file mode 100644 index 0000000000..7dea5bd97c --- /dev/null +++ b/src/regress/lib/libc/longjmp/longjmp.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* $OpenBSD: longjmp.c,v 1.4 2002/02/18 11:27:45 art Exp $ */ | ||
2 | /* | ||
3 | * Artur Grabowski <art@openbsd.org>, 2002 Public Domain. | ||
4 | */ | ||
5 | |||
6 | #include <stdio.h> | ||
7 | #include <stdlib.h> | ||
8 | #include <unistd.h> | ||
9 | #include <setjmp.h> | ||
10 | #include <err.h> | ||
11 | #include <sys/types.h> | ||
12 | #include <sys/time.h> | ||
13 | #include <sys/resource.h> | ||
14 | |||
15 | |||
16 | jmp_buf buf; | ||
17 | |||
18 | /* | ||
19 | * When longjmp is passed the incorrect arg (0), it should translate it into | ||
20 | * something better. | ||
21 | * | ||
22 | * The rlimit is here in case we start spinning. | ||
23 | */ | ||
24 | int | ||
25 | main(int argc, char **argv) | ||
26 | { | ||
27 | struct rlimit rl; | ||
28 | volatile int i, expect; | ||
29 | int (*sj)(jmp_buf); | ||
30 | void (*lj)(jmp_buf, int); | ||
31 | int ch; | ||
32 | extern char *__progname; | ||
33 | |||
34 | sj = setjmp; | ||
35 | lj = longjmp; | ||
36 | |||
37 | while ((ch = getopt(argc, argv, "_")) != -1) { | ||
38 | switch (ch) { | ||
39 | case '_': | ||
40 | sj = _setjmp; | ||
41 | lj = _longjmp; | ||
42 | break; | ||
43 | default: | ||
44 | fprintf(stderr, "Usage: %s [-_]\n", __progname); | ||
45 | exit(1); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | rl.rlim_cur = 2; | ||
50 | rl.rlim_max = 2; | ||
51 | if (setrlimit(RLIMIT_CPU, &rl) < 0) | ||
52 | err(1, "setrlimit"); | ||
53 | |||
54 | expect = 0; | ||
55 | i = (*sj)(buf); | ||
56 | if (i == 0 && expect != 0) | ||
57 | errx(1, "setjmp returns 0 on longjmp(.., 0)"); | ||
58 | if (expect == 0) { | ||
59 | expect = -1; | ||
60 | (*lj)(buf, 0); | ||
61 | } | ||
62 | |||
63 | expect = 0; | ||
64 | i = (*sj)(buf); | ||
65 | if (i != expect) | ||
66 | errx(1, "bad return from setjmp %d/%d", expect, i); | ||
67 | if (expect < 1000) | ||
68 | (*lj)(buf, expect += 2); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
diff --git a/src/regress/lib/libc/malloc/Makefile b/src/regress/lib/libc/malloc/Makefile new file mode 100644 index 0000000000..7c919d1bc2 --- /dev/null +++ b/src/regress/lib/libc/malloc/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2006/04/18 19:04:39 otto Exp $ | ||
2 | |||
3 | SUBDIR+= malloc0test malloc_errno malloc_ulimit1 malloc_ulimit2 | ||
4 | |||
5 | install: | ||
6 | |||
7 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/Makefile b/src/regress/lib/libc/malloc/malloc0test/Makefile new file mode 100644 index 0000000000..8ed8163a79 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc0test/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:09:37 otto Exp $ | ||
2 | |||
3 | PROG= malloc0test | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc0test/malloc0test.c b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c new file mode 100644 index 0000000000..06ff0996ee --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc0test/malloc0test.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* $OpenBSD: malloc0test.c,v 1.5 2008/04/13 00:22:17 djm Exp $ */ | ||
2 | /* | ||
3 | * Public domain. 2001, Theo de Raadt | ||
4 | */ | ||
5 | #include <sys/types.h> | ||
6 | #include <sys/signal.h> | ||
7 | #include <stdio.h> | ||
8 | #include <unistd.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <setjmp.h> | ||
11 | #include <limits.h> | ||
12 | #include <errno.h> | ||
13 | |||
14 | volatile sig_atomic_t got; | ||
15 | jmp_buf jmp; | ||
16 | |||
17 | static void | ||
18 | catch(int signo) | ||
19 | { | ||
20 | got++; | ||
21 | longjmp(jmp, 1); | ||
22 | } | ||
23 | |||
24 | static int | ||
25 | test(char *p, int size) | ||
26 | { | ||
27 | signal(SIGSEGV, catch); | ||
28 | got = 0; | ||
29 | if (setjmp(jmp) == 0) | ||
30 | *p = 0; | ||
31 | if (setjmp(jmp) == 0) | ||
32 | *(p+size-1) = 0; | ||
33 | return (got); | ||
34 | } | ||
35 | |||
36 | char *prot_table[] = { | ||
37 | "unprotected", | ||
38 | "fuckup", | ||
39 | "protected" | ||
40 | }; | ||
41 | |||
42 | #define SIZE 10 | ||
43 | |||
44 | /* | ||
45 | * Do random memory allocations. | ||
46 | * | ||
47 | * For each one, ensure that it is at least 16 bytes in size (that | ||
48 | * being what our current malloc returns for the minsize of an | ||
49 | * object, alignment wise); | ||
50 | * | ||
51 | * For zero-byte allocations, check that they are still aligned. | ||
52 | * | ||
53 | * For each object, ensure that they are correctly protected or not | ||
54 | * protected. | ||
55 | * | ||
56 | * Does not regress test malloc + free combinations ... it should. | ||
57 | */ | ||
58 | int | ||
59 | main(int argc, char *argv[]) | ||
60 | { | ||
61 | caddr_t blob; | ||
62 | int size, tsize; | ||
63 | int prot; | ||
64 | int rval = 0, fuckup = 0; | ||
65 | long limit = 200000, count; | ||
66 | int ch, silent = 0; | ||
67 | char *ep; | ||
68 | extern char *__progname; | ||
69 | |||
70 | while ((ch = getopt(argc, argv, "sn:")) != -1) { | ||
71 | switch (ch) { | ||
72 | case 's': | ||
73 | silent = 1; | ||
74 | break; | ||
75 | case 'n': | ||
76 | errno = 0; | ||
77 | limit = strtol(optarg, &ep, 10); | ||
78 | if (optarg[0] == '\0' || *ep != '\0' || | ||
79 | (errno == ERANGE && | ||
80 | (limit == LONG_MAX || limit == LONG_MIN))) | ||
81 | goto usage; | ||
82 | break; | ||
83 | default: | ||
84 | usage: | ||
85 | fprintf(stderr, "Usage: %s [-s][-n <count>]\n", | ||
86 | __progname); | ||
87 | exit(1); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | if (limit == 0) | ||
92 | limit = LONG_MAX; | ||
93 | |||
94 | for (count = 0; count < limit; count++) { | ||
95 | size = arc4random_uniform(SIZE); | ||
96 | blob = malloc(size); | ||
97 | if (blob == NULL) { | ||
98 | fprintf(stderr, "success: out of memory\n"); | ||
99 | exit(rval); | ||
100 | } | ||
101 | |||
102 | tsize = size == 0 ? 16 : size; | ||
103 | fuckup = 0; | ||
104 | prot = test(blob, tsize); | ||
105 | |||
106 | if (size == 0 && prot < 2) | ||
107 | fuckup = 1; | ||
108 | |||
109 | if (fuckup) { | ||
110 | printf("%8p %6d %20s %10s\n", blob, size, | ||
111 | prot_table[prot], fuckup ? "fuckup" : ""); | ||
112 | rval = 1; | ||
113 | } | ||
114 | |||
115 | if (!silent && count % 100000 == 0 && count != 0) | ||
116 | fprintf(stderr, "count = %ld\n", count); | ||
117 | } | ||
118 | |||
119 | return rval; | ||
120 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/Makefile b/src/regress/lib/libc/malloc/malloc_errno/Makefile new file mode 100644 index 0000000000..73ebe37491 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/07/15 10:06:31 otto Exp $ | ||
2 | |||
3 | PROG= malloc_errno | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c new file mode 100644 index 0000000000..896ea3c900 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_errno/malloc_errno.c | |||
@@ -0,0 +1,46 @@ | |||
1 | /* $OpenBSD: malloc_errno.c,v 1.4 2003/12/25 18:49:57 miod Exp $ */ | ||
2 | /* | ||
3 | * Public domain. 2003, Otto Moerbeek | ||
4 | */ | ||
5 | #include <err.h> | ||
6 | #include <errno.h> | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | |||
10 | static void | ||
11 | testerrno(size_t sz) | ||
12 | { | ||
13 | void *p; | ||
14 | |||
15 | errno = -1; | ||
16 | p = malloc(sz); | ||
17 | |||
18 | if (p == NULL && errno != ENOMEM) | ||
19 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
20 | |||
21 | /* if alloc succeeded, test if errno did not change */ | ||
22 | if (p != NULL && errno != -1) | ||
23 | errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno); | ||
24 | |||
25 | free(p); | ||
26 | } | ||
27 | |||
28 | /* | ||
29 | * Provide some (silly) arguments to malloc(), and check if ERRNO is set | ||
30 | * correctly. | ||
31 | */ | ||
32 | int | ||
33 | main(int argc, char *argv[]) | ||
34 | { | ||
35 | size_t i; | ||
36 | |||
37 | testerrno(1); | ||
38 | testerrno(100000); | ||
39 | testerrno(-1); | ||
40 | testerrno(-1000); | ||
41 | testerrno(-10000); | ||
42 | testerrno(-10000000); | ||
43 | for (i = 0; i < 0x10; i++) | ||
44 | testerrno(i * 0x10000000); | ||
45 | return 0; | ||
46 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile new file mode 100644 index 0000000000..46ced27a98 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:03:30 otto Exp $ | ||
2 | |||
3 | PROG= malloc_ulimit1 | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c new file mode 100644 index 0000000000..99e805e8e1 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit1/malloc_ulimit1.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* $OpenBSD: malloc_ulimit1.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
2 | |||
3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/time.h> | ||
7 | #include <sys/resource.h> | ||
8 | #include <err.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | /* | ||
13 | * This code tries to trigger the case present in -current as of April | ||
14 | * 2006) where the allocation of the region itself succeeds, but the | ||
15 | * page dir entry pages fails. | ||
16 | * This in turn trips a "hole in directories" error. | ||
17 | * Having a large (512M) ulimit -m helps a lot in triggering the | ||
18 | * problem. Note that you may need to run this test multiple times to | ||
19 | * see the error. | ||
20 | */ | ||
21 | |||
22 | #define STARTI 1300 | ||
23 | #define FACTOR 1024 | ||
24 | |||
25 | main() | ||
26 | { | ||
27 | struct rlimit lim; | ||
28 | size_t sz; | ||
29 | int i; | ||
30 | void *p; | ||
31 | |||
32 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
33 | err(1, "getrlimit"); | ||
34 | |||
35 | sz = lim.rlim_cur / FACTOR; | ||
36 | |||
37 | for (i = STARTI; i >= 0; i--) { | ||
38 | size_t len = (sz-i) * FACTOR; | ||
39 | p = malloc(len); | ||
40 | free(p); | ||
41 | free(malloc(4096)); | ||
42 | } | ||
43 | return (0); | ||
44 | } | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile new file mode 100644 index 0000000000..bc83666415 --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/04/18 19:04:03 otto Exp $ | ||
2 | |||
3 | PROG= malloc_ulimit2 | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c new file mode 100644 index 0000000000..ca8e8f438a --- /dev/null +++ b/src/regress/lib/libc/malloc/malloc_ulimit2/malloc_ulimit2.c | |||
@@ -0,0 +1,42 @@ | |||
1 | /* $OpenBSD: malloc_ulimit2.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */ | ||
2 | |||
3 | /* Public Domain, 2006, Otto Moerbeek <otto@drijf.net> */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/time.h> | ||
7 | #include <sys/resource.h> | ||
8 | #include <err.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | #define FACTOR 1024 | ||
13 | |||
14 | main() | ||
15 | { | ||
16 | struct rlimit lim; | ||
17 | size_t sz; | ||
18 | int i; | ||
19 | void *p; | ||
20 | |||
21 | if (getrlimit(RLIMIT_DATA, &lim) == -1) | ||
22 | err(1, "getrlimit"); | ||
23 | |||
24 | sz = lim.rlim_cur / FACTOR; | ||
25 | |||
26 | for (i = 0; ; i++) { | ||
27 | size_t len = (sz-i) * FACTOR; | ||
28 | p = malloc(len); | ||
29 | if (p != NULL) { | ||
30 | free(p); | ||
31 | break; | ||
32 | } | ||
33 | } | ||
34 | i += 10; | ||
35 | for (; i >= 0; i--) { | ||
36 | size_t len = (sz-i) * FACTOR; | ||
37 | p = malloc(len); | ||
38 | free(p); | ||
39 | free(malloc(4096)); | ||
40 | } | ||
41 | return (0); | ||
42 | } | ||
diff --git a/src/regress/lib/libc/mkstemp/Makefile b/src/regress/lib/libc/mkstemp/Makefile new file mode 100644 index 0000000000..dc7eb281a9 --- /dev/null +++ b/src/regress/lib/libc/mkstemp/Makefile | |||
@@ -0,0 +1,19 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/02/11 07:35:38 guenther Exp $ | ||
2 | |||
3 | PROG=mkstemp_test | ||
4 | CLEANFILES+= ; rm -rf output | ||
5 | |||
6 | O = output | ||
7 | |||
8 | # The ktrace/kdump/perl combo verifies that all open() calls that | ||
9 | # were passed O_CREAT were also passed O_EXCL | ||
10 | run-regress-${PROG}: ${PROG} | ||
11 | mkdir -p $O && cd $O && ktrace ../${PROG} | ||
12 | cd $O && kdump | perl -mFcntl -nl \ | ||
13 | -e '/ open\([^,]*,([^,]+)/ or next;' \ | ||
14 | -e '$$f = oct($$1);' \ | ||
15 | -e 'if ($$f & O_CREAT && !($$f & O_EXCL)) {' \ | ||
16 | -e ' print "FAIL"; exit 1' \ | ||
17 | -e '}' | ||
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/mkstemp/mkstemp_test.c b/src/regress/lib/libc/mkstemp/mkstemp_test.c new file mode 100644 index 0000000000..fd133d8368 --- /dev/null +++ b/src/regress/lib/libc/mkstemp/mkstemp_test.c | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010 Philip Guenther <guenther@openbsd.org> | ||
3 | * | ||
4 | * Public domain. | ||
5 | * | ||
6 | * Verify that mkstemp() and mkstemps() doesn't overrun or underrun | ||
7 | * the template buffer and that it can generate names that don't | ||
8 | * contain any X's | ||
9 | */ | ||
10 | |||
11 | #include <sys/param.h> | ||
12 | |||
13 | #include <err.h> | ||
14 | #include <stdio.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <string.h> | ||
17 | #include <sys/mman.h> | ||
18 | #include <sys/stat.h> | ||
19 | #include <unistd.h> | ||
20 | |||
21 | #define MAX_TEMPLATE_LEN 10 | ||
22 | #define MAX_TRIES 100 | ||
23 | |||
24 | #define SUFFIX ".suff" | ||
25 | #define SLEN (sizeof SUFFIX - 1) | ||
26 | |||
27 | long pg; | ||
28 | |||
29 | /* | ||
30 | * verify that a path generated by mkstemp() or mkstemp() looks like a | ||
31 | * reasonable expansion of the template and matches the fd. Returns true | ||
32 | * if all the X's were replaced with non-X's | ||
33 | */ | ||
34 | int | ||
35 | check(int fd, char const *path, char const *prefix, size_t plen, | ||
36 | char const *suffix, size_t slen, int tlen) | ||
37 | { | ||
38 | struct stat sb, fsb; | ||
39 | char const *p; | ||
40 | |||
41 | if (fd < 0) | ||
42 | err(1, "mkstemp"); | ||
43 | if (stat(path, &sb)) | ||
44 | err(1, "stat(%s)", path); | ||
45 | if (fstat(fd, &fsb)) | ||
46 | err(1, "fstat(%d==%s)", fd, path); | ||
47 | if (sb.st_dev != fsb.st_dev || sb.st_ino != fsb.st_ino) | ||
48 | errx(1, "stat mismatch"); | ||
49 | close(fd); | ||
50 | if (memcmp(path, prefix, plen) != 0) | ||
51 | errx(1, "prefix changed! %s vs %s", prefix, path); | ||
52 | if (memcmp(path + plen + tlen, suffix, slen + 1) != 0) | ||
53 | errx(1, "suffix changed! %s vs %s", suffix, path); | ||
54 | for (p = path + plen; p < path + plen + tlen; p++) | ||
55 | if (*p == '\0') | ||
56 | errx(1, "unexpected truncation"); | ||
57 | else if (*p == 'X') | ||
58 | return 0; | ||
59 | return 1; | ||
60 | } | ||
61 | |||
62 | |||
63 | void | ||
64 | try_mkstemp(char *p, char const *prefix, int len) | ||
65 | { | ||
66 | char *q; | ||
67 | size_t plen = strlen(prefix); | ||
68 | int tries, fd; | ||
69 | |||
70 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
71 | memcpy(p, prefix, plen); | ||
72 | memset(p + plen, 'X', len); | ||
73 | p[plen + len] = '\0'; | ||
74 | fd = mkstemp(p); | ||
75 | if (check(fd, p, prefix, plen, "", 0, len)) | ||
76 | return; | ||
77 | } | ||
78 | errx(1, "exceeded MAX_TRIES"); | ||
79 | } | ||
80 | |||
81 | void | ||
82 | try_mkstemps(char *p, char const *prefix, int len, char const *suffix) | ||
83 | { | ||
84 | char *q; | ||
85 | size_t plen = strlen(prefix); | ||
86 | size_t slen = strlen(suffix); | ||
87 | int tries, fd; | ||
88 | |||
89 | for (tries = 0; tries < MAX_TRIES; tries++) { | ||
90 | memcpy(p, prefix, plen); | ||
91 | memset(p + plen, 'X', len); | ||
92 | memcpy(p + plen + len, suffix, slen + 1); | ||
93 | fd = mkstemps(p, slen); | ||
94 | if (check(fd, p, prefix, plen, suffix, slen, len)) | ||
95 | return; | ||
96 | } | ||
97 | errx(1, "exceeded MAX_TRIES"); | ||
98 | } | ||
99 | |||
100 | int | ||
101 | main(void) | ||
102 | { | ||
103 | struct stat sb, fsb; | ||
104 | char cwd[MAXPATHLEN + 1]; | ||
105 | char *p; | ||
106 | size_t clen; | ||
107 | int i; | ||
108 | |||
109 | pg = sysconf(_SC_PAGESIZE); | ||
110 | if (getcwd(cwd, sizeof cwd - 1) == NULL) | ||
111 | err(1, "getcwd"); | ||
112 | clen = strlen(cwd); | ||
113 | cwd[clen++] = '/'; | ||
114 | cwd[clen] = '\0'; | ||
115 | p = mmap(NULL, pg * 3, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); | ||
116 | if (p == NULL) | ||
117 | err(1, "mmap"); | ||
118 | if (mprotect(p, pg, PROT_NONE) || mprotect(p + pg * 2, pg, PROT_NONE)) | ||
119 | err(1, "mprotect"); | ||
120 | p += pg; | ||
121 | |||
122 | i = MAX_TEMPLATE_LEN + 1; | ||
123 | while (i-- > 1) { | ||
124 | /* try first at the start of a page, no prefix */ | ||
125 | try_mkstemp(p, "", i); | ||
126 | /* now at the end of the page, no prefix */ | ||
127 | try_mkstemp(p + pg - i - 1, "", i); | ||
128 | /* start of the page, prefixed with the cwd */ | ||
129 | try_mkstemp(p, cwd, i); | ||
130 | /* how about at the end of the page, prefixed with cwd? */ | ||
131 | try_mkstemp(p + pg - clen - i - 1, cwd, i); | ||
132 | |||
133 | /* again, with mkstemps() and an empty suffix */ | ||
134 | /* try first at the start of a page, no prefix */ | ||
135 | try_mkstemps(p, "", i, ""); | ||
136 | /* now at the end of the page, no prefix */ | ||
137 | try_mkstemps(p + pg - i - 1, "", i, ""); | ||
138 | /* start of the page, prefixed with the cwd */ | ||
139 | try_mkstemps(p, cwd, i, ""); | ||
140 | /* how about at the end of the page, prefixed with cwd? */ | ||
141 | try_mkstemps(p + pg - clen - i - 1, cwd, i, ""); | ||
142 | |||
143 | /* mkstemps() and a non-empty suffix */ | ||
144 | /* try first at the start of a page, no prefix */ | ||
145 | try_mkstemps(p, "", i, SUFFIX); | ||
146 | /* now at the end of the page, no prefix */ | ||
147 | try_mkstemps(p + pg - i - SLEN - 1, "", i, SUFFIX); | ||
148 | /* start of the page, prefixed with the cwd */ | ||
149 | try_mkstemps(p, cwd, i, SUFFIX); | ||
150 | /* how about at the end of the page, prefixed with cwd? */ | ||
151 | try_mkstemps(p + pg - clen - i - SLEN - 1, cwd, i, SUFFIX); | ||
152 | |||
153 | } | ||
154 | |||
155 | return 0; | ||
156 | } | ||
diff --git a/src/regress/lib/libc/netdb/Makefile b/src/regress/lib/libc/netdb/Makefile new file mode 100644 index 0000000000..8254607227 --- /dev/null +++ b/src/regress/lib/libc/netdb/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/10/25 15:10:36 otto Exp $ | ||
2 | |||
3 | PROG= netdb | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/netdb/netdb.c b/src/regress/lib/libc/netdb/netdb.c new file mode 100644 index 0000000000..fabb3ee4e1 --- /dev/null +++ b/src/regress/lib/libc/netdb/netdb.c | |||
@@ -0,0 +1,183 @@ | |||
1 | /* $OpenBSD: netdb.c,v 1.2 2011/05/01 04:27:07 guenther Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Public domain, 2004, Otto Moerbeek <otto@drijf.net> | ||
5 | */ | ||
6 | |||
7 | #include <err.h> | ||
8 | #include <netdb.h> | ||
9 | #include <stdarg.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | int ret = 0; | ||
13 | |||
14 | void | ||
15 | checkp(int n, struct protoent *p, int proto, const char *name, ...) | ||
16 | { | ||
17 | va_list va; | ||
18 | char *a; | ||
19 | int i; | ||
20 | |||
21 | if (p == NULL) { | ||
22 | warnx("%d proto struct is NULL", n); | ||
23 | ret = 1; | ||
24 | return; | ||
25 | } | ||
26 | if (p->p_proto != proto) { | ||
27 | warnx("%d proto num mismatch %d %d", n, p->p_proto, proto); | ||
28 | ret = 1; | ||
29 | } | ||
30 | if (strcmp(p->p_name, name) != 0) { | ||
31 | warnx("%d proto name mismatch %s %s", n, p->p_name, name); | ||
32 | ret = 1; | ||
33 | } | ||
34 | va_start(va, name); | ||
35 | a = va_arg(va, char *); | ||
36 | i = 0; | ||
37 | while (a != NULL) { | ||
38 | if (strcmp(p->p_aliases[i], a) != 0) { | ||
39 | warnx("%d proto alias mismatch %s %s", n, | ||
40 | p->p_aliases[i], a); | ||
41 | ret = 1; | ||
42 | } | ||
43 | i++; | ||
44 | a = va_arg(va, char *); | ||
45 | } | ||
46 | if (p->p_aliases[i] != NULL) { | ||
47 | warnx("%d proto alias list does not end with NULL", n); | ||
48 | ret = 1; | ||
49 | } | ||
50 | va_end(va); | ||
51 | } | ||
52 | |||
53 | |||
54 | void | ||
55 | checks(int n, struct servent *s, int port, const char *proto, | ||
56 | const char *name, ...) | ||
57 | { | ||
58 | va_list va; | ||
59 | char *a; | ||
60 | int i; | ||
61 | |||
62 | if (s == NULL) { | ||
63 | warnx("%d serv struct is NULL", n); | ||
64 | ret = 1; | ||
65 | return; | ||
66 | } | ||
67 | if (s->s_port != ntohs(port)) { | ||
68 | warnx("%d port num mismatch %d %d", n, s->s_port, port); | ||
69 | ret = 1; | ||
70 | } | ||
71 | if (strcmp(s->s_name, name) != 0) { | ||
72 | warnx("%d serv name mismatch %s %s", n, s->s_name, name); | ||
73 | ret = 1; | ||
74 | } | ||
75 | if (strcmp(s->s_proto, proto) != 0) { | ||
76 | warnx("%d serv proto mismatch %s %s", n, s->s_proto, proto); | ||
77 | ret = 1; | ||
78 | } | ||
79 | va_start(va, name); | ||
80 | a = va_arg(va, char *); | ||
81 | i = 0; | ||
82 | while (a != NULL) { | ||
83 | if (strcmp(s->s_aliases[i], a) != 0) { | ||
84 | warnx("%d serv alias mismatch %s %s", n, | ||
85 | s->s_aliases[i], a); | ||
86 | ret = 1; | ||
87 | } | ||
88 | i++; | ||
89 | a = va_arg(va, char *); | ||
90 | } | ||
91 | if (s->s_aliases[i] != NULL) { | ||
92 | warnx("%d serv alias list does not end with NULL", n); | ||
93 | ret = 1; | ||
94 | } | ||
95 | va_end(va); | ||
96 | } | ||
97 | |||
98 | int | ||
99 | main() | ||
100 | { | ||
101 | struct protoent *p; | ||
102 | struct protoent protoent; | ||
103 | struct protoent_data protoent_data; | ||
104 | struct servent *s; | ||
105 | struct servent servent; | ||
106 | struct servent_data servent_data; | ||
107 | int r; | ||
108 | |||
109 | p = getprotobynumber(35); | ||
110 | checkp(1, p, 35, "idpr", "IDPR", (char *)NULL); | ||
111 | |||
112 | p = getprotobyname("igp"); | ||
113 | checkp(2, p, 9, "igp", "IGP", (char *) NULL); | ||
114 | |||
115 | p = getprotobyname("RDP"); | ||
116 | checkp(3, p, 27, "rdp", "RDP", (char *) NULL); | ||
117 | |||
118 | p = getprotobyname("vrrp"); | ||
119 | checkp(4, p, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
120 | |||
121 | p = getprotobyname("nonexistent"); | ||
122 | if (p != NULL) | ||
123 | err(1, "nonexistent proto found"); | ||
124 | |||
125 | memset(&protoent_data, 0, sizeof(protoent_data)); | ||
126 | r = getprotobynumber_r(35, &protoent, &protoent_data); | ||
127 | if (r != 0) | ||
128 | err(1, "proto not found"); | ||
129 | |||
130 | checkp(5, &protoent, 35, "idpr", "IDPR", (char *)NULL); | ||
131 | |||
132 | r = getprotobyname_r("vrrp", &protoent, &protoent_data); | ||
133 | if (r != 0) | ||
134 | err(1, "proto not found"); | ||
135 | checkp(6, &protoent, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
136 | |||
137 | r = getprotobyname_r("nonexistent", &protoent, &protoent_data); | ||
138 | if (r != -1) | ||
139 | err(1, "nonexistent proto found"); | ||
140 | |||
141 | r = getprotobyname_r("", &protoent, &protoent_data); | ||
142 | if (r != -1) | ||
143 | err(1, "nonexistent proto found"); | ||
144 | |||
145 | |||
146 | r = getprotobynumber_r(256, &protoent, &protoent_data); | ||
147 | if (r != -1) | ||
148 | err(1, "nonexistent proto found"); | ||
149 | |||
150 | s = getservbyname("zip", NULL); | ||
151 | checks(7, s, 6, "ddp", "zip", (char *)NULL); | ||
152 | |||
153 | s = getservbyname("nicname", "tcp"); | ||
154 | checks(8, s, 43, "tcp", "whois", "nicname", (char *)NULL); | ||
155 | |||
156 | s = getservbyport(htons(42), "tcp"); | ||
157 | checks(9, s, 42, "tcp", "nameserver", "name", (char *)NULL); | ||
158 | |||
159 | memset(&servent_data, 0, sizeof(servent_data)); | ||
160 | r = getservbyname_r("zip", "ddp", &servent, &servent_data); | ||
161 | if (r != 0) | ||
162 | err(1, "servent not found"); | ||
163 | checks(10, &servent, 6, "ddp", "zip", (char *)NULL); | ||
164 | |||
165 | r = getservbyport_r(htons(520), NULL, &servent, &servent_data); | ||
166 | if (r != 0) | ||
167 | err(1, "servent not found"); | ||
168 | checks(11, &servent, 520, "udp", "route", "router", "routed", (char *)NULL); | ||
169 | |||
170 | r = getservbyname_r("nonexistent", NULL, &servent, &servent_data); | ||
171 | if (r != -1) | ||
172 | err(1, "nonexiststent servent found"); | ||
173 | |||
174 | r = getservbyport_r(htons(50000), NULL, &servent, &servent_data); | ||
175 | if (r != -1) | ||
176 | err(1, "nonexistent servent found"); | ||
177 | |||
178 | r = getservbyport_r(htons(520), "tcp", &servent, &servent_data); | ||
179 | if (r != -1) | ||
180 | err(1, "nonexistent servent found"); | ||
181 | |||
182 | return ret; | ||
183 | } | ||
diff --git a/src/regress/lib/libc/orientation/Makefile b/src/regress/lib/libc/orientation/Makefile new file mode 100644 index 0000000000..5c73702abe --- /dev/null +++ b/src/regress/lib/libc/orientation/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2010/06/29 16:20:28 guenther Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=orientation_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | run-regress-${PROG}: ${PROG} | ||
8 | ./${PROG} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/orientation/orientation_test.c b/src/regress/lib/libc/orientation/orientation_test.c new file mode 100644 index 0000000000..1d0911d12f --- /dev/null +++ b/src/regress/lib/libc/orientation/orientation_test.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* $OpenBSD: orientation_test.c,v 1.3 2011/10/16 14:39:01 stsp Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2009 Philip Guenther | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * Test whether the various stdio functions set the stream orientation | ||
34 | * ("width") as they should | ||
35 | */ | ||
36 | |||
37 | #include <sys/types.h> | ||
38 | #include <err.h> | ||
39 | #include <stddef.h> | ||
40 | #include <stdio.h> | ||
41 | #include <stdlib.h> | ||
42 | #include <string.h> | ||
43 | #include <unistd.h> | ||
44 | #include <wchar.h> | ||
45 | |||
46 | char filename[] = "/tmp/fwide.XXXXXXXXXX"; | ||
47 | |||
48 | FILE *dup_stdout = NULL; | ||
49 | int failures = 0; | ||
50 | |||
51 | void | ||
52 | fail(int line, int r, char const *expect, char const *test) | ||
53 | { | ||
54 | failures++; | ||
55 | fprintf(dup_stdout, | ||
56 | "FAIL: %d: fwide returned %d, expected %s 0 after %s\n", | ||
57 | line, r, expect, test); | ||
58 | } | ||
59 | |||
60 | FILE * | ||
61 | setup(int line) | ||
62 | { | ||
63 | FILE *f; | ||
64 | int r; | ||
65 | |||
66 | if ((f = fopen(filename, "r+")) == NULL) | ||
67 | err(2, "fopen"); | ||
68 | if ((r = fwide(f, 0)) != 0) | ||
69 | fail(line, r, "==", "fopen"); | ||
70 | return (f); | ||
71 | } | ||
72 | |||
73 | FILE * | ||
74 | setup_std(FILE *std, int line) | ||
75 | { | ||
76 | int r; | ||
77 | |||
78 | if (freopen(filename, "r+", std) == NULL) | ||
79 | err(2, "freopen"); | ||
80 | if ((r = fwide(std, 0)) != 0) | ||
81 | fail(line, r, "==", "freopen"); | ||
82 | return (std); | ||
83 | } | ||
84 | |||
85 | #define TEST_(x, op) \ | ||
86 | do { \ | ||
87 | f = setup(__LINE__); \ | ||
88 | x; \ | ||
89 | if (!((r = fwide(f, 0)) op 0)) \ | ||
90 | fail(__LINE__, r, #op, #x); \ | ||
91 | fclose(f); \ | ||
92 | } while (0) | ||
93 | |||
94 | #define TEST_STD_(std, x, op) \ | ||
95 | do { \ | ||
96 | f = setup_std(std, __LINE__); \ | ||
97 | x; \ | ||
98 | if (!((r = fwide(f, 0)) op 0)) \ | ||
99 | fail(__LINE__, r, #op, #x); \ | ||
100 | } while (0) | ||
101 | |||
102 | #define TEST_UNCHANGED(x) TEST_(x, ==) | ||
103 | #define TEST_NARROW(x) TEST_(x, <) | ||
104 | #define TEST_WIDE(x) TEST_(x, >) | ||
105 | #define TEST_UNCHANGED_STD(std, x) TEST_STD_(std, x, ==) | ||
106 | #define TEST_NARROW_STD(std, x) TEST_STD_(std, x, <) | ||
107 | #define TEST_WIDE_STD(std, x) TEST_STD_(std, x, >) | ||
108 | |||
109 | int | ||
110 | main(int argc, char *argv[]) | ||
111 | { | ||
112 | char buffer[BUFSIZ]; | ||
113 | wchar_t wbuffer[BUFSIZ]; | ||
114 | FILE *f; | ||
115 | off_t off; | ||
116 | fpos_t pos; | ||
117 | size_t size; | ||
118 | int fd, r; | ||
119 | char c; | ||
120 | wchar_t wc; | ||
121 | |||
122 | if ((fd = dup(1)) == -1) | ||
123 | err(2, "dup"); | ||
124 | if ((dup_stdout = fdopen(fd, "w")) == NULL) | ||
125 | err(2, "fdopen"); | ||
126 | if ((fd = mkstemp(filename)) == -1) | ||
127 | err(2, "mkstemp"); | ||
128 | if (write(fd, "0123456789\n\n", 12) != 12 || close(fd)) | ||
129 | err(2, "write + close"); | ||
130 | |||
131 | /* status */ | ||
132 | TEST_UNCHANGED(fwide(f, 0)); | ||
133 | TEST_NARROW(fwide(f, -1)); | ||
134 | TEST_WIDE(fwide(f, 1)); | ||
135 | TEST_UNCHANGED(feof(f)); | ||
136 | TEST_UNCHANGED(ferror(f)); | ||
137 | TEST_UNCHANGED(fileno(f)); | ||
138 | TEST_UNCHANGED(clearerr(f)); | ||
139 | |||
140 | /* flush and purge */ | ||
141 | TEST_UNCHANGED(fflush(f)); | ||
142 | TEST_UNCHANGED(fpurge(f)); | ||
143 | |||
144 | /* positioning */ | ||
145 | TEST_UNCHANGED(fgetpos(f, &pos)); | ||
146 | TEST_UNCHANGED(fgetpos(f, &pos); fsetpos(f, &pos)); | ||
147 | TEST_UNCHANGED(ftell(f)); | ||
148 | TEST_UNCHANGED(ftello(f)); | ||
149 | TEST_UNCHANGED(fseek(f, 1, SEEK_CUR)); | ||
150 | TEST_UNCHANGED(fseek(f, 1, SEEK_SET)); | ||
151 | TEST_UNCHANGED(fseek(f, 1, SEEK_END)); | ||
152 | TEST_UNCHANGED(fseeko(f, 1, SEEK_CUR)); | ||
153 | TEST_UNCHANGED(fseeko(f, 1, SEEK_SET)); | ||
154 | TEST_UNCHANGED(fseeko(f, 1, SEEK_END)); | ||
155 | TEST_UNCHANGED(rewind(f)); | ||
156 | |||
157 | /* buffering */ | ||
158 | TEST_UNCHANGED(setbuf(f, NULL)); | ||
159 | TEST_UNCHANGED(setbuf(f, buffer)); | ||
160 | TEST_UNCHANGED(setvbuf(f, buffer, _IONBF, BUFSIZ)); | ||
161 | TEST_UNCHANGED(setvbuf(f, buffer, _IOLBF, BUFSIZ)); | ||
162 | TEST_UNCHANGED(setvbuf(f, buffer, _IOFBF, BUFSIZ)); | ||
163 | TEST_UNCHANGED(setvbuf(f, NULL, _IONBF, 0)); | ||
164 | TEST_UNCHANGED(setvbuf(f, NULL, _IOLBF, 0)); | ||
165 | TEST_UNCHANGED(setvbuf(f, NULL, _IOFBF, 0)); | ||
166 | TEST_UNCHANGED(setbuffer(f, NULL, 0)); | ||
167 | TEST_UNCHANGED(setbuffer(f, buffer, BUFSIZ)); | ||
168 | TEST_UNCHANGED(setlinebuf(f)); | ||
169 | |||
170 | /* locking */ | ||
171 | TEST_UNCHANGED(flockfile(f);funlockfile(f)); | ||
172 | TEST_UNCHANGED(ftrylockfile(f);funlockfile(f)); | ||
173 | |||
174 | /* input */ | ||
175 | TEST_NARROW(getc(f)); | ||
176 | TEST_NARROW(getc_unlocked(f)); | ||
177 | TEST_NARROW(fgetc(f)); | ||
178 | TEST_NARROW(c = fgetc(f); ungetc(c, f)); | ||
179 | TEST_NARROW(fgets(buffer, BUFSIZ, f)); | ||
180 | TEST_NARROW(fscanf(f, "%s\n", buffer)); | ||
181 | TEST_NARROW(fgetln(f, &size)); | ||
182 | |||
183 | /* output */ | ||
184 | TEST_NARROW(putc('c', f)); | ||
185 | TEST_NARROW(putc_unlocked('c', f)); | ||
186 | TEST_NARROW(fputc('c', f)); | ||
187 | TEST_NARROW(fputs("foo", f)); | ||
188 | TEST_NARROW(fprintf(f, "%s\n", "foo")); | ||
189 | |||
190 | /* input from stdin */ | ||
191 | TEST_NARROW_STD(stdin, getchar()); | ||
192 | TEST_NARROW_STD(stdin, getchar_unlocked()); | ||
193 | TEST_NARROW_STD(stdin, gets(buffer)); | ||
194 | TEST_NARROW_STD(stdin, scanf("%s\n", buffer)); | ||
195 | |||
196 | /* output to stdout */ | ||
197 | TEST_NARROW_STD(stdout, putchar('c')); | ||
198 | TEST_NARROW_STD(stdout, putchar_unlocked('c')); | ||
199 | TEST_NARROW_STD(stdout, puts("foo")); | ||
200 | TEST_NARROW_STD(stdout, printf("foo")); | ||
201 | |||
202 | /* word-size ops */ | ||
203 | /* | ||
204 | * fread and fwrite are specified as being implemented in | ||
205 | * terms of fgetc() and fputc() and therefore must set the | ||
206 | * stream orientation to narrow. | ||
207 | */ | ||
208 | TEST_NARROW(fread(buffer, 4, BUFSIZ / 4, f)); | ||
209 | TEST_NARROW(fwrite(buffer, 4, BUFSIZ / 4, f)); | ||
210 | |||
211 | /* | ||
212 | * getw() and putw() aren't specified anywhere but logically | ||
213 | * should behave the same as fread/fwrite. Not all OSes agree: | ||
214 | * Solaris 10 has them not changing the orientation. | ||
215 | */ | ||
216 | TEST_NARROW(getw(f)); | ||
217 | TEST_NARROW(putw(1234, f)); | ||
218 | |||
219 | |||
220 | /* WIDE CHAR TIME! */ | ||
221 | |||
222 | /* input */ | ||
223 | TEST_WIDE(getwc(f)); | ||
224 | TEST_WIDE(fgetwc(f)); | ||
225 | TEST_WIDE(wc = fgetwc(f); ungetwc(wc, f)); | ||
226 | TEST_WIDE(fgetws(wbuffer, BUFSIZ, f)); | ||
227 | TEST_WIDE(fwscanf(f, L"%s\n", wbuffer)); | ||
228 | |||
229 | /* output */ | ||
230 | TEST_WIDE(putwc(L'c', f)); | ||
231 | TEST_WIDE(fputwc(L'c', f)); | ||
232 | TEST_WIDE(fputws(L"foo", f)); | ||
233 | TEST_WIDE(fwprintf(f, L"%s\n", L"foo")); | ||
234 | |||
235 | /* input from stdin */ | ||
236 | TEST_WIDE_STD(stdin, getwchar()); | ||
237 | TEST_WIDE_STD(stdin, wscanf(L"%s\n", wbuffer)); | ||
238 | |||
239 | /* output to stdout */ | ||
240 | TEST_WIDE_STD(stdout, putwchar(L'c')); | ||
241 | TEST_WIDE_STD(stdout, wprintf(L"foo")); | ||
242 | |||
243 | |||
244 | TEST_UNCHANGED_STD(stderr, perror("foo")); | ||
245 | |||
246 | remove(filename); | ||
247 | if (failures) | ||
248 | exit(1); | ||
249 | exit(0); | ||
250 | } | ||
251 | |||
diff --git a/src/regress/lib/libc/popen/Makefile b/src/regress/lib/libc/popen/Makefile new file mode 100644 index 0000000000..25b8668a7a --- /dev/null +++ b/src/regress/lib/libc/popen/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/02/16 01:55:09 art Exp $ | ||
2 | |||
3 | PROG=popen | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/popen/popen.c b/src/regress/lib/libc/popen/popen.c new file mode 100644 index 0000000000..916cb71b03 --- /dev/null +++ b/src/regress/lib/libc/popen/popen.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* $NetBSD: popen.c,v 1.1 1999/09/30 09:23:23 tron Exp $ */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * This code is derived from software contributed to The NetBSD Foundation | ||
8 | * by Matthias Scheler. | ||
9 | * | ||
10 | * Redistribution and use in source and binary forms, with or without | ||
11 | * modification, are permitted provided that the following conditions | ||
12 | * are met: | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in the | ||
17 | * documentation and/or other materials provided with the distribution. | ||
18 | * | ||
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | #include <sys/param.h> | ||
33 | |||
34 | #include <err.h> | ||
35 | #include <errno.h> | ||
36 | #include <paths.h> | ||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <time.h> | ||
40 | #include <unistd.h> | ||
41 | |||
42 | #define _PATH_CAT "/bin/cat" | ||
43 | #define BUFSIZE (640*1024) | ||
44 | /* 640KB ought to be enough for everyone. */ | ||
45 | #define DATAFILE "popen.data" | ||
46 | |||
47 | int | ||
48 | main(int argc, char **argv) | ||
49 | { | ||
50 | char *buffer, command[MAXPATHLEN]; | ||
51 | int index, in; | ||
52 | FILE *pipe; | ||
53 | |||
54 | if ((buffer = malloc(BUFSIZE*sizeof(char))) == NULL) | ||
55 | err(1, NULL); | ||
56 | |||
57 | for (index=0; index<BUFSIZE; index++) | ||
58 | buffer[index]=arc4random(); | ||
59 | |||
60 | (void)snprintf(command, sizeof(command), "%s >%s", | ||
61 | _PATH_CAT, DATAFILE); | ||
62 | if ((pipe = popen(command, "w")) == NULL) | ||
63 | err(1, "popen write"); | ||
64 | |||
65 | if (fwrite(buffer, sizeof(char), BUFSIZE, pipe) != BUFSIZE) | ||
66 | err(1, "write"); | ||
67 | |||
68 | if (pclose(pipe) == -1) | ||
69 | err(1, "pclose"); | ||
70 | |||
71 | (void)snprintf(command, sizeof(command), "%s %s", | ||
72 | _PATH_CAT, DATAFILE); | ||
73 | if ((pipe = popen(command, "r")) == NULL) | ||
74 | err(1, "popen read"); | ||
75 | |||
76 | index = 0; | ||
77 | while ((in = fgetc(pipe)) != EOF) | ||
78 | if (index == BUFSIZE) { | ||
79 | errno = EFBIG; | ||
80 | err(1, "read"); | ||
81 | } | ||
82 | else | ||
83 | if ((char)in != buffer[index++]) { | ||
84 | errno = EINVAL; | ||
85 | err(1, "read"); | ||
86 | } | ||
87 | |||
88 | if (index < BUFSIZE) { | ||
89 | errno = EIO; | ||
90 | err(1, "read"); | ||
91 | } | ||
92 | |||
93 | if (pclose(pipe) == -1) | ||
94 | err(1, "pclose"); | ||
95 | |||
96 | (void)unlink(DATAFILE); | ||
97 | return 0; | ||
98 | } | ||
diff --git a/src/regress/lib/libc/printf/Makefile b/src/regress/lib/libc/printf/Makefile new file mode 100644 index 0000000000..c2e2732d6e --- /dev/null +++ b/src/regress/lib/libc/printf/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2008/09/07 20:36:10 martynas Exp $ | ||
2 | |||
3 | PROG= fp | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/printf/fp.c b/src/regress/lib/libc/printf/fp.c new file mode 100644 index 0000000000..6ed52fdb49 --- /dev/null +++ b/src/regress/lib/libc/printf/fp.c | |||
@@ -0,0 +1,217 @@ | |||
1 | /* $OpenBSD: fp.c,v 1.1 2008/09/07 20:36:10 martynas Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * Test for printf() floating point formats. | ||
30 | */ | ||
31 | |||
32 | #include <assert.h> | ||
33 | #include <err.h> | ||
34 | #include <float.h> | ||
35 | #include <math.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdarg.h> | ||
38 | #include <stdint.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | |||
42 | #define testfmt(result, fmt, ...) \ | ||
43 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
44 | void _testfmt(const char *, int, const char *, const char *, ...); | ||
45 | void smash_stack(void); | ||
46 | |||
47 | int | ||
48 | main(int argc, char *argv[]) | ||
49 | { | ||
50 | /* | ||
51 | * Basic tests of decimal output functionality. | ||
52 | */ | ||
53 | testfmt(" 1.000000E+00", "%13E", 1.0); | ||
54 | testfmt(" 1.000000", "%13f", 1.0); | ||
55 | testfmt(" 1", "%13G", 1.0); | ||
56 | testfmt(" 1.000000E+00", "%13LE", 1.0L); | ||
57 | testfmt(" 1.000000", "%13Lf", 1.0L); | ||
58 | testfmt(" 1", "%13LG", 1.0L); | ||
59 | |||
60 | testfmt("2.718282", "%.*f", -2, 2.7182818); | ||
61 | |||
62 | testfmt("1.234568e+06", "%e", 1234567.8); | ||
63 | testfmt("1234567.800000", "%f", 1234567.8); | ||
64 | testfmt("1.23457E+06", "%G", 1234567.8); | ||
65 | testfmt("1.234568e+06", "%Le", 1234567.8L); | ||
66 | testfmt("1234567.800000", "%Lf", 1234567.8L); | ||
67 | testfmt("1.23457E+06", "%LG", 1234567.8L); | ||
68 | |||
69 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
70 | testfmt("123456789.864210", "%Lf", 123456789.8642097531L); | ||
71 | testfmt("-1.23457E+08", "%LG", -123456789.8642097531L); | ||
72 | testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L); | ||
73 | testfmt(" 3.141592653589793238e-4000", "%L27.18Le", | ||
74 | 3.14159265358979323846e-4000L); | ||
75 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
76 | |||
77 | /* | ||
78 | * Infinities and NaNs | ||
79 | */ | ||
80 | #ifdef NAN | ||
81 | testfmt("nan", "%e", NAN); | ||
82 | testfmt("NAN", "%F", NAN); | ||
83 | testfmt("nan", "%g", NAN); | ||
84 | testfmt("NAN", "%LE", (long double)NAN); | ||
85 | testfmt(" nan", "%05e", NAN); | ||
86 | #endif /* NAN */ | ||
87 | |||
88 | testfmt("INF", "%E", HUGE_VAL); | ||
89 | testfmt("-inf", "%f", -HUGE_VAL); | ||
90 | testfmt("+inf", "%+g", HUGE_VAL); | ||
91 | testfmt(" inf", "%4.2Le", HUGE_VALL); | ||
92 | testfmt("-inf", "%Lf", -HUGE_VALL); | ||
93 | testfmt(" inf", "%05e", HUGE_VAL); | ||
94 | testfmt(" -inf", "%05e", -HUGE_VAL); | ||
95 | |||
96 | /* | ||
97 | * Padding | ||
98 | */ | ||
99 | testfmt("0.000000e+00", "%e", 0.0); | ||
100 | testfmt("0.000000", "%F", (double)0.0); | ||
101 | testfmt("0", "%G", 0.0); | ||
102 | testfmt(" 0", "%3.0Lg", 0.0L); | ||
103 | testfmt(" 0", "%5.0f", 0.001); | ||
104 | |||
105 | /* | ||
106 | * Precision specifiers | ||
107 | */ | ||
108 | testfmt("1.0123e+00", "%.4e", 1.0123456789); | ||
109 | testfmt("1.0123", "%.4f", 1.0123456789); | ||
110 | testfmt("1.012", "%.4g", 1.0123456789); | ||
111 | testfmt("1.2346e-02", "%.4e", 0.0123456789); | ||
112 | testfmt("0.0123", "%.4f", 0.0123456789); | ||
113 | testfmt("0.01235", "%.4g", 0.0123456789); | ||
114 | |||
115 | /* | ||
116 | * Signed conversions | ||
117 | */ | ||
118 | testfmt("+2.500000e-01", "%+e", 0.25); | ||
119 | testfmt("+0.000000", "%+F", 0.0); | ||
120 | testfmt("-1", "%+g", -1.0); | ||
121 | |||
122 | testfmt("-1.000000e+00", "% e", -1.0); | ||
123 | testfmt("+1.000000", "% +f", 1.0); | ||
124 | testfmt(" 1", "% g", 1.0); | ||
125 | testfmt(" 0", "% g", 0.0); | ||
126 | |||
127 | /* | ||
128 | * ``Alternate form'' | ||
129 | */ | ||
130 | testfmt("1.250e+00", "%#.3e", 1.25); | ||
131 | testfmt("123.000000", "%#f", 123.0); | ||
132 | testfmt(" 12345.", "%#7.5g", 12345.0); | ||
133 | testfmt(" 1.00000", "%#8g", 1.0); | ||
134 | testfmt("0.0", "%#.2g", 0.0); | ||
135 | |||
136 | /* | ||
137 | * Padding and decimal point placement | ||
138 | */ | ||
139 | testfmt("03.2E+00", "%08.1E", 3.25); | ||
140 | testfmt("003.25", "%06.2F", 3.25); | ||
141 | testfmt("0003.25", "%07.4G", 3.25); | ||
142 | |||
143 | testfmt("3.14159e-05", "%g", 3.14159e-5); | ||
144 | testfmt("0.000314159", "%g", 3.14159e-4); | ||
145 | testfmt("3.14159e+06", "%g", 3.14159e6); | ||
146 | testfmt("314159", "%g", 3.14159e5); | ||
147 | testfmt("314159.", "%#g", 3.14159e5); | ||
148 | |||
149 | testfmt(" 9.000000e+03", "%13e", 9000.0); | ||
150 | testfmt(" 9000.000000", "%12f", 9000.0); | ||
151 | testfmt(" 9000", "%5g", 9000.0); | ||
152 | testfmt(" 900000.", "%#8g", 900000.0); | ||
153 | testfmt(" 9e+06", "%6g", 9000000.0); | ||
154 | testfmt(" 9.000000e-04", "%13e", 0.0009); | ||
155 | testfmt(" 0.000900", "%9f", 0.0009); | ||
156 | testfmt(" 0.0009", "%7g", 0.0009); | ||
157 | testfmt(" 9e-05", "%6g", 0.00009); | ||
158 | testfmt(" 9.00000e-05", "%#12g", 0.00009); | ||
159 | testfmt(" 9.e-05", "%#7.1g", 0.00009); | ||
160 | |||
161 | testfmt(" 0.0", "%4.1f", 0.0); | ||
162 | testfmt("90.0", "%4.1f", 90.0); | ||
163 | testfmt(" 100", "%4.0f", 100.0); | ||
164 | testfmt("9.0e+01", "%4.1e", 90.0); | ||
165 | testfmt("1e+02", "%4.0e", 100.0); | ||
166 | |||
167 | /* | ||
168 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
169 | * are only valid if the implementation converts to hex digits | ||
170 | * on nibble boundaries. | ||
171 | */ | ||
172 | testfmt("0x0p+0", "%a", 0x0.0p0); | ||
173 | testfmt("0X0.P+0", "%#LA", 0x0.0p0L); | ||
174 | #ifdef NAN | ||
175 | testfmt("inf", "%La", (long double)INFINITY); | ||
176 | testfmt("+INF", "%+A", INFINITY); | ||
177 | testfmt("nan", "%La", (long double)NAN); | ||
178 | testfmt("NAN", "%A", NAN); | ||
179 | #endif /* NAN */ | ||
180 | |||
181 | testfmt(" 0x1.23p+0", "%10a", 0x1.23p0); | ||
182 | testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500); | ||
183 | testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40); | ||
184 | testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4); | ||
185 | testfmt("0x1p-1074", "%a", 0x1p-1074); | ||
186 | testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024); | ||
187 | |||
188 | return (0); | ||
189 | } | ||
190 | |||
191 | void | ||
192 | smash_stack(void) | ||
193 | { | ||
194 | static uint32_t junk = 0xdeadbeef; | ||
195 | uint32_t buf[512]; | ||
196 | int i; | ||
197 | |||
198 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
199 | buf[i] = junk; | ||
200 | } | ||
201 | |||
202 | void | ||
203 | _testfmt(const char *result, int line, const char *argstr, const char *fmt,...) | ||
204 | { | ||
205 | char s[100]; | ||
206 | va_list ap; | ||
207 | |||
208 | va_start(ap, fmt); | ||
209 | smash_stack(); | ||
210 | vsnprintf(s, sizeof(s), fmt, ap); | ||
211 | if (strcmp(result, s) != 0) { | ||
212 | fprintf(stderr, | ||
213 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
214 | line, fmt, argstr, s, result); | ||
215 | abort(); | ||
216 | } | ||
217 | } | ||
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile index 93b7bb9052..271debb5d3 100644 --- a/src/regress/lib/libc/regex/Makefile +++ b/src/regress/lib/libc/regex/Makefile | |||
@@ -1,16 +1,21 @@ | |||
1 | # $OpenBSD: Makefile,v 1.6 2004/08/13 14:54:12 millert Exp $ | ||
1 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ |
2 | 3 | ||
3 | PROG= re | 4 | PROG= re |
4 | SRCS= main.c split.c debug.c | 5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c |
5 | NOMAN= | 6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex |
6 | 7 | ||
7 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex | 8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE |
8 | 9 | ||
9 | TESTS= ${.CURDIR}/tests | 10 | TESTS= ${.CURDIR}/tests |
10 | 11 | ||
11 | regress: | 12 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref |
13 | |||
14 | do-reg: ${PROG} | ||
12 | ./re < ${TESTS} | 15 | ./re < ${TESTS} |
16 | do-reg-long: ${PROG} | ||
13 | ./re -el < ${TESTS} | 17 | ./re -el < ${TESTS} |
18 | do-reg-backref: ${PROG} | ||
14 | ./re -er < ${TESTS} | 19 | ./re -er < ${TESTS} |
15 | 20 | ||
16 | .include <bsd.prog.mk> | 21 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c index 861f550611..11129e7249 100644 --- a/src/regress/lib/libc/regex/debug.c +++ b/src/regress/lib/libc/regex/debug.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ | ||
1 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | 2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ |
2 | 3 | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
@@ -218,7 +219,7 @@ FILE *d; | |||
218 | fprintf(d, ">"); | 219 | fprintf(d, ">"); |
219 | break; | 220 | break; |
220 | default: | 221 | default: |
221 | fprintf(d, "!%d(%d)!", OP(*s), opnd); | 222 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); |
222 | break; | 223 | break; |
223 | } | 224 | } |
224 | if (!done) | 225 | if (!done) |
@@ -237,8 +238,8 @@ int ch; | |||
237 | static char buf[10]; | 238 | static char buf[10]; |
238 | 239 | ||
239 | if (isprint(ch) || ch == ' ') | 240 | if (isprint(ch) || ch == ' ') |
240 | sprintf(buf, "%c", ch); | 241 | snprintf(buf, sizeof buf, "%c", ch); |
241 | else | 242 | else |
242 | sprintf(buf, "\\%o", ch); | 243 | snprintf(buf, sizeof buf, "\\%o", ch); |
243 | return(buf); | 244 | return(buf); |
244 | } | 245 | } |
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih index fb9bac0c75..9eb313af23 100644 --- a/src/regress/lib/libc/regex/debug.ih +++ b/src/regress/lib/libc/regex/debug.ih | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
1 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | 2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ |
2 | 3 | ||
3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
@@ -6,9 +7,9 @@ extern "C" { | |||
6 | #endif | 7 | #endif |
7 | 8 | ||
8 | /* === debug.c === */ | 9 | /* === debug.c === */ |
9 | void regprint __P((regex_t *r, FILE *d)); | 10 | void regprint(regex_t *r, FILE *d); |
10 | static void s_print __P((register struct re_guts *g, FILE *d)); | 11 | static void s_print(register struct re_guts *g, FILE *d); |
11 | static char *regchar __P((int ch)); | 12 | static char *regchar(int ch); |
12 | 13 | ||
13 | #ifdef __cplusplus | 14 | #ifdef __cplusplus |
14 | } | 15 | } |
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 8d88a8b9b8..e0ed86f5e8 100644 --- a/src/regress/lib/libc/regex/main.c +++ b/src/regress/lib/libc/regex/main.c | |||
@@ -1,10 +1,13 @@ | |||
1 | /* $OpenBSD: main.c,v 1.7 2007/09/12 19:32:35 otto Exp $ */ | ||
1 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ |
2 | 3 | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdlib.h> | ||
4 | #include <string.h> | 6 | #include <string.h> |
5 | #include <sys/types.h> | 7 | #include <sys/types.h> |
6 | #include <regex.h> | 8 | #include <regex.h> |
7 | #include <assert.h> | 9 | #include <assert.h> |
10 | #include <unistd.h> | ||
8 | 11 | ||
9 | #include "main.ih" | 12 | #include "main.ih" |
10 | 13 | ||
@@ -19,15 +22,15 @@ regoff_t startoff = 0; | |||
19 | regoff_t endoff = 0; | 22 | regoff_t endoff = 0; |
20 | 23 | ||
21 | 24 | ||
22 | extern int split(); | 25 | extern int split(char *, char *[], int, char *); |
23 | extern void regprint(); | 26 | extern void regprint(regex_t *, FILE *); |
24 | 27 | ||
25 | /* | 28 | /* |
26 | - main - do the simple case, hand off to regress() for regression | 29 | - main - do the simple case, hand off to regress() for regression |
27 | */ | 30 | */ |
28 | main(argc, argv) | 31 | int |
29 | int argc; | 32 | main(int argc, char *argv[]) |
30 | char *argv[]; | 33 | |
31 | { | 34 | { |
32 | regex_t re; | 35 | regex_t re; |
33 | # define NS 10 | 36 | # define NS 10 |
@@ -43,7 +46,7 @@ char *argv[]; | |||
43 | 46 | ||
44 | progname = argv[0]; | 47 | progname = argv[0]; |
45 | 48 | ||
46 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) | 49 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1) |
47 | switch (c) { | 50 | switch (c) { |
48 | case 'c': /* compile options */ | 51 | case 'c': /* compile options */ |
49 | copts = options('c', optarg); | 52 | copts = options('c', optarg); |
@@ -79,7 +82,7 @@ char *argv[]; | |||
79 | err = regcomp(&re, argv[optind++], copts); | 82 | err = regcomp(&re, argv[optind++], copts); |
80 | if (err) { | 83 | if (err) { |
81 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 84 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
82 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 85 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
83 | eprint(err), len, sizeof(erbuf), erbuf); | 86 | eprint(err), len, sizeof(erbuf), erbuf); |
84 | exit(status); | 87 | exit(status); |
85 | } | 88 | } |
@@ -97,15 +100,15 @@ char *argv[]; | |||
97 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | 100 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); |
98 | if (err) { | 101 | if (err) { |
99 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 102 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
100 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 103 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
101 | eprint(err), len, sizeof(erbuf), erbuf); | 104 | eprint(err), len, sizeof(erbuf), erbuf); |
102 | exit(status); | 105 | exit(status); |
103 | } | 106 | } |
104 | if (!(copts®_NOSUB)) { | 107 | if (!(copts®_NOSUB)) { |
105 | len = (int)(subs[0].rm_eo - subs[0].rm_so); | 108 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); |
106 | if (subs[0].rm_so != -1) { | 109 | if (subs[0].rm_so != -1) { |
107 | if (len != 0) | 110 | if (len != 0) |
108 | printf("match `%.*s'\n", len, | 111 | printf("match `%.*s'\n", (int)len, |
109 | argv[optind] + subs[0].rm_so); | 112 | argv[optind] + subs[0].rm_so); |
110 | else | 113 | else |
111 | printf("match `'@%.1s\n", | 114 | printf("match `'@%.1s\n", |
@@ -144,7 +147,7 @@ FILE *in; | |||
144 | line++; | 147 | line++; |
145 | if (inbuf[0] == '#' || inbuf[0] == '\n') | 148 | if (inbuf[0] == '#' || inbuf[0] == '\n') |
146 | continue; /* NOTE CONTINUE */ | 149 | continue; /* NOTE CONTINUE */ |
147 | inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ | 150 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ |
148 | if (debug) | 151 | if (debug) |
149 | fprintf(stdout, "%d:\n", line); | 152 | fprintf(stdout, "%d:\n", line); |
150 | nf = split(inbuf, f, MAXF, "\t\t"); | 153 | nf = split(inbuf, f, MAXF, "\t\t"); |
@@ -225,14 +228,14 @@ int opts; /* may not match f1 */ | |||
225 | char f0copy[1000]; | 228 | char f0copy[1000]; |
226 | char f2copy[1000]; | 229 | char f2copy[1000]; |
227 | 230 | ||
228 | strcpy(f0copy, f0); | 231 | strlcpy(f0copy, f0, sizeof f0copy); |
229 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | 232 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; |
230 | fixstr(f0copy); | 233 | fixstr(f0copy); |
231 | err = regcomp(&re, f0copy, opts); | 234 | err = regcomp(&re, f0copy, opts); |
232 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | 235 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { |
233 | /* unexpected error or wrong error */ | 236 | /* unexpected error or wrong error */ |
234 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 237 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
235 | fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n", | 238 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", |
236 | line, type, eprint(err), len, | 239 | line, type, eprint(err), len, |
237 | sizeof(erbuf), erbuf); | 240 | sizeof(erbuf), erbuf); |
238 | status = 1; | 241 | status = 1; |
@@ -249,7 +252,7 @@ int opts; /* may not match f1 */ | |||
249 | return; | 252 | return; |
250 | } | 253 | } |
251 | 254 | ||
252 | strcpy(f2copy, f2); | 255 | strlcpy(f2copy, f2, sizeof f2copy); |
253 | fixstr(f2copy); | 256 | fixstr(f2copy); |
254 | 257 | ||
255 | if (options('e', f1)®_STARTEND) { | 258 | if (options('e', f1)®_STARTEND) { |
@@ -263,7 +266,7 @@ int opts; /* may not match f1 */ | |||
263 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | 266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { |
264 | /* unexpected error or wrong error */ | 267 | /* unexpected error or wrong error */ |
265 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
266 | fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n", | 269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", |
267 | line, type, eprint(err), len, | 270 | line, type, eprint(err), len, |
268 | sizeof(erbuf), erbuf); | 271 | sizeof(erbuf), erbuf); |
269 | status = 1; | 272 | status = 1; |
@@ -427,8 +430,9 @@ char *should; | |||
427 | (sub.rm_so != -1 && sub.rm_eo == -1) || | 430 | (sub.rm_so != -1 && sub.rm_eo == -1) || |
428 | (sub.rm_so != -1 && sub.rm_so < 0) || | 431 | (sub.rm_so != -1 && sub.rm_so < 0) || |
429 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | 432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { |
430 | sprintf(grump, "start %ld end %ld", (long)sub.rm_so, | 433 | snprintf(grump, sizeof grump, |
431 | (long)sub.rm_eo); | 434 | "start %ld end %ld", (long)sub.rm_so, |
435 | (long)sub.rm_eo); | ||
432 | return(grump); | 436 | return(grump); |
433 | } | 437 | } |
434 | 438 | ||
@@ -440,8 +444,9 @@ char *should; | |||
440 | 444 | ||
441 | /* check for in range */ | 445 | /* check for in range */ |
442 | if (sub.rm_eo > strlen(str)) { | 446 | if (sub.rm_eo > strlen(str)) { |
443 | sprintf(grump, "start %ld end %ld, past end of string", | 447 | snprintf(grump, sizeof grump, |
444 | (long)sub.rm_so, (long)sub.rm_eo); | 448 | "start %ld end %ld, past end of string", |
449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
445 | return(grump); | 450 | return(grump); |
446 | } | 451 | } |
447 | 452 | ||
@@ -451,13 +456,13 @@ char *should; | |||
451 | 456 | ||
452 | /* check for not supposed to match */ | 457 | /* check for not supposed to match */ |
453 | if (should == NULL) { | 458 | if (should == NULL) { |
454 | sprintf(grump, "matched `%.*s'", len, p); | 459 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); |
455 | return(grump); | 460 | return(grump); |
456 | } | 461 | } |
457 | 462 | ||
458 | /* check for wrong match */ | 463 | /* check for wrong match */ |
459 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | 464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { |
460 | sprintf(grump, "matched `%.*s' instead", len, p); | 465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); |
461 | return(grump); | 466 | return(grump); |
462 | } | 467 | } |
463 | if (shlen > 0) | 468 | if (shlen > 0) |
@@ -470,7 +475,7 @@ char *should; | |||
470 | if (shlen == 0) | 475 | if (shlen == 0) |
471 | shlen = 1; /* force check for end-of-string */ | 476 | shlen = 1; /* force check for end-of-string */ |
472 | if (strncmp(p, at, shlen) != 0) { | 477 | if (strncmp(p, at, shlen) != 0) { |
473 | sprintf(grump, "matched null at `%.20s'", p); | 478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); |
474 | return(grump); | 479 | return(grump); |
475 | } | 480 | } |
476 | return(NULL); | 481 | return(NULL); |
@@ -501,10 +506,9 @@ efind(name) | |||
501 | char *name; | 506 | char *name; |
502 | { | 507 | { |
503 | static char efbuf[100]; | 508 | static char efbuf[100]; |
504 | size_t n; | ||
505 | regex_t re; | 509 | regex_t re; |
506 | 510 | ||
507 | sprintf(efbuf, "REG_%s", name); | 511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); |
508 | assert(strlen(efbuf) < sizeof(efbuf)); | 512 | assert(strlen(efbuf) < sizeof(efbuf)); |
509 | re.re_endp = efbuf; | 513 | re.re_endp = efbuf; |
510 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | 514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); |
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih index 135e3e792d..0860e26333 100644 --- a/src/regress/lib/libc/regex/main.ih +++ b/src/regress/lib/libc/regex/main.ih | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
1 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | 2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ |
2 | 3 | ||
3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
@@ -6,14 +7,14 @@ extern "C" { | |||
6 | #endif | 7 | #endif |
7 | 8 | ||
8 | /* === main.c === */ | 9 | /* === main.c === */ |
9 | void regress __P((FILE *in)); | 10 | void regress(FILE *in); |
10 | void try __P((char *f0, char *f1, char *f2, char *f3, char *f4, int opts)); | 11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); |
11 | int options __P((int type, char *s)); | 12 | int options(int type, char *s); |
12 | int opt __P((int c, char *s)); | 13 | int opt(int c, char *s); |
13 | void fixstr __P((register char *p)); | 14 | void fixstr(register char *p); |
14 | char *check __P((char *str, regmatch_t sub, char *should)); | 15 | char *check(char *str, regmatch_t sub, char *should); |
15 | static char *eprint __P((int err)); | 16 | static char *eprint(int err); |
16 | static int efind __P((char *name)); | 17 | static int efind(char *name); |
17 | 18 | ||
18 | #ifdef __cplusplus | 19 | #ifdef __cplusplus |
19 | } | 20 | } |
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c index dd1ca14480..fcd81a3503 100644 --- a/src/regress/lib/libc/regex/split.c +++ b/src/regress/lib/libc/regex/split.c | |||
@@ -1,18 +1,17 @@ | |||
1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
1 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | 2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ |
2 | 3 | ||
3 | #include <stdio.h> | 4 | #include <stdio.h> |
4 | #include <string.h> | 5 | #include <string.h> |
5 | 6 | ||
7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
8 | |||
6 | /* | 9 | /* |
7 | - split - divide a string into fields, like awk split() | 10 | - split - divide a string into fields, like awk split() |
8 | = int split(char *string, char *fields[], int nfields, char *sep); | 11 | = int split(char *string, char *fields[], int nfields, char *sep); |
9 | */ | 12 | */ |
10 | int /* number of fields, including overflow */ | 13 | int /* number of fields, including overflow */ |
11 | split(string, fields, nfields, sep) | 14 | split(char *string, char *fields[], int nfields, char *sep) |
12 | char *string; | ||
13 | char *fields[]; /* list is not NULL-terminated */ | ||
14 | int nfields; /* number of entries available in fields[] */ | ||
15 | char *sep; /* "" white, "c" single char, "ab" [ab]+ */ | ||
16 | { | 15 | { |
17 | register char *p = string; | 16 | register char *p = string; |
18 | register char c; /* latest character */ | 17 | register char c; /* latest character */ |
@@ -161,18 +160,18 @@ char *argv[]; | |||
161 | 160 | ||
162 | if (argc > 4) | 161 | if (argc > 4) |
163 | for (n = atoi(argv[3]); n > 0; n--) { | 162 | for (n = atoi(argv[3]); n > 0; n--) { |
164 | (void) strcpy(buf, argv[1]); | 163 | (void) strlcpy(buf, argv[1], sizeof buf); |
165 | } | 164 | } |
166 | else if (argc > 3) | 165 | else if (argc > 3) |
167 | for (n = atoi(argv[3]); n > 0; n--) { | 166 | for (n = atoi(argv[3]); n > 0; n--) { |
168 | (void) strcpy(buf, argv[1]); | 167 | (void) strlcpy(buf, argv[1], sizeof buf); |
169 | (void) split(buf, fields, MNF, argv[2]); | 168 | (void) split(buf, fields, MNF, argv[2]); |
170 | } | 169 | } |
171 | else if (argc > 2) | 170 | else if (argc > 2) |
172 | dosplit(argv[1], argv[2]); | 171 | dosplit(argv[1], argv[2]); |
173 | else if (argc > 1) | 172 | else if (argc > 1) |
174 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | 173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { |
175 | buf[strlen(buf)-1] = '\0'; /* stomp newline */ | 174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ |
176 | dosplit(buf, argv[1]); | 175 | dosplit(buf, argv[1]); |
177 | } | 176 | } |
178 | else | 177 | else |
@@ -287,7 +286,7 @@ regress() | |||
287 | register char *f; | 286 | register char *f; |
288 | 287 | ||
289 | for (n = 0; tests[n].str != NULL; n++) { | 288 | for (n = 0; tests[n].str != NULL; n++) { |
290 | (void) strcpy(buf, tests[n].str); | 289 | (void) strlcpy(buf, tests[n].str, sizeof buf); |
291 | fields[RNF] = NULL; | 290 | fields[RNF] = NULL; |
292 | nf = split(buf, fields, RNF, tests[n].seps); | 291 | nf = split(buf, fields, RNF, tests[n].seps); |
293 | printit = 0; | 292 | printit = 0; |
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests index 8e89f161b1..c827c868b7 100644 --- a/src/regress/lib/libc/regex/tests +++ b/src/regress/lib/libc/regex/tests | |||
@@ -1,3 +1,4 @@ | |||
1 | # $OpenBSD: tests,v 1.5 2004/11/29 16:50:31 otto Exp $ | ||
1 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | 2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ |
2 | 3 | ||
3 | # regular expression test set | 4 | # regular expression test set |
@@ -168,6 +169,30 @@ a\(\(b\)*\2\)*d b abbbd abbbd | |||
168 | \(a\)\1bc*d b aabcccd aabcccd | 169 | \(a\)\1bc*d b aabcccd aabcccd |
169 | \(a\)\1bc*[ce]d b aabcccd aabcccd | 170 | \(a\)\1bc*[ce]d b aabcccd aabcccd |
170 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | 171 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd |
172 | \(b*\)\(a*\1\)* b ab a | ||
173 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
174 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
175 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
176 | \(.*\)\1 b "" "" | ||
177 | \(.*\)\1 b a "" | ||
178 | \(.*\)\1 b aa aa | ||
179 | \(.*\)\1 b aaa aa | ||
180 | \(.*\)\1 b aaaa aaaa | ||
181 | \([^_]*\)\1 b "" "" | ||
182 | \([^_]*\)\1 b a "" | ||
183 | \([^_]*\)\1 b aa aa | ||
184 | \([^_]*\)\1 b aaa aa | ||
185 | \([^_]*\)\1 b aaaa aaaa | ||
186 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
187 | foo\(.*\)bar\1 b foobar foobar "" | ||
188 | \(\(.\)b\)*\1 b aba | ||
189 | \(\(.\)b\)*\1 b abba | ||
190 | \(\(.\)b\)*\1 b abbba | ||
191 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
192 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
193 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
194 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
195 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
171 | 196 | ||
172 | # ordinary repetitions | 197 | # ordinary repetitions |
173 | ab*c & abc abc | 198 | ab*c & abc abc |
@@ -475,3 +500,4 @@ CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | |||
475 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | 500 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz |
476 | a?b - ab ab | 501 | a?b - ab ab |
477 | -\{0,1\}[0-9]*$ b -5 -5 | 502 | -\{0,1\}[0-9]*$ b -5 -5 |
503 | |||
diff --git a/src/regress/lib/libc/setjmp-signal/Makefile b/src/regress/lib/libc/setjmp-signal/Makefile new file mode 100644 index 0000000000..a9649a8abe --- /dev/null +++ b/src/regress/lib/libc/setjmp-signal/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2002/07/31 05:18:24 art Exp $ | ||
2 | |||
3 | PROG= setjmp-signal | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/setjmp-signal/setjmp-signal.c b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c new file mode 100644 index 0000000000..310e4052ef --- /dev/null +++ b/src/regress/lib/libc/setjmp-signal/setjmp-signal.c | |||
@@ -0,0 +1,26 @@ | |||
1 | /* $OpenBSD: setjmp-signal.c,v 1.3 2003/01/03 20:46:05 miod Exp $ */ | ||
2 | /* | ||
3 | * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain. | ||
4 | */ | ||
5 | |||
6 | #include <setjmp.h> | ||
7 | #include <signal.h> | ||
8 | |||
9 | jmp_buf jb; | ||
10 | |||
11 | void | ||
12 | segv_handler(int signum) | ||
13 | { | ||
14 | longjmp(jb, 1); | ||
15 | } | ||
16 | |||
17 | int | ||
18 | main() | ||
19 | { | ||
20 | signal(SIGSEGV, segv_handler); | ||
21 | if (setjmp(jb) == 0) { | ||
22 | *((int *)0L) = 0; | ||
23 | return (1); | ||
24 | } | ||
25 | return (0); | ||
26 | } | ||
diff --git a/src/regress/lib/libc/setjmp/Makefile b/src/regress/lib/libc/setjmp/Makefile index 25bf99d4cb..fc68e8d44c 100644 --- a/src/regress/lib/libc/setjmp/Makefile +++ b/src/regress/lib/libc/setjmp/Makefile | |||
@@ -1,16 +1,9 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/01/01 23:00:51 art Exp $ | ||
1 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:13 cgd Exp $ |
2 | 3 | ||
3 | PROG= setjmptest | 4 | PROG= setjmptest |
4 | SRCS= jmptest.c | 5 | SRCS= jmptest.c |
5 | NOMAN= noman, no way, man | ||
6 | 6 | ||
7 | CFLAGS+= -DTEST_SETJMP | 7 | CFLAGS+= -DTEST_SETJMP |
8 | 8 | ||
9 | .PATH: ${.CURDIR}/../setjmp | 9 | .include <bsd.regress.mk> |
10 | |||
11 | install: | ||
12 | |||
13 | regress: ${PROG} | ||
14 | ./${PROG} | ||
15 | |||
16 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c index f2cecc9178..9512c9ee34 100644 --- a/src/regress/lib/libc/setjmp/jmptest.c +++ b/src/regress/lib/libc/setjmp/jmptest.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: jmptest.c,v 1.7 2003/09/02 23:52:16 david Exp $ */ | ||
1 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | 2 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ |
2 | 3 | ||
3 | /* | 4 | /* |
@@ -32,10 +33,12 @@ | |||
32 | */ | 33 | */ |
33 | 34 | ||
34 | #include <sys/types.h> | 35 | #include <sys/types.h> |
36 | #include <err.h> | ||
35 | #include <setjmp.h> | 37 | #include <setjmp.h> |
36 | #include <signal.h> | 38 | #include <signal.h> |
37 | #include <stdio.h> | 39 | #include <stdio.h> |
38 | #include <stdlib.h> | 40 | #include <stdlib.h> |
41 | #include <string.h> | ||
39 | #include <unistd.h> | 42 | #include <unistd.h> |
40 | 43 | ||
41 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | 44 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 |
@@ -62,21 +65,20 @@ | |||
62 | 65 | ||
63 | int expectsignal; | 66 | int expectsignal; |
64 | 67 | ||
65 | void | 68 | static void |
66 | aborthandler(signo) | 69 | aborthandler(int signo) |
67 | int signo; | ||
68 | { | 70 | { |
69 | 71 | ||
70 | if (expectsignal) | 72 | if (expectsignal) |
71 | exit(0); | 73 | _exit(0); |
72 | else | 74 | else { |
73 | errx(1, "kill(SIGABRT) succeeded"); | 75 | warnx("kill(SIGABRT) succeeded"); |
76 | _exit(1); | ||
77 | } | ||
74 | } | 78 | } |
75 | 79 | ||
76 | int | 80 | int |
77 | main(argc, argv) | 81 | main(int argc, char *argv[]) |
78 | int argc; | ||
79 | char *argv[]; | ||
80 | { | 82 | { |
81 | struct sigaction sa; | 83 | struct sigaction sa; |
82 | BUF jb; | 84 | BUF jb; |
@@ -101,7 +103,7 @@ main(argc, argv) | |||
101 | #endif | 103 | #endif |
102 | 104 | ||
103 | sa.sa_handler = aborthandler; | 105 | sa.sa_handler = aborthandler; |
104 | sa.sa_mask = 0; | 106 | sigemptyset(&sa.sa_mask); |
105 | sa.sa_flags = 0; | 107 | sa.sa_flags = 0; |
106 | if (sigaction(SIGABRT, &sa, NULL) == -1) | 108 | if (sigaction(SIGABRT, &sa, NULL) == -1) |
107 | err(1, "sigaction failed"); | 109 | err(1, "sigaction failed"); |
diff --git a/src/regress/lib/libc/sigreturn/Makefile b/src/regress/lib/libc/sigreturn/Makefile new file mode 100644 index 0000000000..9891ba9e05 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/Makefile | |||
@@ -0,0 +1,18 @@ | |||
1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
2 | |||
3 | PROG= sigret | ||
4 | |||
5 | DEBUG+= -ggdb | ||
6 | |||
7 | REGRESS_TARGETS+= sigret-normal sigret-indirect sigret-altstack | ||
8 | |||
9 | sigret-normal: ${PROG} | ||
10 | ./${PROG} | ||
11 | |||
12 | sigret-indirect: ${PROG} | ||
13 | ./${PROG} -i | ||
14 | |||
15 | sigret-altstack: ${PROG} | ||
16 | ./${PROG} -a | ||
17 | |||
18 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sigreturn/sigret.c b/src/regress/lib/libc/sigreturn/sigret.c new file mode 100644 index 0000000000..72945fa503 --- /dev/null +++ b/src/regress/lib/libc/sigreturn/sigret.c | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * $OpenBSD: sigret.c,v 1.5 2003/07/31 21:48:04 deraadt Exp $ | ||
3 | * | ||
4 | * Public Domain | ||
5 | * | ||
6 | * Playing games with sigreturn. Check if calling sigreturn from a | ||
7 | * signal handler screws anything up. | ||
8 | * | ||
9 | * Run with: | ||
10 | * -a: use an alternate signal stack | ||
11 | * | ||
12 | * -b: call sigreturn from outside of a signal handler | ||
13 | * An error is OK | ||
14 | * | ||
15 | * -c: clobber the sigcontext before calling sigreturn | ||
16 | * the program should die | ||
17 | * | ||
18 | * -f: don't use sigreturn -- fall through the signal handler | ||
19 | * -c, and -i options ignored when used | ||
20 | * | ||
21 | * -i: call sigreturn from a function called by the signal handler | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <sys/time.h> | ||
26 | |||
27 | #include <err.h> | ||
28 | #include <signal.h> | ||
29 | #include <stdarg.h> | ||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | #include <unistd.h> | ||
34 | |||
35 | /* | ||
36 | * sigalarm occurs 50 times/second. Stop running after 10 seconds | ||
37 | * (100 interrupts). | ||
38 | */ | ||
39 | #define MAX_INTERRUPTS 500 | ||
40 | |||
41 | int failed; | ||
42 | int altstack; | ||
43 | int badcall; | ||
44 | int clobbercall; | ||
45 | int fallthru; | ||
46 | int indirect; | ||
47 | |||
48 | volatile int count; | ||
49 | struct sigcontext gscp; | ||
50 | int gscp_loaded; | ||
51 | |||
52 | static void | ||
53 | usage(const char * err, ...) | ||
54 | { | ||
55 | extern const char * __progname; | ||
56 | |||
57 | if (err) { | ||
58 | va_list ap; | ||
59 | va_start(ap, err); | ||
60 | vwarnx(err, ap); | ||
61 | va_end(ap); | ||
62 | } | ||
63 | fprintf(stderr, "usage: %s [-abcfi]\n", __progname); | ||
64 | exit(1); | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | indirect_return(struct sigcontext * scp) | ||
69 | { | ||
70 | sigreturn(scp); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | sig_handler(int sig, siginfo_t *blah, void *x) | ||
75 | { | ||
76 | struct sigcontext * scp = x; | ||
77 | |||
78 | count++; | ||
79 | |||
80 | if (!fallthru) { | ||
81 | if (clobbercall) | ||
82 | memset(scp, 0, sizeof *scp); | ||
83 | if (indirect) | ||
84 | indirect_return(scp); | ||
85 | else if (badcall) { | ||
86 | gscp = *scp; | ||
87 | gscp_loaded = 1; | ||
88 | } else | ||
89 | sigreturn(scp); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | static void | ||
94 | test2(char *fmt) | ||
95 | { | ||
96 | char *ofmt = fmt; | ||
97 | |||
98 | if (gscp_loaded) { | ||
99 | gscp_loaded = 0; | ||
100 | sigreturn(&gscp); | ||
101 | } | ||
102 | |||
103 | for (; *fmt; fmt++) | ||
104 | switch (*fmt) { | ||
105 | case 'i': | ||
106 | case 'c': | ||
107 | case 'l': | ||
108 | case 'p': | ||
109 | break; | ||
110 | default: | ||
111 | failed = 1; | ||
112 | fprintf(stderr, | ||
113 | "unexpected character 0x%02x `%c' in %s: count %d\n", | ||
114 | *fmt, *fmt, ofmt, count); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | int | ||
119 | main(int argc, char * argv[]) | ||
120 | { | ||
121 | extern char *optarg; | ||
122 | extern int optind; | ||
123 | |||
124 | int opt; | ||
125 | |||
126 | struct sigaction act; | ||
127 | struct sigaltstack ss; | ||
128 | |||
129 | while ((opt = getopt(argc, argv, "abcfi")) != -1) { | ||
130 | switch (opt) { | ||
131 | case 'a': | ||
132 | /* use sigaltstack */ | ||
133 | altstack = 1; | ||
134 | break; | ||
135 | case 'b': | ||
136 | /* call outside of sig_handler */ | ||
137 | badcall = 1; | ||
138 | break; | ||
139 | case 'c': | ||
140 | /* force error by munging sigcontext */ | ||
141 | clobbercall = 1; | ||
142 | break; | ||
143 | case 'f': | ||
144 | /* don't use sigreturn */ | ||
145 | fallthru = 1; | ||
146 | break; | ||
147 | case 'i': | ||
148 | /* call sigreturn indirectly */ | ||
149 | indirect = 1; | ||
150 | break; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /* make sure there is no other cruft left on the command line */ | ||
155 | if (optind != argc) | ||
156 | usage("unknown argument -- %s", argv[ optind ]); | ||
157 | |||
158 | if (altstack) { | ||
159 | if ((ss.ss_sp = malloc(SIGSTKSZ)) == NULL) | ||
160 | errx(1, "ss_sp malloc"); | ||
161 | |||
162 | ss.ss_size = SIGSTKSZ; | ||
163 | ss.ss_flags = 0; | ||
164 | if (sigaltstack(&ss,0) == -1) | ||
165 | err(1, "sigaltstack"); | ||
166 | } | ||
167 | |||
168 | sigfillset(&act.sa_mask); | ||
169 | act.sa_sigaction = sig_handler; | ||
170 | act.sa_flags = SA_RESTART; | ||
171 | if (altstack) | ||
172 | act.sa_flags |= SA_ONSTACK; | ||
173 | sigaction(SIGALRM, &act, NULL); | ||
174 | |||
175 | ualarm(10000, 10000); | ||
176 | |||
177 | while (count < MAX_INTERRUPTS) | ||
178 | test2("iclp"); | ||
179 | |||
180 | return failed; | ||
181 | } | ||
diff --git a/src/regress/lib/libc/sigsetjmp/Makefile b/src/regress/lib/libc/sigsetjmp/Makefile index 41682fcb66..f88bea3b47 100644 --- a/src/regress/lib/libc/sigsetjmp/Makefile +++ b/src/regress/lib/libc/sigsetjmp/Makefile | |||
@@ -1,17 +1,19 @@ | |||
1 | # $NetBSD: Makefile,v 1.2 1995/04/20 22:40:40 cgd Exp $ | 1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ |
2 | 2 | ||
3 | PROG= sigsetjmptest | 3 | PROG= sigsetjmptest |
4 | SRCS= jmptest.c | 4 | SRCS= jmptest.c |
5 | NOMAN= noman, no way, man | ||
6 | 5 | ||
7 | CFLAGS+= -DTEST_SIGSETJMP | 6 | CFLAGS+= -DTEST_SIGSETJMP |
8 | 7 | ||
9 | .PATH: ${.CURDIR}/../setjmp | 8 | .PATH: ${.CURDIR}/../setjmp |
10 | 9 | ||
11 | install: | 10 | REGRESS_TARGETS=sigsetjmp-save sigsetjmp-nosave |
12 | 11 | ||
13 | regress: ${PROG} | 12 | sigsetjmp-save: ${PROG} |
14 | ./${PROG} save | 13 | ./${PROG} save |
14 | sigsetjmp-nosave: ${PROG} | ||
15 | ./${PROG} nosave | 15 | ./${PROG} nosave |
16 | 16 | ||
17 | .include <bsd.prog.mk> | 17 | .PHONY: ${REGRESS_TARGETS} |
18 | |||
19 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/Makefile b/src/regress/lib/libc/sleep/Makefile new file mode 100644 index 0000000000..3700b1662a --- /dev/null +++ b/src/regress/lib/libc/sleep/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2009/12/14 05:08:19 guenther Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=sleep_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | run-regress-${PROG}: ${PROG} | ||
8 | [ x$$(./${PROG} 1) = x0 ] || exit 1 | ||
9 | file=$$(mktemp -t sleep.XXXXXXXXXX); ./${PROG} 4 >$$file & pid=$$!; \ | ||
10 | sleep 1; kill $$pid; sleep 1; v=$$(cat $$file); rm -f $$file; \ | ||
11 | { [ $$v -gt 0 ] && [ $$v -lt 4 ] ; } || exit 2 | ||
12 | |||
13 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sleep/sleep_test.c b/src/regress/lib/libc/sleep/sleep_test.c new file mode 100644 index 0000000000..c9ab0d095f --- /dev/null +++ b/src/regress/lib/libc/sleep/sleep_test.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* $OpenBSD: sleep_test.c,v 1.1 2009/12/14 05:08:19 guenther Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2009 Philip Guenther | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | /* | ||
33 | * Test whether sleep returns the correct value | ||
34 | */ | ||
35 | |||
36 | #include <sys/types.h> | ||
37 | #include <err.h> | ||
38 | #include <errno.h> | ||
39 | #include <limits.h> | ||
40 | #include <signal.h> | ||
41 | #include <stddef.h> | ||
42 | #include <stdio.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <unistd.h> | ||
45 | |||
46 | static void | ||
47 | handler(int sig) | ||
48 | { | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | static void * | ||
53 | garbage(void) | ||
54 | { | ||
55 | char buf[20]; | ||
56 | strlcpy(buf, "012354678901235467890123546789", sizeof buf); | ||
57 | return buf; | ||
58 | } | ||
59 | |||
60 | int | ||
61 | main(int argc, char *argv[]) | ||
62 | { | ||
63 | struct sigaction sa; | ||
64 | char const *errstr; | ||
65 | int i; | ||
66 | |||
67 | if (argc != 2) | ||
68 | return (1); | ||
69 | errno = 0; | ||
70 | i = strtonum(argv[1], 0, INT_MAX, &errstr); | ||
71 | if (i == 0 && errno != 0) { | ||
72 | fprintf(stderr, "%s\n", errstr); | ||
73 | return (1); | ||
74 | } | ||
75 | |||
76 | memset(&sa, 0, sizeof sa); | ||
77 | sa.sa_handler = &handler; | ||
78 | if (sigaction(SIGTERM, &sa, NULL)) | ||
79 | err(3, "sigaction"); | ||
80 | garbage(); | ||
81 | printf("%d\n", sleep(i)); | ||
82 | return (0); | ||
83 | } | ||
84 | |||
diff --git a/src/regress/lib/libc/sprintf/Makefile b/src/regress/lib/libc/sprintf/Makefile new file mode 100644 index 0000000000..47bab9cdd3 --- /dev/null +++ b/src/regress/lib/libc/sprintf/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2003/05/15 04:23:49 deraadt Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=sprintf_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | |||
7 | run-regress-atexit_test: ${PROG} | ||
8 | ./${PROG} | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/sprintf/sprintf_test.c b/src/regress/lib/libc/sprintf/sprintf_test.c new file mode 100644 index 0000000000..61c58f2f09 --- /dev/null +++ b/src/regress/lib/libc/sprintf/sprintf_test.c | |||
@@ -0,0 +1,102 @@ | |||
1 | /* $OpenBSD: sprintf_test.c,v 1.4 2004/09/18 19:31:32 otto Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2003 Theo de Raadt | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * - Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * - Redistributions in binary form must reproduce the above | ||
14 | * copyright notice, this list of conditions and the following | ||
15 | * disclaimer in the documentation and/or other materials provided | ||
16 | * with the distribution. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
28 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | * POSSIBILITY OF SUCH DAMAGE. | ||
30 | */ | ||
31 | |||
32 | #include <stddef.h> | ||
33 | #include <stdio.h> | ||
34 | #include <stdlib.h> | ||
35 | #include <string.h> | ||
36 | #include <signal.h> | ||
37 | |||
38 | char correct[] = | ||
39 | "|xx 01 02 03 04\n" | ||
40 | "|xx 05 06 07 08\n" | ||
41 | "|xx 09 10 11 12\n" | ||
42 | "|xx 13 14 15 16\n" | ||
43 | "|xx 17 18 19 20\n" | ||
44 | "|xx 21 22 23 24\n" | ||
45 | "|xx 25 26 27 28\n" | ||
46 | "|xx 29 30 31 32\n" | ||
47 | "|xx 33 34 35 36\n" | ||
48 | "|xx 37 38 39 40\n" | ||
49 | "|xx 41 42 43 44\n" | ||
50 | "|xx 45 -1 1 -1 1\n"; | ||
51 | |||
52 | char correct2[] = | ||
53 | "1 0 -1 1 1 2 1 3 -1 4 1 \n" | ||
54 | "1 -1 1 1 -1 1 \n"; | ||
55 | |||
56 | int | ||
57 | main(int argc, char *argv[]) | ||
58 | { | ||
59 | char buf[1024]; | ||
60 | size_t sz1, sz2, sz3, sz4; | ||
61 | ptrdiff_t p1, p2, p3, p4; | ||
62 | |||
63 | /* Test positional arguments */ | ||
64 | snprintf(buf, sizeof buf, | ||
65 | "|xx %1$s %2$s %3$s %4$s\n" | ||
66 | "|xx %5$s %6$s %7$s %8$s\n" | ||
67 | "|xx %9$s %10$s %11$s %12$s\n" | ||
68 | "|xx %13$s %14$s %15$s %16$s\n" | ||
69 | "|xx %17$s %18$s %19$s %20$s\n" | ||
70 | "|xx %21$s %22$s %23$s %24$s\n" | ||
71 | "|xx %25$s %26$s %27$s %28$s\n" | ||
72 | "|xx %29$s %30$s %31$s %32$s\n" | ||
73 | "|xx %33$s %34$s %35$s %36$s\n" | ||
74 | "|xx %37$s %38$s %39$s %40$s\n" | ||
75 | "|xx %41$s %42$s %43$s %44$s\n" | ||
76 | "|xx %45$d %46$ld %47$lld %48$d %49$lld\n", | ||
77 | "01", "02", "03", "04", "05", "06", | ||
78 | "07", "08", "09", "10", "11", "12", | ||
79 | "13", "14", "15", "16", "17", "18", | ||
80 | "19", "20", "21", "22", "23", "24", | ||
81 | "25", "26", "27", "28", "29", "30", | ||
82 | "31", "32", "33", "34", "35", "36", | ||
83 | "37", "38", "39", "40", "41", "42", | ||
84 | "43", "44", 45, -1L, 1LL, -1, 1LL | ||
85 | ); | ||
86 | |||
87 | if (strcmp(buf, correct) != 0) | ||
88 | exit(1); | ||
89 | |||
90 | sz1 = (size_t)1; | ||
91 | sz2 = (size_t)-1; | ||
92 | p1 = (ptrdiff_t)1; | ||
93 | p2 = (ptrdiff_t)-1; | ||
94 | snprintf(buf, sizeof buf, | ||
95 | "%zx %d %zd %d %zu %d %tx %d %td %d %tu %zn %tn\n" | ||
96 | "%1$zx %3$zd %5$zu %7$tx %9$td %11$tu %14$zn %15$tn\n", | ||
97 | sz1, 0, sz2, 1, sz1, 2, p1, 3, p2, 4, p1, &sz3, &p3, &sz4, &p4); | ||
98 | if (strcmp(buf, correct2) != 0 || sz3 != 24 || p3 != 25 || | ||
99 | sz4 != 40 || p4 != 41) | ||
100 | exit(1); | ||
101 | exit(0); | ||
102 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/Makefile b/src/regress/lib/libc/stdio_threading/Makefile new file mode 100644 index 0000000000..e42481afc2 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | SUBDIR += fopen fread fwrite fgetln fgets fputs | ||
2 | |||
3 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/Makefile b/src/regress/lib/libc/stdio_threading/fgetln/Makefile new file mode 100644 index 0000000000..cad51e2b23 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgetln/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fgetln_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c new file mode 100755 index 0000000000..d5c4db2edf --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgetln/fgetln_test.c | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fgetln_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | size_t len; | ||
24 | char *buf; | ||
25 | int i; | ||
26 | |||
27 | for (i = 0; i < 4096; i++) { | ||
28 | if ((buf = fgetln(file, &len)) == NULL) { | ||
29 | |||
30 | if (feof(file)) | ||
31 | break; | ||
32 | |||
33 | printf("OMG!!!\n"); | ||
34 | fflush(stdout); | ||
35 | break; | ||
36 | } | ||
37 | if (strncmp(buf, TEXT_N, sizeof(TEXT_N))) | ||
38 | err(1, "fgetln not atomic!!!"); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | int | ||
43 | main(void) | ||
44 | { | ||
45 | char sfn[24]; | ||
46 | char buf[sizeof(TEXT_N)]; | ||
47 | FILE *sfp; | ||
48 | int fd, i; | ||
49 | |||
50 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
51 | if ((fd = mkstemp(sfn)) == -1 || | ||
52 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
53 | if (fd != -1) { | ||
54 | unlink(sfn); | ||
55 | close(fd); | ||
56 | } | ||
57 | err(1, "could not open temporary file"); | ||
58 | } | ||
59 | |||
60 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
61 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
62 | err(1, "Could not populate test file"); | ||
63 | |||
64 | run_threads(fgetln_thread, sfp); | ||
65 | |||
66 | unlink(sfn); | ||
67 | close(fd); | ||
68 | |||
69 | exit(0); | ||
70 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/Makefile b/src/regress/lib/libc/stdio_threading/fgets/Makefile new file mode 100644 index 0000000000..52310fd429 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgets/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fgets_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c new file mode 100755 index 0000000000..685d4c8257 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fgets/fgets_test.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fgets_thread(void *v) | ||
21 | { | ||
22 | char buf[sizeof(TEXT_N) + 1]; | ||
23 | FILE *file = v; | ||
24 | int i; | ||
25 | |||
26 | for (i = 0; i < 4096; i++) { | ||
27 | if (fgets(buf, sizeof(buf), file) == NULL) { | ||
28 | |||
29 | if (feof(file)) | ||
30 | break; | ||
31 | |||
32 | printf("OMG!!!\n"); | ||
33 | fflush(stdout); | ||
34 | break; | ||
35 | } | ||
36 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
37 | err(1, "Read not atomic!!!"); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | int | ||
42 | main(void) | ||
43 | { | ||
44 | char sfn[24]; | ||
45 | char buf[sizeof(TEXT)]; | ||
46 | FILE *sfp; | ||
47 | int fd, i; | ||
48 | |||
49 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
50 | if ((fd = mkstemp(sfn)) == -1 || | ||
51 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
52 | if (fd != -1) { | ||
53 | unlink(sfn); | ||
54 | close(fd); | ||
55 | } | ||
56 | err(1, "could not open temporary file"); | ||
57 | } | ||
58 | |||
59 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
60 | if (fwrite(TEXT_N, sizeof(char), strlen(TEXT_N), sfp) == 0) | ||
61 | err(1, "Could not populate test file"); | ||
62 | |||
63 | run_threads(fgets_thread, sfp); | ||
64 | |||
65 | unlink(sfn); | ||
66 | close(fd); | ||
67 | |||
68 | exit(0); | ||
69 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/Makefile b/src/regress/lib/libc/stdio_threading/fopen/Makefile new file mode 100644 index 0000000000..e51deeff1d --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fopen/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fopen_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c new file mode 100755 index 0000000000..72359bb323 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fopen/fopen_test.c | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <pthread.h> | ||
19 | #include "local.h" | ||
20 | |||
21 | int | ||
22 | writefn(void *cookie, const char *buf, int size) | ||
23 | { | ||
24 | return 0; | ||
25 | } | ||
26 | |||
27 | void | ||
28 | fopen_thread(void *v) | ||
29 | { | ||
30 | FILE *file; | ||
31 | int i; | ||
32 | |||
33 | for (i = 0; i < 4096; i++) { | ||
34 | file = fwopen(&i, writefn); | ||
35 | if (file != NULL) { | ||
36 | fputc('0', file); | ||
37 | pthread_yield(); | ||
38 | fclose(file); | ||
39 | } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | int | ||
44 | main(void) | ||
45 | { | ||
46 | run_threads(fopen_thread, NULL); | ||
47 | exit(0); | ||
48 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/Makefile b/src/regress/lib/libc/stdio_threading/fputs/Makefile new file mode 100644 index 0000000000..e561745581 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fputs/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fputs_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c new file mode 100755 index 0000000000..c0a617510e --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fputs/fputs_test.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fputs_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | int i; | ||
24 | |||
25 | for (i = 0; i < 4096; i++) { | ||
26 | if (fputs(TEXT, file) != 0) { | ||
27 | |||
28 | if (feof(file)) | ||
29 | break; | ||
30 | |||
31 | printf("OMG!!!\n"); | ||
32 | fflush(stdout); | ||
33 | break; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(void) | ||
40 | { | ||
41 | char sfn[24]; | ||
42 | char buf[sizeof(TEXT)]; | ||
43 | FILE *sfp; | ||
44 | int fd, i; | ||
45 | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
47 | if ((fd = mkstemp(sfn)) == -1 || | ||
48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
49 | if (fd != -1) { | ||
50 | unlink(sfn); | ||
51 | close(fd); | ||
52 | } | ||
53 | err(1, "could not open temporary file"); | ||
54 | } | ||
55 | |||
56 | run_threads(fputs_thread, sfp); | ||
57 | |||
58 | while (fgets(buf, sizeof(buf), sfp) != NULL) /* verify */ | ||
59 | if (strcmp(buf, TEXT)) | ||
60 | err(1, "Thread writes were not atomic!!!"); | ||
61 | |||
62 | unlink(sfn); | ||
63 | close(fd); | ||
64 | |||
65 | exit(0); | ||
66 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/Makefile b/src/regress/lib/libc/stdio_threading/fread/Makefile new file mode 100644 index 0000000000..25196dd7ab --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fread/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fread_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fread/fread_test.c b/src/regress/lib/libc/stdio_threading/fread/fread_test.c new file mode 100755 index 0000000000..b2372f5ab6 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fread/fread_test.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <pthread.h> | ||
19 | #include "local.h" | ||
20 | |||
21 | void | ||
22 | fread_thread(void *v) | ||
23 | { | ||
24 | char buf[sizeof(TEXT)]; | ||
25 | FILE *file = v; | ||
26 | int i; | ||
27 | |||
28 | for (i = 0; i < 4096; i++) { | ||
29 | if (fread(buf, sizeof(char), strlen(TEXT), file) == 0) { | ||
30 | |||
31 | if (feof(file)) | ||
32 | break; | ||
33 | |||
34 | printf("OMG!!!\n"); | ||
35 | fflush(stdout); | ||
36 | break; | ||
37 | } | ||
38 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
39 | err(1, "Read not atomic!!!"); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | int | ||
44 | main(void) | ||
45 | { | ||
46 | char sfn[24]; | ||
47 | char buf[sizeof(TEXT)]; | ||
48 | FILE *sfp; | ||
49 | int fd, i; | ||
50 | |||
51 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
52 | if ((fd = mkstemp(sfn)) == -1 || | ||
53 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
54 | if (fd != -1) { | ||
55 | unlink(sfn); | ||
56 | close(fd); | ||
57 | } | ||
58 | err(1, "could not open temporary file"); | ||
59 | } | ||
60 | |||
61 | for (i = 0; i < 4096 * THREAD_COUNT; i++) | ||
62 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), sfp) == 0) | ||
63 | err(1, "Could not populate test file"); | ||
64 | |||
65 | run_threads(fread_thread, sfp); | ||
66 | |||
67 | unlink(sfn); | ||
68 | close(fd); | ||
69 | |||
70 | exit(0); | ||
71 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/Makefile b/src/regress/lib/libc/stdio_threading/fwrite/Makefile new file mode 100644 index 0000000000..e79899c475 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fwrite/Makefile | |||
@@ -0,0 +1,6 @@ | |||
1 | TOPDIR=${.CURDIR} | ||
2 | PROG=fwrite_test | ||
3 | CFLAGS+=-I${TOPDIR}/../include/ | ||
4 | LDFLAGS+=-lpthread | ||
5 | |||
6 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c new file mode 100755 index 0000000000..39bfb51ef0 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/fwrite/fwrite_test.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "local.h" | ||
18 | |||
19 | void | ||
20 | fwrite_thread(void *v) | ||
21 | { | ||
22 | FILE *file = v; | ||
23 | int i; | ||
24 | |||
25 | for (i = 0; i < 4096; i++) { | ||
26 | if (fwrite(TEXT, sizeof(char), strlen(TEXT), file) == 0) { | ||
27 | |||
28 | if (feof(file)) | ||
29 | break; | ||
30 | |||
31 | printf("OMG!!!\n"); | ||
32 | fflush(stdout); | ||
33 | break; | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | int | ||
39 | main(void) | ||
40 | { | ||
41 | char sfn[24]; | ||
42 | char buf[sizeof(TEXT)]; | ||
43 | FILE *sfp; | ||
44 | int fd, i; | ||
45 | |||
46 | strlcpy(sfn, "/tmp/barnacles.XXXXXXXX", sizeof(sfn)); | ||
47 | if ((fd = mkstemp(sfn)) == -1 || | ||
48 | (sfp = fdopen(fd, "w+")) == NULL) { | ||
49 | if (fd != -1) { | ||
50 | unlink(sfn); | ||
51 | close(fd); | ||
52 | } | ||
53 | err(1, "could not open temporary file"); | ||
54 | } | ||
55 | |||
56 | run_threads(fwrite_thread, sfp); | ||
57 | |||
58 | while (fread(buf, sizeof(char), strlen(TEXT), sfp)) /* verify */ | ||
59 | if (strncmp(buf, TEXT, sizeof(TEXT))) | ||
60 | err(1, "Thread writes were not atomic!!!"); | ||
61 | |||
62 | unlink(sfn); | ||
63 | close(fd); | ||
64 | |||
65 | exit(0); | ||
66 | } | ||
diff --git a/src/regress/lib/libc/stdio_threading/include/local.h b/src/regress/lib/libc/stdio_threading/include/local.h new file mode 100644 index 0000000000..e2ad4e31e0 --- /dev/null +++ b/src/regress/lib/libc/stdio_threading/include/local.h | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2008 Bret S. Lambert <blambert@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include <stdio.h> | ||
18 | #include <stdlib.h> | ||
19 | #include <string.h> | ||
20 | #include <unistd.h> | ||
21 | #include <pthread.h> | ||
22 | |||
23 | #define THREAD_COUNT 64 | ||
24 | |||
25 | #define TEXT "barnacles" | ||
26 | #define TEXT_N "barnacles\n" | ||
27 | |||
28 | void run_threads(void (*)(void *), void *); | ||
29 | |||
30 | static pthread_rwlock_t start; | ||
31 | static void (*real_func)(void *); | ||
32 | |||
33 | static void * | ||
34 | thread(void *arg) | ||
35 | { | ||
36 | int r; | ||
37 | |||
38 | if ((r = pthread_rwlock_rdlock(&start))) | ||
39 | errx(1, "could not obtain lock in thread: %s", strerror(r)); | ||
40 | real_func(arg); | ||
41 | if ((r = pthread_rwlock_unlock(&start))) | ||
42 | errx(1, "could not release lock in thread: %s", strerror(r)); | ||
43 | return NULL; | ||
44 | } | ||
45 | |||
46 | void | ||
47 | run_threads(void (*func)(void *), void *arg) | ||
48 | { | ||
49 | pthread_t self, pthread[THREAD_COUNT]; | ||
50 | int i, r; | ||
51 | |||
52 | self = pthread_self(); | ||
53 | real_func = func; | ||
54 | if ((r = pthread_rwlock_init(&start, NULL))) | ||
55 | errx(1, "could not initialize lock: %s", strerror(r)); | ||
56 | |||
57 | if ((r = pthread_rwlock_wrlock(&start))) /* block */ | ||
58 | errx(1, "could not lock lock: %s", strerror(r)); | ||
59 | |||
60 | for (i = 0; i < THREAD_COUNT; i++) | ||
61 | if ((r = pthread_create(&pthread[i], NULL, thread, arg))) { | ||
62 | warnx("could not create thread: %s", strerror(r)); | ||
63 | pthread[i] = self; | ||
64 | } | ||
65 | |||
66 | |||
67 | if ((r = pthread_rwlock_unlock(&start))) /* unleash */ | ||
68 | errx(1, "could not release lock: %s", strerror(r)); | ||
69 | |||
70 | sleep(1); | ||
71 | |||
72 | if ((r = pthread_rwlock_wrlock(&start))) /* sync */ | ||
73 | errx(1, "parent could not sync with children: %s", | ||
74 | strerror(r)); | ||
75 | |||
76 | for (i = 0; i < THREAD_COUNT; i++) | ||
77 | if (! pthread_equal(pthread[i], self) && | ||
78 | (r = pthread_join(pthread[i], NULL))) | ||
79 | warnx("could not join thread: %s", strerror(r)); | ||
80 | } | ||
81 | |||
diff --git a/src/regress/lib/libc/strerror/Makefile b/src/regress/lib/libc/strerror/Makefile new file mode 100644 index 0000000000..448b6da903 --- /dev/null +++ b/src/regress/lib/libc/strerror/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/04/30 17:15:12 espie Exp $ | ||
2 | |||
3 | NOMAN= | ||
4 | PROG=strerror_test | ||
5 | CPPFLAGS+=-I${.CURDIR}/../../../../lib/libc | ||
6 | CLEANFILES+= invalid.out valid.out | ||
7 | |||
8 | run-regress-strerror_test: ${PROG} | ||
9 | ./${PROG} >${.OBJDIR}/valid.out | ||
10 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strerror/strerror_test.c b/src/regress/lib/libc/strerror/strerror_test.c new file mode 100644 index 0000000000..700080cd3e --- /dev/null +++ b/src/regress/lib/libc/strerror/strerror_test.c | |||
@@ -0,0 +1,71 @@ | |||
1 | /* $OpenBSD: strerror_test.c,v 1.4 2005/05/13 07:06:20 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <signal.h> | ||
18 | #include <string.h> | ||
19 | #include <stdio.h> | ||
20 | #include <limits.h> | ||
21 | #include <errno.h> | ||
22 | |||
23 | void | ||
24 | check_strerror_r(int val) | ||
25 | { | ||
26 | char buffer[NL_TEXTMAX + 1]; | ||
27 | int i, r; | ||
28 | |||
29 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
30 | buffer[sizeof(buffer) - 1] = '\0'; | ||
31 | (void)strerror_r(val, NULL, 0); /* XXX */ | ||
32 | for (i = 0; i < 25; i++) { | ||
33 | r = strerror_r(val, buffer, i); | ||
34 | printf("%d %d %zu: %s\n", i, r, strlen(buffer), buffer); | ||
35 | } | ||
36 | } | ||
37 | |||
38 | void | ||
39 | check_strsignal(int val) | ||
40 | { | ||
41 | char buffer[NL_TEXTMAX + 1]; | ||
42 | int i, r; | ||
43 | |||
44 | memset(buffer, 'X', sizeof(buffer) - 1); | ||
45 | buffer[sizeof(buffer) - 1] = '\0'; | ||
46 | (void)__strsignal(val, buffer); | ||
47 | printf("%s\n", buffer); | ||
48 | } | ||
49 | |||
50 | int | ||
51 | main() | ||
52 | { | ||
53 | printf("%s\n", strerror(21345)); | ||
54 | printf("%s\n", strerror(-21345)); | ||
55 | printf("%s\n", strerror(0)); | ||
56 | printf("%s\n", strerror(INT_MAX)); | ||
57 | printf("%s\n", strerror(INT_MIN)); | ||
58 | printf("%s\n", strerror(EPERM)); | ||
59 | check_strerror_r(EPERM); | ||
60 | check_strerror_r(21345); | ||
61 | check_strsignal(-1); | ||
62 | check_strsignal(0); | ||
63 | check_strsignal(10); | ||
64 | check_strsignal(NSIG-1); | ||
65 | check_strsignal(NSIG); | ||
66 | check_strsignal(100); | ||
67 | check_strsignal(INT_MAX); | ||
68 | check_strsignal(INT_MIN); | ||
69 | check_strsignal(UINT_MAX); | ||
70 | return 0; | ||
71 | } | ||
diff --git a/src/regress/lib/libc/strerror/valid.ok b/src/regress/lib/libc/strerror/valid.ok new file mode 100644 index 0000000000..cbc365c598 --- /dev/null +++ b/src/regress/lib/libc/strerror/valid.ok | |||
@@ -0,0 +1,65 @@ | |||
1 | Unknown error: 21345 | ||
2 | Unknown error: -21345 | ||
3 | Undefined error: 0 | ||
4 | Unknown error: 2147483647 | ||
5 | Unknown error: -2147483648 | ||
6 | Operation not permitted | ||
7 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
8 | 1 34 0: | ||
9 | 2 34 1: O | ||
10 | 3 34 2: Op | ||
11 | 4 34 3: Ope | ||
12 | 5 34 4: Oper | ||
13 | 6 34 5: Opera | ||
14 | 7 34 6: Operat | ||
15 | 8 34 7: Operati | ||
16 | 9 34 8: Operatio | ||
17 | 10 34 9: Operation | ||
18 | 11 34 10: Operation | ||
19 | 12 34 11: Operation n | ||
20 | 13 34 12: Operation no | ||
21 | 14 34 13: Operation not | ||
22 | 15 34 14: Operation not | ||
23 | 16 34 15: Operation not p | ||
24 | 17 34 16: Operation not pe | ||
25 | 18 34 17: Operation not per | ||
26 | 19 34 18: Operation not perm | ||
27 | 20 34 19: Operation not permi | ||
28 | 21 34 20: Operation not permit | ||
29 | 22 34 21: Operation not permitt | ||
30 | 23 34 22: Operation not permitte | ||
31 | 24 0 23: Operation not permitted | ||
32 | 0 34 255: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
33 | 1 34 0: | ||
34 | 2 34 1: U | ||
35 | 3 34 2: Un | ||
36 | 4 34 3: Unk | ||
37 | 5 34 4: Unkn | ||
38 | 6 34 5: Unkno | ||
39 | 7 34 6: Unknow | ||
40 | 8 34 7: Unknown | ||
41 | 9 34 8: Unknown | ||
42 | 10 34 9: Unknown e | ||
43 | 11 34 10: Unknown er | ||
44 | 12 34 11: Unknown err | ||
45 | 13 34 12: Unknown erro | ||
46 | 14 34 13: Unknown error | ||
47 | 15 34 14: Unknown error: | ||
48 | 16 34 15: Unknown error: | ||
49 | 17 34 15: Unknown error: | ||
50 | 18 34 15: Unknown error: | ||
51 | 19 34 15: Unknown error: | ||
52 | 20 34 15: Unknown error: | ||
53 | 21 22 20: Unknown error: 21345 | ||
54 | 22 22 20: Unknown error: 21345 | ||
55 | 23 22 20: Unknown error: 21345 | ||
56 | 24 22 20: Unknown error: 21345 | ||
57 | Unknown signal: 4294967295 | ||
58 | Signal 0 | ||
59 | Bus error | ||
60 | Thread AST | ||
61 | Unknown signal: 33 | ||
62 | Unknown signal: 100 | ||
63 | Unknown signal: 2147483647 | ||
64 | Unknown signal: 2147483648 | ||
65 | Unknown signal: 4294967295 | ||
diff --git a/src/regress/lib/libc/strnlen/Makefile b/src/regress/lib/libc/strnlen/Makefile new file mode 100644 index 0000000000..e7c74972e1 --- /dev/null +++ b/src/regress/lib/libc/strnlen/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2010/06/02 12:20:47 millert Exp $ | ||
2 | |||
3 | PROG= strnlentest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strnlen/strnlentest.c b/src/regress/lib/libc/strnlen/strnlentest.c new file mode 100644 index 0000000000..e67e6adfb8 --- /dev/null +++ b/src/regress/lib/libc/strnlen/strnlentest.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* $OpenBSD: strnlentest.c,v 1.1 2010/06/02 12:20:47 millert Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include <sys/types.h> | ||
20 | |||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | #include <unistd.h> | ||
25 | |||
26 | int main(int argc, char *argv[]) | ||
27 | { | ||
28 | char *buf; | ||
29 | int failures = 0; | ||
30 | size_t len, bufsize; | ||
31 | |||
32 | /* Enable malloc security options. */ | ||
33 | setenv("MALLOC_OPTIONS", "S", 0); | ||
34 | |||
35 | bufsize = getpagesize(); /* trigger guard pages easily */ | ||
36 | buf = malloc(bufsize); | ||
37 | if (buf == NULL) { | ||
38 | fprintf(stderr, "unable to allocate memory\n"); | ||
39 | return 1; | ||
40 | } | ||
41 | memset(buf, 'a', bufsize); | ||
42 | |||
43 | len = strnlen(buf, bufsize); | ||
44 | if (len != bufsize) { | ||
45 | fprintf(stderr, "strnlen: failed unterminated buffer test (1)"); | ||
46 | failures++; | ||
47 | } | ||
48 | |||
49 | len = strnlen(buf, bufsize / 2); | ||
50 | if (len != bufsize / 2) { | ||
51 | fprintf(stderr, "strnlen: failed unterminated buffer test (2)"); | ||
52 | failures++; | ||
53 | } | ||
54 | |||
55 | buf[bufsize - 1] = '\0'; | ||
56 | len = strnlen(buf, bufsize); | ||
57 | if (len != bufsize - 1) { | ||
58 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (1)"); | ||
59 | failures++; | ||
60 | } | ||
61 | |||
62 | len = strnlen(buf, (size_t)-1); | ||
63 | if (len != bufsize - 1) { | ||
64 | fprintf(stderr, "strnlen: failed NUL-terminated buffer test (2)"); | ||
65 | failures++; | ||
66 | } | ||
67 | |||
68 | return failures; | ||
69 | } | ||
diff --git a/src/regress/lib/libc/strtod/Makefile b/src/regress/lib/libc/strtod/Makefile new file mode 100644 index 0000000000..030c0e7f56 --- /dev/null +++ b/src/regress/lib/libc/strtod/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/09/29 11:00:24 otto Exp $ | ||
2 | |||
3 | PROG= strtodtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtod/strtodtest.c b/src/regress/lib/libc/strtod/strtodtest.c new file mode 100644 index 0000000000..0291365a75 --- /dev/null +++ b/src/regress/lib/libc/strtod/strtodtest.c | |||
@@ -0,0 +1,22 @@ | |||
1 | /* $OpenBSD: strtodtest.c,v 1.1 2006/09/29 11:00:24 otto Exp $ */ | ||
2 | /* Public domain, Otto Moerbeek <otto@drijf.net>, 2006. */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <errno.h> | ||
7 | |||
8 | /* | ||
9 | * Checks if strtod() reports underflow. | ||
10 | */ | ||
11 | |||
12 | int | ||
13 | main() | ||
14 | { | ||
15 | char *tmp="0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"; | ||
16 | double d; | ||
17 | |||
18 | d = strtod(tmp, NULL); | ||
19 | if (errno != ERANGE) | ||
20 | errx(1, "errno = %d", errno); | ||
21 | return (0); | ||
22 | } | ||
diff --git a/src/regress/lib/libc/strtonum/Makefile b/src/regress/lib/libc/strtonum/Makefile new file mode 100644 index 0000000000..e0e8ecd139 --- /dev/null +++ b/src/regress/lib/libc/strtonum/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/08/03 20:38:36 otto Exp $ | ||
2 | |||
3 | PROG= strtonumtest | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/strtonum/strtonumtest.c b/src/regress/lib/libc/strtonum/strtonumtest.c new file mode 100644 index 0000000000..7e82a007fe --- /dev/null +++ b/src/regress/lib/libc/strtonum/strtonumtest.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | |||
18 | #include <limits.h> | ||
19 | #include <stdio.h> | ||
20 | #include <stdlib.h> | ||
21 | |||
22 | int fail; | ||
23 | |||
24 | void | ||
25 | test(const char *p, long long lb, long long ub, int ok) | ||
26 | { | ||
27 | long long val; | ||
28 | const char *q; | ||
29 | |||
30 | val = strtonum(p, lb, ub, &q); | ||
31 | if (ok && q != NULL) { | ||
32 | fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub); | ||
33 | fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q); | ||
34 | fail = 1; | ||
35 | } else if (!ok && q == NULL) { | ||
36 | fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val); | ||
37 | fprintf(stderr, "NUMBER ACCEPTED\n"); | ||
38 | fail = 1; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | int main(int argc, char *argv[]) | ||
43 | { | ||
44 | test("1", 0, 10, 1); | ||
45 | test("0", -2, 5, 1); | ||
46 | test("0", 2, 5, 0); | ||
47 | test("0", 2, LLONG_MAX, 0); | ||
48 | test("-2", 0, LLONG_MAX, 0); | ||
49 | test("0", -5, LLONG_MAX, 1); | ||
50 | test("-3", -3, LLONG_MAX, 1); | ||
51 | test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1); | ||
52 | test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1); | ||
53 | test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0); | ||
54 | test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0); | ||
55 | test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
56 | test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0); | ||
57 | test("-2", 10, -1, 0); | ||
58 | test("-2", -10, -1, 1); | ||
59 | test("-20", -10, -1, 0); | ||
60 | test("20", -10, -1, 0); | ||
61 | |||
62 | return (fail); | ||
63 | } | ||
64 | |||
diff --git a/src/regress/lib/libc/telldir/Makefile b/src/regress/lib/libc/telldir/Makefile new file mode 100644 index 0000000000..0927779663 --- /dev/null +++ b/src/regress/lib/libc/telldir/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/03/25 20:27:11 otto Exp $ | ||
2 | |||
3 | PROG= telldir | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/telldir/telldir.c b/src/regress/lib/libc/telldir/telldir.c new file mode 100644 index 0000000000..fc1ca3e891 --- /dev/null +++ b/src/regress/lib/libc/telldir/telldir.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* $OpenBSD: telldir.c,v 1.2 2006/04/01 18:24:53 otto Exp $ */ | ||
2 | |||
3 | /* Written by Otto Moerbeek, 2006, Public domain. */ | ||
4 | |||
5 | #include <sys/types.h> | ||
6 | #include <sys/stat.h> | ||
7 | #include <dirent.h> | ||
8 | #include <err.h> | ||
9 | #include <limits.h> | ||
10 | #include <fcntl.h> | ||
11 | #include <stdio.h> | ||
12 | #include <string.h> | ||
13 | #include <unistd.h> | ||
14 | |||
15 | |||
16 | #define NFILES 1000 | ||
17 | |||
18 | void | ||
19 | createfiles(void) | ||
20 | { | ||
21 | int i, fd; | ||
22 | char file[PATH_MAX]; | ||
23 | |||
24 | mkdir("d", 0755); | ||
25 | for (i = 0; i < NFILES; i++) { | ||
26 | snprintf(file, sizeof file, "d/%d", i); | ||
27 | if ((fd = open(file, O_CREAT | O_WRONLY, 0600)) == -1) | ||
28 | err(1, "open %s", file); | ||
29 | close(fd); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | void | ||
34 | delfiles(void) | ||
35 | { | ||
36 | DIR *dp; | ||
37 | struct dirent *f; | ||
38 | char file[PATH_MAX]; | ||
39 | |||
40 | dp = opendir("d"); | ||
41 | if (dp == NULL) | ||
42 | err(1, "opendir"); | ||
43 | while (f = readdir(dp)) { | ||
44 | if (strcmp(f->d_name, ".") == 0 || | ||
45 | strcmp(f->d_name, "..") == 0) | ||
46 | continue; | ||
47 | snprintf(file, sizeof file, "d/%s", f->d_name); | ||
48 | if (unlink(file) == -1) | ||
49 | err(1, "unlink %s", f->d_name); | ||
50 | } | ||
51 | closedir(dp); | ||
52 | if (rmdir("d") == -1) | ||
53 | err(1, "rmdir"); | ||
54 | } | ||
55 | |||
56 | void | ||
57 | loop(DIR *dp, int i) | ||
58 | { | ||
59 | struct dirent *f; | ||
60 | char file[PATH_MAX]; | ||
61 | long pos, remember = -1; | ||
62 | |||
63 | rewinddir(dp); | ||
64 | snprintf(file, sizeof file, "%d", i); | ||
65 | for (;;) { | ||
66 | pos = telldir(dp); | ||
67 | f = readdir(dp); | ||
68 | if (f == NULL) | ||
69 | break; | ||
70 | if (strcmp(file, f->d_name) == 0) | ||
71 | remember = pos; | ||
72 | } | ||
73 | if (remember == -1) | ||
74 | errx(1, "remember"); | ||
75 | seekdir(dp, remember); | ||
76 | if (telldir(dp) != remember) | ||
77 | errx(1, "tell after seek"); | ||
78 | if (telldir(dp) != remember) | ||
79 | errx(1, "tell after tell"); | ||
80 | f = readdir(dp); | ||
81 | if (f == NULL) | ||
82 | err(1, "seek to %s %ld", file, remember); | ||
83 | |||
84 | if (strcmp(f->d_name, file) != 0) | ||
85 | err(1, "name mismatch: %s != %s\n", f->d_name, file); | ||
86 | } | ||
87 | |||
88 | int | ||
89 | main(void) | ||
90 | { | ||
91 | DIR *dp; | ||
92 | int i; | ||
93 | |||
94 | createfiles(); | ||
95 | |||
96 | dp = opendir("d"); | ||
97 | if (dp == NULL) | ||
98 | err(1, "opendir"); | ||
99 | |||
100 | for (i = 0; i < NFILES; i++) | ||
101 | loop(dp, (i + NFILES/2) % NFILES); | ||
102 | |||
103 | closedir(dp); | ||
104 | delfiles(); | ||
105 | return 0; | ||
106 | } | ||
diff --git a/src/regress/lib/libc/time/Makefile b/src/regress/lib/libc/time/Makefile new file mode 100644 index 0000000000..28b5556027 --- /dev/null +++ b/src/regress/lib/libc/time/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2004/01/20 16:47:55 millert Exp $ | ||
2 | |||
3 | SUBDIR+=strptime | ||
4 | |||
5 | .include <bsd.subdir.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/Makefile b/src/regress/lib/libc/time/strptime/Makefile new file mode 100644 index 0000000000..f2c9ebaf2c --- /dev/null +++ b/src/regress/lib/libc/time/strptime/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2004/01/21 18:13:48 david Exp $ | ||
2 | |||
3 | PROG= strptime_test | ||
4 | SRCS= main.c | ||
5 | CLEANFILES+= got | ||
6 | |||
7 | REGRESS_TARGETS=do-reg | ||
8 | do-reg: ${PROG} | ||
9 | ./${PROG} < ${.CURDIR}/tests > got | ||
10 | diff ${.CURDIR}/expected got | ||
11 | |||
12 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/time/strptime/expected b/src/regress/lib/libc/time/strptime/expected new file mode 100644 index 0000000000..d038d319af --- /dev/null +++ b/src/regress/lib/libc/time/strptime/expected | |||
@@ -0,0 +1,346 @@ | |||
1 | --- ctime --- 1 | ||
2 | succeeded | ||
3 | 46 27 23 20 0 98 2 -1 | ||
4 | |||
5 | --- ctime --- 2 | ||
6 | succeeded | ||
7 | 46 27 23 20 0 98 2 -1 | ||
8 | |||
9 | --- ctime --- 3 | ||
10 | succeeded | ||
11 | 46 27 23 20 0 98 2 -1 | ||
12 | |||
13 | --- %a --- 1 | ||
14 | succeeded | ||
15 | -1 -1 -1 -1 -1 -1 0 -1 | ||
16 | |||
17 | --- %a --- 2 | ||
18 | succeeded | ||
19 | -1 -1 -1 -1 -1 -1 0 -1 | ||
20 | |||
21 | --- %a --- 3 | ||
22 | succeeded | ||
23 | -1 -1 -1 -1 -1 -1 1 -1 | ||
24 | |||
25 | --- %a --- 4 | ||
26 | succeeded | ||
27 | -1 -1 -1 -1 -1 -1 1 -1 | ||
28 | |||
29 | --- %a --- 5 | ||
30 | succeeded | ||
31 | -1 -1 -1 -1 -1 -1 2 -1 | ||
32 | |||
33 | --- %a --- 6 | ||
34 | succeeded | ||
35 | -1 -1 -1 -1 -1 -1 2 -1 | ||
36 | |||
37 | --- %a --- 7 | ||
38 | succeeded | ||
39 | -1 -1 -1 -1 -1 -1 3 -1 | ||
40 | |||
41 | --- %a --- 8 | ||
42 | succeeded | ||
43 | -1 -1 -1 -1 -1 -1 3 -1 | ||
44 | |||
45 | --- %a --- 9 | ||
46 | succeeded | ||
47 | -1 -1 -1 -1 -1 -1 4 -1 | ||
48 | |||
49 | --- %a --- 10 | ||
50 | succeeded | ||
51 | -1 -1 -1 -1 -1 -1 4 -1 | ||
52 | |||
53 | --- %a --- 11 | ||
54 | succeeded | ||
55 | -1 -1 -1 -1 -1 -1 5 -1 | ||
56 | |||
57 | --- %a --- 12 | ||
58 | succeeded | ||
59 | -1 -1 -1 -1 -1 -1 5 -1 | ||
60 | |||
61 | --- %a --- 13 | ||
62 | succeeded | ||
63 | -1 -1 -1 -1 -1 -1 6 -1 | ||
64 | |||
65 | --- %a --- 14 | ||
66 | succeeded | ||
67 | -1 -1 -1 -1 -1 -1 6 -1 | ||
68 | |||
69 | --- %a --- 15 | ||
70 | succeeded | ||
71 | -1 -1 -1 -1 -1 -1 6 -1 | ||
72 | urn | ||
73 | |||
74 | --- %a --- 16 | ||
75 | failed | ||
76 | --- %A --- 1 | ||
77 | succeeded | ||
78 | -1 -1 -1 -1 -1 -1 0 -1 | ||
79 | |||
80 | --- %A --- 2 | ||
81 | succeeded | ||
82 | -1 -1 -1 -1 -1 -1 0 -1 | ||
83 | |||
84 | --- %A --- 3 | ||
85 | succeeded | ||
86 | -1 -1 -1 -1 -1 -1 1 -1 | ||
87 | |||
88 | --- %A --- 4 | ||
89 | succeeded | ||
90 | -1 -1 -1 -1 -1 -1 1 -1 | ||
91 | |||
92 | --- %A --- 5 | ||
93 | succeeded | ||
94 | -1 -1 -1 -1 -1 -1 2 -1 | ||
95 | |||
96 | --- %A --- 6 | ||
97 | succeeded | ||
98 | -1 -1 -1 -1 -1 -1 2 -1 | ||
99 | |||
100 | --- %A --- 7 | ||
101 | succeeded | ||
102 | -1 -1 -1 -1 -1 -1 3 -1 | ||
103 | |||
104 | --- %A --- 8 | ||
105 | succeeded | ||
106 | -1 -1 -1 -1 -1 -1 3 -1 | ||
107 | |||
108 | --- %A --- 9 | ||
109 | succeeded | ||
110 | -1 -1 -1 -1 -1 -1 4 -1 | ||
111 | |||
112 | --- %A --- 10 | ||
113 | succeeded | ||
114 | -1 -1 -1 -1 -1 -1 4 -1 | ||
115 | |||
116 | --- %A --- 11 | ||
117 | succeeded | ||
118 | -1 -1 -1 -1 -1 -1 5 -1 | ||
119 | |||
120 | --- %A --- 12 | ||
121 | succeeded | ||
122 | -1 -1 -1 -1 -1 -1 5 -1 | ||
123 | |||
124 | --- %A --- 13 | ||
125 | succeeded | ||
126 | -1 -1 -1 -1 -1 -1 6 -1 | ||
127 | |||
128 | --- %A --- 14 | ||
129 | succeeded | ||
130 | -1 -1 -1 -1 -1 -1 6 -1 | ||
131 | |||
132 | --- %A --- 15 | ||
133 | succeeded | ||
134 | -1 -1 -1 -1 -1 -1 6 -1 | ||
135 | urn | ||
136 | |||
137 | --- %A --- 16 | ||
138 | failed | ||
139 | --- %b --- 1 | ||
140 | succeeded | ||
141 | -1 -1 -1 -1 0 -1 -1 -1 | ||
142 | |||
143 | --- %b --- 2 | ||
144 | succeeded | ||
145 | -1 -1 -1 -1 0 -1 -1 -1 | ||
146 | |||
147 | --- %b --- 3 | ||
148 | succeeded | ||
149 | -1 -1 -1 -1 1 -1 -1 -1 | ||
150 | |||
151 | --- %b --- 4 | ||
152 | succeeded | ||
153 | -1 -1 -1 -1 1 -1 -1 -1 | ||
154 | |||
155 | --- %b --- 5 | ||
156 | succeeded | ||
157 | -1 -1 -1 -1 2 -1 -1 -1 | ||
158 | |||
159 | --- %b --- 6 | ||
160 | succeeded | ||
161 | -1 -1 -1 -1 2 -1 -1 -1 | ||
162 | |||
163 | --- %b --- 7 | ||
164 | succeeded | ||
165 | -1 -1 -1 -1 3 -1 -1 -1 | ||
166 | |||
167 | --- %b --- 8 | ||
168 | succeeded | ||
169 | -1 -1 -1 -1 3 -1 -1 -1 | ||
170 | |||
171 | --- %b --- 9 | ||
172 | succeeded | ||
173 | -1 -1 -1 -1 4 -1 -1 -1 | ||
174 | |||
175 | --- %b --- 10 | ||
176 | succeeded | ||
177 | -1 -1 -1 -1 5 -1 -1 -1 | ||
178 | |||
179 | --- %b --- 11 | ||
180 | succeeded | ||
181 | -1 -1 -1 -1 5 -1 -1 -1 | ||
182 | |||
183 | --- %b --- 12 | ||
184 | succeeded | ||
185 | -1 -1 -1 -1 6 -1 -1 -1 | ||
186 | |||
187 | --- %b --- 13 | ||
188 | succeeded | ||
189 | -1 -1 -1 -1 6 -1 -1 -1 | ||
190 | |||
191 | --- %b --- 14 | ||
192 | succeeded | ||
193 | -1 -1 -1 -1 7 -1 -1 -1 | ||
194 | |||
195 | --- %b --- 15 | ||
196 | succeeded | ||
197 | -1 -1 -1 -1 7 -1 -1 -1 | ||
198 | |||
199 | --- %b --- 16 | ||
200 | succeeded | ||
201 | -1 -1 -1 -1 8 -1 -1 -1 | ||
202 | |||
203 | --- %b --- 17 | ||
204 | succeeded | ||
205 | -1 -1 -1 -1 8 -1 -1 -1 | ||
206 | |||
207 | --- %b --- 18 | ||
208 | succeeded | ||
209 | -1 -1 -1 -1 9 -1 -1 -1 | ||
210 | |||
211 | --- %b --- 19 | ||
212 | succeeded | ||
213 | -1 -1 -1 -1 9 -1 -1 -1 | ||
214 | |||
215 | --- %b --- 20 | ||
216 | succeeded | ||
217 | -1 -1 -1 -1 10 -1 -1 -1 | ||
218 | |||
219 | --- %b --- 21 | ||
220 | succeeded | ||
221 | -1 -1 -1 -1 10 -1 -1 -1 | ||
222 | |||
223 | --- %b --- 22 | ||
224 | succeeded | ||
225 | -1 -1 -1 -1 11 -1 -1 -1 | ||
226 | |||
227 | --- %b --- 23 | ||
228 | succeeded | ||
229 | -1 -1 -1 -1 11 -1 -1 -1 | ||
230 | |||
231 | --- %b --- 25 | ||
232 | succeeded | ||
233 | -1 -1 -1 -1 4 -1 -1 -1 | ||
234 | or | ||
235 | |||
236 | --- %b --- 24 | ||
237 | succeeded | ||
238 | -1 -1 -1 -1 2 -1 -1 -1 | ||
239 | s | ||
240 | |||
241 | --- %b --- 26 | ||
242 | failed | ||
243 | --- %B --- 1 | ||
244 | succeeded | ||
245 | -1 -1 -1 -1 0 -1 -1 -1 | ||
246 | |||
247 | --- %B --- 2 | ||
248 | succeeded | ||
249 | -1 -1 -1 -1 0 -1 -1 -1 | ||
250 | |||
251 | --- %B --- 3 | ||
252 | succeeded | ||
253 | -1 -1 -1 -1 1 -1 -1 -1 | ||
254 | |||
255 | --- %B --- 4 | ||
256 | succeeded | ||
257 | -1 -1 -1 -1 1 -1 -1 -1 | ||
258 | |||
259 | --- %B --- 5 | ||
260 | succeeded | ||
261 | -1 -1 -1 -1 2 -1 -1 -1 | ||
262 | |||
263 | --- %B --- 6 | ||
264 | succeeded | ||
265 | -1 -1 -1 -1 2 -1 -1 -1 | ||
266 | |||
267 | --- %B --- 7 | ||
268 | succeeded | ||
269 | -1 -1 -1 -1 3 -1 -1 -1 | ||
270 | |||
271 | --- %B --- 8 | ||
272 | succeeded | ||
273 | -1 -1 -1 -1 3 -1 -1 -1 | ||
274 | |||
275 | --- %B --- 9 | ||
276 | succeeded | ||
277 | -1 -1 -1 -1 4 -1 -1 -1 | ||
278 | |||
279 | --- %B --- 10 | ||
280 | succeeded | ||
281 | -1 -1 -1 -1 5 -1 -1 -1 | ||
282 | |||
283 | --- %B --- 11 | ||
284 | succeeded | ||
285 | -1 -1 -1 -1 5 -1 -1 -1 | ||
286 | |||
287 | --- %B --- 12 | ||
288 | succeeded | ||
289 | -1 -1 -1 -1 6 -1 -1 -1 | ||
290 | |||
291 | --- %B --- 13 | ||
292 | succeeded | ||
293 | -1 -1 -1 -1 6 -1 -1 -1 | ||
294 | |||
295 | --- %B --- 14 | ||
296 | succeeded | ||
297 | -1 -1 -1 -1 7 -1 -1 -1 | ||
298 | |||
299 | --- %B --- 15 | ||
300 | succeeded | ||
301 | -1 -1 -1 -1 7 -1 -1 -1 | ||
302 | |||
303 | --- %B --- 16 | ||
304 | succeeded | ||
305 | -1 -1 -1 -1 8 -1 -1 -1 | ||
306 | |||
307 | --- %B --- 17 | ||
308 | succeeded | ||
309 | -1 -1 -1 -1 8 -1 -1 -1 | ||
310 | |||
311 | --- %B --- 18 | ||
312 | succeeded | ||
313 | -1 -1 -1 -1 9 -1 -1 -1 | ||
314 | |||
315 | --- %B --- 19 | ||
316 | succeeded | ||
317 | -1 -1 -1 -1 9 -1 -1 -1 | ||
318 | |||
319 | --- %B --- 20 | ||
320 | succeeded | ||
321 | -1 -1 -1 -1 10 -1 -1 -1 | ||
322 | |||
323 | --- %B --- 21 | ||
324 | succeeded | ||
325 | -1 -1 -1 -1 10 -1 -1 -1 | ||
326 | |||
327 | --- %B --- 22 | ||
328 | succeeded | ||
329 | -1 -1 -1 -1 11 -1 -1 -1 | ||
330 | |||
331 | --- %B --- 23 | ||
332 | succeeded | ||
333 | -1 -1 -1 -1 11 -1 -1 -1 | ||
334 | |||
335 | --- %B --- 25 | ||
336 | succeeded | ||
337 | -1 -1 -1 -1 4 -1 -1 -1 | ||
338 | or | ||
339 | |||
340 | --- %B --- 24 | ||
341 | succeeded | ||
342 | -1 -1 -1 -1 2 -1 -1 -1 | ||
343 | s | ||
344 | |||
345 | --- %B --- 26 | ||
346 | failed | ||
diff --git a/src/regress/lib/libc/time/strptime/main.c b/src/regress/lib/libc/time/strptime/main.c new file mode 100644 index 0000000000..c4e06a9b59 --- /dev/null +++ b/src/regress/lib/libc/time/strptime/main.c | |||
@@ -0,0 +1,110 @@ | |||
1 | /* $OpenBSD: main.c,v 1.2 2008/06/26 05:42:05 ray Exp $ */ | ||
2 | /* $NetBSD: main.c,v 1.4 2002/02/21 07:38:18 itojun Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 1998 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * 2. Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
18 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
19 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
20 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
27 | * POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | #include <err.h> | ||
30 | #include <stdio.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | #include <time.h> | ||
34 | |||
35 | int main(int, char *[]); | ||
36 | void die(void); | ||
37 | |||
38 | void | ||
39 | die(void) | ||
40 | { | ||
41 | |||
42 | if (ferror(stdin)) | ||
43 | err(1, "fgetln"); | ||
44 | else | ||
45 | errx(1, "input is truncated"); | ||
46 | } | ||
47 | |||
48 | int | ||
49 | main(int argc, char *argv[]) | ||
50 | { | ||
51 | char *p, *title, *buf, *format; | ||
52 | size_t len; | ||
53 | struct tm tm; | ||
54 | |||
55 | for (;;) { | ||
56 | p = fgetln(stdin, &len); | ||
57 | if (p == 0) | ||
58 | die(); | ||
59 | title = malloc(len + 1); | ||
60 | memcpy(title, p, len); | ||
61 | title[len] = '\0'; | ||
62 | |||
63 | if (!strcmp(title, "EOF\n")) | ||
64 | return(0); | ||
65 | if (title[0] == '#' || title[0] == '\n') { | ||
66 | free(title); | ||
67 | continue; | ||
68 | } | ||
69 | |||
70 | p = fgetln(stdin, &len); | ||
71 | if (p == 0) | ||
72 | die(); | ||
73 | buf = malloc(len + 1); | ||
74 | memcpy(buf, p, len); | ||
75 | buf[len] = '\0'; | ||
76 | |||
77 | p = fgetln(stdin, &len); | ||
78 | if (p == 0) | ||
79 | die(); | ||
80 | format = malloc(len + 1); | ||
81 | memcpy(format, p, len); | ||
82 | format[len] = '\0'; | ||
83 | |||
84 | tm.tm_sec = -1; | ||
85 | tm.tm_min = -1; | ||
86 | tm.tm_hour = -1; | ||
87 | tm.tm_mday = -1; | ||
88 | tm.tm_mon = -1; | ||
89 | tm.tm_year = -1; | ||
90 | tm.tm_wday = -1; | ||
91 | tm.tm_yday = -1; | ||
92 | |||
93 | p = strptime(buf, format, &tm); | ||
94 | |||
95 | printf("%s", title); | ||
96 | if (p) { | ||
97 | printf("succeeded\n"); | ||
98 | printf("%d %d %d %d %d %d %d %d\n", | ||
99 | tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, | ||
100 | tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday); | ||
101 | printf("%s\n", p); | ||
102 | } else { | ||
103 | printf("failed\n"); | ||
104 | } | ||
105 | |||
106 | free(title); | ||
107 | free(buf); | ||
108 | free(format); | ||
109 | } | ||
110 | } | ||
diff --git a/src/regress/lib/libc/time/strptime/tests b/src/regress/lib/libc/time/strptime/tests new file mode 100644 index 0000000000..d96393b2b7 --- /dev/null +++ b/src/regress/lib/libc/time/strptime/tests | |||
@@ -0,0 +1,267 @@ | |||
1 | # some intial checks to make sure common things work | ||
2 | --- ctime --- 1 | ||
3 | Tue Jan 20 23:27:46 1998 | ||
4 | %a %b %d %T %Y | ||
5 | --- ctime --- 2 | ||
6 | Tue Jan 20 23:27:46 1998 | ||
7 | %a %b %d %H:%M:%S %Y | ||
8 | --- ctime --- 3 | ||
9 | Tue Jan 20 23:27:46 1998 | ||
10 | %c | ||
11 | |||
12 | # test some valid and invalid day names | ||
13 | --- %a --- 1 | ||
14 | Sun | ||
15 | %a | ||
16 | --- %a --- 2 | ||
17 | Sunday | ||
18 | %a | ||
19 | --- %a --- 3 | ||
20 | Mon | ||
21 | %a | ||
22 | --- %a --- 4 | ||
23 | Monday | ||
24 | %a | ||
25 | --- %a --- 5 | ||
26 | Tue | ||
27 | %a | ||
28 | --- %a --- 6 | ||
29 | Tuesday | ||
30 | %a | ||
31 | --- %a --- 7 | ||
32 | Wed | ||
33 | %a | ||
34 | --- %a --- 8 | ||
35 | Wednesday | ||
36 | %a | ||
37 | --- %a --- 9 | ||
38 | Thu | ||
39 | %a | ||
40 | --- %a --- 10 | ||
41 | Thursday | ||
42 | %a | ||
43 | --- %a --- 11 | ||
44 | Fri | ||
45 | %a | ||
46 | --- %a --- 12 | ||
47 | Friday | ||
48 | %a | ||
49 | --- %a --- 13 | ||
50 | Sat | ||
51 | %a | ||
52 | --- %a --- 14 | ||
53 | Saturday | ||
54 | %a | ||
55 | --- %a --- 15 | ||
56 | Saturn | ||
57 | %a | ||
58 | --- %a --- 16 | ||
59 | Moon | ||
60 | %a | ||
61 | --- %A --- 1 | ||
62 | Sun | ||
63 | %A | ||
64 | --- %A --- 2 | ||
65 | Sunday | ||
66 | %A | ||
67 | --- %A --- 3 | ||
68 | Mon | ||
69 | %A | ||
70 | --- %A --- 4 | ||
71 | Monday | ||
72 | %A | ||
73 | --- %A --- 5 | ||
74 | Tue | ||
75 | %A | ||
76 | --- %A --- 6 | ||
77 | Tuesday | ||
78 | %A | ||
79 | --- %A --- 7 | ||
80 | Wed | ||
81 | %A | ||
82 | --- %A --- 8 | ||
83 | Wednesday | ||
84 | %A | ||
85 | --- %A --- 9 | ||
86 | Thu | ||
87 | %A | ||
88 | --- %A --- 10 | ||
89 | Thursday | ||
90 | %A | ||
91 | --- %A --- 11 | ||
92 | Fri | ||
93 | %A | ||
94 | --- %A --- 12 | ||
95 | Friday | ||
96 | %A | ||
97 | --- %A --- 13 | ||
98 | Sat | ||
99 | %A | ||
100 | --- %A --- 14 | ||
101 | Saturday | ||
102 | %A | ||
103 | --- %A --- 15 | ||
104 | Saturn | ||
105 | %A | ||
106 | --- %A --- 16 | ||
107 | Moon | ||
108 | %A | ||
109 | |||
110 | # test some valid and invalid month names | ||
111 | --- %b --- 1 | ||
112 | Jan | ||
113 | %b | ||
114 | --- %b --- 2 | ||
115 | January | ||
116 | %b | ||
117 | --- %b --- 3 | ||
118 | Feb | ||
119 | %b | ||
120 | --- %b --- 4 | ||
121 | February | ||
122 | %b | ||
123 | --- %b --- 5 | ||
124 | Mar | ||
125 | %b | ||
126 | --- %b --- 6 | ||
127 | March | ||
128 | %b | ||
129 | --- %b --- 7 | ||
130 | Apr | ||
131 | %b | ||
132 | --- %b --- 8 | ||
133 | April | ||
134 | %b | ||
135 | --- %b --- 9 | ||
136 | May | ||
137 | %b | ||
138 | --- %b --- 10 | ||
139 | Jun | ||
140 | %b | ||
141 | --- %b --- 11 | ||
142 | June | ||
143 | %b | ||
144 | --- %b --- 12 | ||
145 | Jul | ||
146 | %b | ||
147 | --- %b --- 13 | ||
148 | July | ||
149 | %b | ||
150 | --- %b --- 14 | ||
151 | Aug | ||
152 | %b | ||
153 | --- %b --- 15 | ||
154 | August | ||
155 | %b | ||
156 | --- %b --- 16 | ||
157 | Sep | ||
158 | %b | ||
159 | --- %b --- 17 | ||
160 | September | ||
161 | %b | ||
162 | --- %b --- 18 | ||
163 | Oct | ||
164 | %b | ||
165 | --- %b --- 19 | ||
166 | October | ||
167 | %b | ||
168 | --- %b --- 20 | ||
169 | Nov | ||
170 | %b | ||
171 | --- %b --- 21 | ||
172 | November | ||
173 | %b | ||
174 | --- %b --- 22 | ||
175 | Dec | ||
176 | %b | ||
177 | --- %b --- 23 | ||
178 | December | ||
179 | %b | ||
180 | --- %b --- 25 | ||
181 | Mayor | ||
182 | %b | ||
183 | --- %b --- 24 | ||
184 | Mars | ||
185 | %b | ||
186 | --- %b --- 26 | ||
187 | Rover | ||
188 | %b | ||
189 | --- %B --- 1 | ||
190 | Jan | ||
191 | %B | ||
192 | --- %B --- 2 | ||
193 | January | ||
194 | %B | ||
195 | --- %B --- 3 | ||
196 | Feb | ||
197 | %B | ||
198 | --- %B --- 4 | ||
199 | February | ||
200 | %B | ||
201 | --- %B --- 5 | ||
202 | Mar | ||
203 | %B | ||
204 | --- %B --- 6 | ||
205 | March | ||
206 | %B | ||
207 | --- %B --- 7 | ||
208 | Apr | ||
209 | %B | ||
210 | --- %B --- 8 | ||
211 | April | ||
212 | %B | ||
213 | --- %B --- 9 | ||
214 | May | ||
215 | %B | ||
216 | --- %B --- 10 | ||
217 | Jun | ||
218 | %B | ||
219 | --- %B --- 11 | ||
220 | June | ||
221 | %B | ||
222 | --- %B --- 12 | ||
223 | Jul | ||
224 | %B | ||
225 | --- %B --- 13 | ||
226 | July | ||
227 | %B | ||
228 | --- %B --- 14 | ||
229 | Aug | ||
230 | %B | ||
231 | --- %B --- 15 | ||
232 | August | ||
233 | %B | ||
234 | --- %B --- 16 | ||
235 | Sep | ||
236 | %B | ||
237 | --- %B --- 17 | ||
238 | September | ||
239 | %B | ||
240 | --- %B --- 18 | ||
241 | Oct | ||
242 | %B | ||
243 | --- %B --- 19 | ||
244 | October | ||
245 | %B | ||
246 | --- %B --- 20 | ||
247 | Nov | ||
248 | %B | ||
249 | --- %B --- 21 | ||
250 | November | ||
251 | %B | ||
252 | --- %B --- 22 | ||
253 | Dec | ||
254 | %B | ||
255 | --- %B --- 23 | ||
256 | December | ||
257 | %B | ||
258 | --- %B --- 25 | ||
259 | Mayor | ||
260 | %B | ||
261 | --- %B --- 24 | ||
262 | Mars | ||
263 | %B | ||
264 | --- %B --- 26 | ||
265 | Rover | ||
266 | %B | ||
267 | EOF | ||
diff --git a/src/regress/lib/libc/vis/Makefile b/src/regress/lib/libc/vis/Makefile new file mode 100644 index 0000000000..13e560bbf7 --- /dev/null +++ b/src/regress/lib/libc/vis/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2005/08/29 18:41:56 otto Exp $ | ||
2 | |||
3 | PROG= vis_test | ||
4 | CLEANFILES+= valid.out | ||
5 | |||
6 | run-regress-vis_test: ${PROG} | ||
7 | ./${PROG} >${.OBJDIR}/valid.out | ||
8 | cmp -s ${.OBJDIR}/valid.out ${.CURDIR}/valid.ok | ||
9 | |||
10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/vis/valid.ok b/src/regress/lib/libc/vis/valid.ok new file mode 100644 index 0000000000..f8c0efa503 --- /dev/null +++ b/src/regress/lib/libc/vis/valid.ok | |||
@@ -0,0 +1,2 @@ | |||
1 | \^@\^A\^B\^C\^D\^E\^F\^G\^H | ||
2 | \^K\^L\^M\^N\^O\^P\^Q\^R\^S\^T\^U\^V\^W\^X\^Y\^Z\^[\^\\^]\^^\^_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\^?\M^@\M^A\M^B\M^C\M^D\M^E\M^F\M^G\M^H\M^I\M^J\M^K\M^L\M^M\M^N\M^O\M^P\M^Q\M^R\M^S\M^T\M^U\M^V\M^W\M^X\M^Y\M^Z\M^[\M^\\M^]\M^^\M^_\240\M-!\M-"\M-#\M-$\M-%\M-&\M-'\M-(\M-)\M-*\M-+\M-,\M--\M-.\M-/\M-0\M-1\M-2\M-3\M-4\M-5\M-6\M-7\M-8\M-9\M-:\M-;\M-<\M-=\M->\M-?\M-@\M-A\M-B\M-C\M-D\M-E\M-F\M-G\M-H\M-I\M-J\M-K\M-L\M-M\M-N\M-O\M-P\M-Q\M-R\M-S\M-T\M-U\M-V\M-W\M-X\M-Y\M-Z\M-[\M-\\M-]\M-^\M-_\M-`\M-a\M-b\M-c\M-d\M-e\M-f\M-g\M-h\M-i\M-j\M-k\M-l\M-m\M-n\M-o\M-p\M-q\M-r\M-s\M-t\M-u\M-v\M-w\M-x\M-y\M-z\M-{\M-|\M-}\M-~\M^? | ||
diff --git a/src/regress/lib/libc/vis/vis_test.c b/src/regress/lib/libc/vis/vis_test.c new file mode 100644 index 0000000000..74113e7a61 --- /dev/null +++ b/src/regress/lib/libc/vis/vis_test.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* $OpenBSD: vis_test.c,v 1.3 2011/03/13 22:12:37 deraadt Exp $ */ | ||
2 | |||
3 | /* Public domain. 2005, Otto Moerbeek */ | ||
4 | |||
5 | #include <limits.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <string.h> | ||
8 | #include <stdio.h> | ||
9 | #include <vis.h> | ||
10 | |||
11 | #define NTESTS 8000 | ||
12 | #define NCH 800 | ||
13 | |||
14 | char ibuf[NCH]; | ||
15 | char obuf[NCH * 4]; | ||
16 | char rbuf[NCH * 4]; | ||
17 | |||
18 | int flags[] = { | ||
19 | VIS_ALL, | ||
20 | VIS_GLOB, | ||
21 | VIS_TAB, | ||
22 | VIS_NL, | ||
23 | VIS_WHITE, | ||
24 | VIS_SAFE | ||
25 | }; | ||
26 | |||
27 | char *flagname[] = { | ||
28 | "VIS_ALL", | ||
29 | "VIS_GLOB", | ||
30 | "VIS_TAB", | ||
31 | "VIS_NL", | ||
32 | "VIS_WHITE", | ||
33 | "VIS_SAFE" | ||
34 | }; | ||
35 | |||
36 | int title; | ||
37 | |||
38 | void | ||
39 | dotitle(int i, int j) | ||
40 | { | ||
41 | if (title == 0) | ||
42 | printf("%d %s:", i, flagname[j]); | ||
43 | title = 1; | ||
44 | } | ||
45 | |||
46 | int | ||
47 | main(int argc, char *argv[]) | ||
48 | { | ||
49 | |||
50 | char inp[UCHAR_MAX + 1]; | ||
51 | char out[4 * UCHAR_MAX + 1]; | ||
52 | int i, j, fail = 0; | ||
53 | ssize_t owant, o, r; | ||
54 | |||
55 | for (i = 0; i <= UCHAR_MAX; i++) { | ||
56 | inp[i] = i; | ||
57 | } | ||
58 | strvisx(out, inp, UCHAR_MAX + 1, 0); | ||
59 | printf("%s\n", out); | ||
60 | |||
61 | for (i = 0; i < NTESTS; i++) { | ||
62 | arc4random_buf(ibuf, sizeof(ibuf) - 1); | ||
63 | ibuf[sizeof(ibuf) - 1] = '\0'; | ||
64 | title = 0; | ||
65 | |||
66 | for (j = 0; j < sizeof(flags)/sizeof(flags[0]); j++) { | ||
67 | owant = sizeof(ibuf); | ||
68 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
69 | if (o >= owant) { | ||
70 | owant = o + 1; | ||
71 | o = strnvis(obuf, ibuf, owant, flags[j]); | ||
72 | if (o > owant) { | ||
73 | dotitle(i, j); | ||
74 | printf("HUGE overflow\n"); | ||
75 | } | ||
76 | if (o < owant - 1) { | ||
77 | dotitle(i, j); | ||
78 | printf("over-estimate of overflow\n"); | ||
79 | } | ||
80 | } else if (o > strlen(ibuf) * 4) { | ||
81 | dotitle(i, j); | ||
82 | printf("wants too much %d %d\n", o, strlen(ibuf) * 4); | ||
83 | continue; | ||
84 | } | ||
85 | |||
86 | r = strnunvis(rbuf, obuf, sizeof rbuf); | ||
87 | |||
88 | if (r == -1) { | ||
89 | dotitle(i, j); | ||
90 | printf("cannot decode\n"); | ||
91 | printf("%s\n", obuf); | ||
92 | fail = 1; | ||
93 | } else if (r != strlen(ibuf)) { | ||
94 | dotitle(i, j); | ||
95 | printf("rlen %d != inlen %d\n", r, strlen(ibuf)); | ||
96 | printf("%s\n", obuf); | ||
97 | printf("%s\n", rbuf); | ||
98 | fail = 1; | ||
99 | } else if (bcmp(ibuf, rbuf, r)) { | ||
100 | dotitle(i, j); | ||
101 | printf("strings are different\n"); | ||
102 | printf("%s\n", ibuf); | ||
103 | printf("%s\n", rbuf); | ||
104 | fail = 1; | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | exit(fail); | ||
109 | } | ||
diff --git a/src/regress/lib/libc/wprintf/Makefile b/src/regress/lib/libc/wprintf/Makefile new file mode 100644 index 0000000000..7b1897f2c4 --- /dev/null +++ b/src/regress/lib/libc/wprintf/Makefile | |||
@@ -0,0 +1,5 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2011/04/24 08:00:22 stsp Exp $ | ||
2 | |||
3 | PROG= wfp | ||
4 | |||
5 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/wprintf/wfp.c b/src/regress/lib/libc/wprintf/wfp.c new file mode 100644 index 0000000000..fc3120b53c --- /dev/null +++ b/src/regress/lib/libc/wprintf/wfp.c | |||
@@ -0,0 +1,218 @@ | |||
1 | /* $OpenBSD: wfp.c,v 1.1 2011/04/24 08:00:22 stsp Exp $ */ | ||
2 | /*- | ||
3 | * Copyright (c) 2002, 2005 David Schultz <das@FreeBSD.org> | ||
4 | * All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions | ||
8 | * are met: | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * | ||
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
25 | * SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | /* | ||
29 | * Test for wprintf() floating point formats. | ||
30 | */ | ||
31 | |||
32 | #include <assert.h> | ||
33 | #include <err.h> | ||
34 | #include <float.h> | ||
35 | #include <math.h> | ||
36 | #include <stdio.h> | ||
37 | #include <stdarg.h> | ||
38 | #include <stdint.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | #include <wchar.h> | ||
42 | |||
43 | #define testfmt(result, fmt, ...) \ | ||
44 | _testfmt((result), __LINE__, #__VA_ARGS__, fmt, __VA_ARGS__) | ||
45 | void _testfmt(const wchar_t *, int, const char *, const wchar_t *, ...); | ||
46 | void smash_stack(void); | ||
47 | |||
48 | int | ||
49 | main(int argc, char *argv[]) | ||
50 | { | ||
51 | /* | ||
52 | * Basic tests of decimal output functionality. | ||
53 | */ | ||
54 | testfmt(L" 1.000000E+00", L"%13E", 1.0); | ||
55 | testfmt(L" 1.000000", L"%13f", 1.0); | ||
56 | testfmt(L" 1", L"%13G", 1.0); | ||
57 | testfmt(L" 1.000000E+00", L"%13LE", 1.0L); | ||
58 | testfmt(L" 1.000000", L"%13Lf", 1.0L); | ||
59 | testfmt(L" 1", L"%13LG", 1.0L); | ||
60 | |||
61 | testfmt(L"2.718282", L"%.*f", -2, 2.7182818); | ||
62 | |||
63 | testfmt(L"1.234568e+06", L"%e", 1234567.8); | ||
64 | testfmt(L"1234567.800000", L"%f", 1234567.8); | ||
65 | testfmt(L"1.23457E+06", L"%G", 1234567.8); | ||
66 | testfmt(L"1.234568e+06", L"%Le", 1234567.8L); | ||
67 | testfmt(L"1234567.800000", L"%Lf", 1234567.8L); | ||
68 | testfmt(L"1.23457E+06", L"%LG", 1234567.8L); | ||
69 | |||
70 | #if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) | ||
71 | testfmt(L"123456789.864210", L"%Lf", 123456789.8642097531L); | ||
72 | testfmt(L"-1.23457E+08", L"%LG", -123456789.8642097531L); | ||
73 | testfmt(L"123456789.8642097531", L"%.10Lf", 123456789.8642097531L); | ||
74 | testfmt(L" 3.141592653589793238e-4000", L"%L27.18Le", | ||
75 | 3.14159265358979323846e-4000L); | ||
76 | #endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */ | ||
77 | |||
78 | /* | ||
79 | * Infinities and NaNs | ||
80 | */ | ||
81 | #ifdef NAN | ||
82 | testfmt(L"nan", L"%e", NAN); | ||
83 | testfmt(L"NAN", L"%F", NAN); | ||
84 | testfmt(L"nan", L"%g", NAN); | ||
85 | testfmt(L"NAN", L"%LE", (long double)NAN); | ||
86 | testfmt(L" nan", L"%05e", NAN); | ||
87 | #endif /* NAN */ | ||
88 | |||
89 | testfmt(L"INF", L"%E", HUGE_VAL); | ||
90 | testfmt(L"-inf", L"%f", -HUGE_VAL); | ||
91 | testfmt(L"+inf", L"%+g", HUGE_VAL); | ||
92 | testfmt(L" inf", L"%4.2Le", HUGE_VALL); | ||
93 | testfmt(L"-inf", L"%Lf", -HUGE_VALL); | ||
94 | testfmt(L" inf", L"%05e", HUGE_VAL); | ||
95 | testfmt(L" -inf", L"%05e", -HUGE_VAL); | ||
96 | |||
97 | /* | ||
98 | * Padding | ||
99 | */ | ||
100 | testfmt(L"0.000000e+00", L"%e", 0.0); | ||
101 | testfmt(L"0.000000", L"%F", (double)0.0); | ||
102 | testfmt(L"0", L"%G", 0.0); | ||
103 | testfmt(L" 0", L"%3.0Lg", 0.0L); | ||
104 | testfmt(L" 0", L"%5.0f", 0.001); | ||
105 | |||
106 | /* | ||
107 | * Precision specifiers | ||
108 | */ | ||
109 | testfmt(L"1.0123e+00", L"%.4e", 1.0123456789); | ||
110 | testfmt(L"1.0123", L"%.4f", 1.0123456789); | ||
111 | testfmt(L"1.012", L"%.4g", 1.0123456789); | ||
112 | testfmt(L"1.2346e-02", L"%.4e", 0.0123456789); | ||
113 | testfmt(L"0.0123", L"%.4f", 0.0123456789); | ||
114 | testfmt(L"0.01235", L"%.4g", 0.0123456789); | ||
115 | |||
116 | /* | ||
117 | * Signed conversions | ||
118 | */ | ||
119 | testfmt(L"+2.500000e-01", L"%+e", 0.25); | ||
120 | testfmt(L"+0.000000", L"%+F", 0.0); | ||
121 | testfmt(L"-1", L"%+g", -1.0); | ||
122 | |||
123 | testfmt(L"-1.000000e+00", L"% e", -1.0); | ||
124 | testfmt(L"+1.000000", L"% +f", 1.0); | ||
125 | testfmt(L" 1", L"% g", 1.0); | ||
126 | testfmt(L" 0", L"% g", 0.0); | ||
127 | |||
128 | /* | ||
129 | * ``Alternate form'' | ||
130 | */ | ||
131 | testfmt(L"1.250e+00", L"%#.3e", 1.25); | ||
132 | testfmt(L"123.000000", L"%#f", 123.0); | ||
133 | testfmt(L" 12345.", L"%#7.5g", 12345.0); | ||
134 | testfmt(L" 1.00000", L"%#8g", 1.0); | ||
135 | testfmt(L"0.0", L"%#.2g", 0.0); | ||
136 | |||
137 | /* | ||
138 | * Padding and decimal point placement | ||
139 | */ | ||
140 | testfmt(L"03.2E+00", L"%08.1E", 3.25); | ||
141 | testfmt(L"003.25", L"%06.2F", 3.25); | ||
142 | testfmt(L"0003.25", L"%07.4G", 3.25); | ||
143 | |||
144 | testfmt(L"3.14159e-05", L"%g", 3.14159e-5); | ||
145 | testfmt(L"0.000314159", L"%g", 3.14159e-4); | ||
146 | testfmt(L"3.14159e+06", L"%g", 3.14159e6); | ||
147 | testfmt(L"314159", L"%g", 3.14159e5); | ||
148 | testfmt(L"314159.", L"%#g", 3.14159e5); | ||
149 | |||
150 | testfmt(L" 9.000000e+03", L"%13e", 9000.0); | ||
151 | testfmt(L" 9000.000000", L"%12f", 9000.0); | ||
152 | testfmt(L" 9000", L"%5g", 9000.0); | ||
153 | testfmt(L" 900000.", L"%#8g", 900000.0); | ||
154 | testfmt(L" 9e+06", L"%6g", 9000000.0); | ||
155 | testfmt(L" 9.000000e-04", L"%13e", 0.0009); | ||
156 | testfmt(L" 0.000900", L"%9f", 0.0009); | ||
157 | testfmt(L" 0.0009", L"%7g", 0.0009); | ||
158 | testfmt(L" 9e-05", L"%6g", 0.00009); | ||
159 | testfmt(L" 9.00000e-05", L"%#12g", 0.00009); | ||
160 | testfmt(L" 9.e-05", L"%#7.1g", 0.00009); | ||
161 | |||
162 | testfmt(L" 0.0", L"%4.1f", 0.0); | ||
163 | testfmt(L"90.0", L"%4.1f", 90.0); | ||
164 | testfmt(L" 100", L"%4.0f", 100.0); | ||
165 | testfmt(L"9.0e+01", L"%4.1e", 90.0); | ||
166 | testfmt(L"1e+02", L"%4.0e", 100.0); | ||
167 | |||
168 | /* | ||
169 | * Hexadecimal floating point (%a, %A) tests. Some of these | ||
170 | * are only valid if the implementation converts to hex digits | ||
171 | * on nibble boundaries. | ||
172 | */ | ||
173 | testfmt(L"0x0p+0", L"%a", 0x0.0p0); | ||
174 | testfmt(L"0X0.P+0", L"%#LA", 0x0.0p0L); | ||
175 | #ifdef NAN | ||
176 | testfmt(L"inf", L"%La", (long double)INFINITY); | ||
177 | testfmt(L"+INF", L"%+A", INFINITY); | ||
178 | testfmt(L"nan", L"%La", (long double)NAN); | ||
179 | testfmt(L"NAN", L"%A", NAN); | ||
180 | #endif /* NAN */ | ||
181 | |||
182 | testfmt(L" 0x1.23p+0", L"%10a", 0x1.23p0); | ||
183 | testfmt(L" 0x1.23p-500", L"%12a", 0x1.23p-500); | ||
184 | testfmt(L" 0x1.2p+40", L"%10.1a", 0x1.23p40); | ||
185 | testfmt(L" 0X1.230000000000000000000000P-4", L"%32.24A", 0x1.23p-4); | ||
186 | testfmt(L"0x1p-1074", L"%a", 0x1p-1074); | ||
187 | testfmt(L"0x1.2345p-1024", L"%a", 0x1.2345p-1024); | ||
188 | |||
189 | return (0); | ||
190 | } | ||
191 | |||
192 | void | ||
193 | smash_stack(void) | ||
194 | { | ||
195 | static uint32_t junk = 0xdeadbeef; | ||
196 | uint32_t buf[512]; | ||
197 | int i; | ||
198 | |||
199 | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||
200 | buf[i] = junk; | ||
201 | } | ||
202 | |||
203 | void | ||
204 | _testfmt(const wchar_t *result, int line, const char *argstr, const wchar_t *fmt,...) | ||
205 | { | ||
206 | wchar_t s[100]; | ||
207 | va_list ap; | ||
208 | |||
209 | va_start(ap, fmt); | ||
210 | smash_stack(); | ||
211 | vswprintf(s, sizeof(s), fmt, ap); | ||
212 | if (wcscmp(result, s) != 0) { | ||
213 | fprintf(stderr, | ||
214 | "%d: printf(\"%s\", %s) ==> [%s], expected [%s]\n", | ||
215 | line, (char*)fmt, argstr, s, result); | ||
216 | abort(); | ||
217 | } | ||
218 | } | ||