diff options
Diffstat (limited to 'src/regress/lib/libc')
113 files changed, 4885 insertions, 358 deletions
diff --git a/src/regress/lib/libc/Makefile b/src/regress/lib/libc/Makefile index 7b65e2c1c5..cca83b0a86 100644 --- a/src/regress/lib/libc/Makefile +++ b/src/regress/lib/libc/Makefile | |||
@@ -1,6 +1,10 @@ | |||
1 | # $NetBSD: Makefile,v 1.6 1995/04/24 05:52:15 cgd Exp $ | 1 | # $OpenBSD: Makefile,v 1.28 2008/10/02 12:26:45 millert 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 | ||
2 | 7 | ||
3 | SUBDIR+= _setjmp db regex setjmp sigsetjmp | ||
4 | .if (${MACHINE_ARCH} != "vax") | 8 | .if (${MACHINE_ARCH} != "vax") |
5 | SUBDIR+= ieeefp | 9 | SUBDIR+= ieeefp |
6 | .endif | 10 | .endif |
@@ -9,8 +13,6 @@ SUBDIR+= ieeefp | |||
9 | SUBDIR+= arch/${MACHINE_ARCH} | 13 | SUBDIR+= arch/${MACHINE_ARCH} |
10 | .endif | 14 | .endif |
11 | 15 | ||
12 | regress: _SUBDIRUSE | ||
13 | |||
14 | install: | 16 | install: |
15 | 17 | ||
16 | .include <bsd.subdir.mk> | 18 | .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/cxa-atexit/Makefile b/src/regress/lib/libc/cxa-atexit/Makefile new file mode 100644 index 0000000000..ffd83fe1ca --- /dev/null +++ b/src/regress/lib/libc/cxa-atexit/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2007/09/03 14:42:44 millert Exp $ | ||
2 | |||
3 | .include <bsd.own.mk> | ||
4 | |||
5 | USE_GCC3?=No | ||
6 | |||
7 | .if ${USE_GCC3:L} == "yes" | ||
8 | SUBDIR+= libgd1 libgd2 test1 | ||
9 | .endif | ||
10 | |||
11 | install: | ||
12 | |||
13 | .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..8eda40d6b3 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.11 2003/07/31 21:48:02 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 | * |
@@ -35,15 +32,15 @@ | |||
35 | 32 | ||
36 | #ifndef lint | 33 | #ifndef lint |
37 | static char copyright[] = | 34 | static char copyright[] = |
38 | "@(#) Copyright (c) 1992, 1993\n\ | 35 | "@(#) Copyright (c) 1992, 1993, 1994\n\ |
39 | The Regents of the University of California. All rights reserved.\n"; | 36 | The Regents of the University of California. All rights reserved.\n"; |
40 | #endif /* not lint */ | 37 | #endif /* not lint */ |
41 | 38 | ||
42 | #ifndef lint | 39 | #ifndef lint |
43 | #if 0 | 40 | #if 0 |
44 | static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; | 41 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; |
45 | #else | 42 | #else |
46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | 43 | static char rcsid[] = "$OpenBSD: dbtest.c,v 1.11 2003/07/31 21:48:02 deraadt Exp $"; |
47 | #endif | 44 | #endif |
48 | #endif /* not lint */ | 45 | #endif /* not lint */ |
49 | 46 | ||
@@ -57,39 +54,41 @@ static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | |||
57 | #include <stdio.h> | 54 | #include <stdio.h> |
58 | #include <stdlib.h> | 55 | #include <stdlib.h> |
59 | #include <string.h> | 56 | #include <string.h> |
57 | #include <stdarg.h> | ||
60 | #include <unistd.h> | 58 | #include <unistd.h> |
61 | 59 | ||
62 | #include <db.h> | 60 | #include <db.h> |
63 | 61 | ||
64 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | 62 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; |
65 | 63 | ||
66 | void compare __P((DBT *, DBT *)); | 64 | void compare(DBT *, DBT *); |
67 | DBTYPE dbtype __P((char *)); | 65 | DBTYPE dbtype(char *); |
68 | void dump __P((DB *, int)); | 66 | void dump(DB *, int); |
69 | void err __P((const char *, ...)); | 67 | void dberr(const char *, ...); |
70 | void get __P((DB *, DBT *)); | 68 | void get(DB *, DBT *); |
71 | void getdata __P((DB *, DBT *, DBT *)); | 69 | void getdata(DB *, DBT *, DBT *); |
72 | void put __P((DB *, DBT *, DBT *)); | 70 | void put(DB *, DBT *, DBT *); |
73 | void rem __P((DB *, DBT *)); | 71 | void rem(DB *, DBT *); |
74 | void *rfile __P((char *, size_t *)); | 72 | char *sflags(int); |
75 | void seq __P((DB *, DBT *)); | 73 | void synk(DB *); |
76 | u_int setflags __P((char *)); | 74 | void *rfile(char *, size_t *); |
77 | void *setinfo __P((DBTYPE, char *)); | 75 | void seq(DB *, DBT *); |
78 | void usage __P((void)); | 76 | u_int setflags(char *); |
79 | void *xmalloc __P((char *, size_t)); | 77 | void *setinfo(DBTYPE, char *); |
80 | 78 | void usage(void); | |
81 | DBTYPE type; | 79 | void *xmalloc(char *, size_t); |
82 | void *infop; | 80 | |
83 | u_long lineno; | 81 | DBTYPE type; /* Database type. */ |
84 | u_int flags; | 82 | void *infop; /* Iflags. */ |
85 | int ofd = STDOUT_FILENO; | 83 | u_long lineno; /* Current line in test script. */ |
84 | u_int flags; /* Current DB flags. */ | ||
85 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
86 | 86 | ||
87 | DB *XXdbp; /* Global for gdb. */ | 87 | DB *XXdbp; /* Global for gdb. */ |
88 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
88 | 89 | ||
89 | int | 90 | int |
90 | main(argc, argv) | 91 | main(int argc, char *argv[]) |
91 | int argc; | ||
92 | char *argv[]; | ||
93 | { | 92 | { |
94 | extern int optind; | 93 | extern int optind; |
95 | extern char *optarg; | 94 | extern char *optarg; |
@@ -97,14 +96,15 @@ main(argc, argv) | |||
97 | DB *dbp; | 96 | DB *dbp; |
98 | DBT data, key, keydata; | 97 | DBT data, key, keydata; |
99 | size_t len; | 98 | size_t len; |
100 | int ch, oflags; | 99 | int ch, oflags, sflag; |
101 | char *fname, *infoarg, *p, buf[8 * 1024]; | 100 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; |
102 | 101 | ||
103 | infoarg = NULL; | 102 | infoarg = NULL; |
104 | fname = NULL; | 103 | fname = NULL; |
105 | oflags = O_CREAT | O_RDWR; | 104 | oflags = O_CREAT | O_RDWR; |
106 | while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) | 105 | sflag = 0; |
107 | switch(ch) { | 106 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) |
107 | switch (ch) { | ||
108 | case 'f': | 108 | case 'f': |
109 | fname = optarg; | 109 | fname = optarg; |
110 | break; | 110 | break; |
@@ -117,7 +117,10 @@ main(argc, argv) | |||
117 | case 'o': | 117 | case 'o': |
118 | if ((ofd = open(optarg, | 118 | if ((ofd = open(optarg, |
119 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 119 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
120 | err("%s: %s", optarg, strerror(errno)); | 120 | dberr("%s: %s", optarg, strerror(errno)); |
121 | break; | ||
122 | case 's': | ||
123 | sflag = 1; | ||
121 | break; | 124 | break; |
122 | case '?': | 125 | case '?': |
123 | default: | 126 | default: |
@@ -133,8 +136,8 @@ main(argc, argv) | |||
133 | type = dbtype(*argv++); | 136 | type = dbtype(*argv++); |
134 | 137 | ||
135 | /* Open the descriptor file. */ | 138 | /* Open the descriptor file. */ |
136 | if (freopen(*argv, "r", stdin) == NULL) | 139 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) |
137 | err("%s: %s", *argv, strerror(errno)); | 140 | dberr("%s: %s", *argv, strerror(errno)); |
138 | 141 | ||
139 | /* Set up the db structure as necessary. */ | 142 | /* Set up the db structure as necessary. */ |
140 | if (infoarg == NULL) | 143 | if (infoarg == NULL) |
@@ -145,61 +148,93 @@ main(argc, argv) | |||
145 | if (*p != '\0') | 148 | if (*p != '\0') |
146 | infop = setinfo(type, p); | 149 | infop = setinfo(type, p); |
147 | 150 | ||
148 | /* Open the DB. */ | 151 | /* |
152 | * Open the DB. Delete any preexisting copy, you almost never | ||
153 | * want it around, and it often screws up tests. | ||
154 | */ | ||
149 | if (fname == NULL) { | 155 | if (fname == NULL) { |
150 | p = getenv("TMPDIR"); | 156 | p = getenv("TMPDIR"); |
151 | if (p == NULL) | 157 | if (p == NULL) |
152 | p = "/var/tmp"; | 158 | p = "/var/tmp"; |
153 | (void)sprintf(buf, "%s/__dbtest", p); | 159 | (void)snprintf(buf, sizeof buf, "%s/__dbtest", p); |
154 | fname = buf; | 160 | fname = buf; |
155 | (void)unlink(buf); | 161 | (void)unlink(buf); |
156 | } | 162 | } else if (!sflag) |
163 | (void)unlink(fname); | ||
164 | |||
157 | if ((dbp = dbopen(fname, | 165 | if ((dbp = dbopen(fname, |
158 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | 166 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) |
159 | err("dbopen: %s", strerror(errno)); | 167 | dberr("dbopen: %s", strerror(errno)); |
160 | XXdbp = dbp; | 168 | XXdbp = dbp; |
161 | 169 | ||
162 | state = COMMAND; | 170 | state = COMMAND; |
163 | for (lineno = 1; | 171 | for (lineno = 1; |
164 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | 172 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { |
165 | len = strlen(buf); | 173 | /* Delete the newline, displaying the key/data is easier. */ |
166 | switch(*p) { | 174 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) |
175 | *t = '\0'; | ||
176 | if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') | ||
177 | continue; | ||
178 | |||
179 | /* Convenient gdb break point. */ | ||
180 | if (XXlineno == lineno) | ||
181 | XXlineno = 1; | ||
182 | switch (*p) { | ||
167 | case 'c': /* compare */ | 183 | case 'c': /* compare */ |
168 | if (state != COMMAND) | 184 | if (state != COMMAND) |
169 | err("line %lu: not expecting command", lineno); | 185 | dberr("line %lu: not expecting command", |
186 | lineno); | ||
170 | state = KEY; | 187 | state = KEY; |
171 | command = COMPARE; | 188 | command = COMPARE; |
172 | break; | 189 | break; |
173 | case 'e': /* echo */ | 190 | case 'e': /* echo */ |
174 | if (state != COMMAND) | 191 | if (state != COMMAND) |
175 | err("line %lu: not expecting command", lineno); | 192 | dberr("line %lu: not expecting command", |
193 | lineno); | ||
176 | /* Don't display the newline, if CR at EOL. */ | 194 | /* Don't display the newline, if CR at EOL. */ |
177 | if (p[len - 2] == '\r') | 195 | if (p[len - 2] == '\r') |
178 | --len; | 196 | --len; |
179 | if (write(ofd, p + 1, len - 1) != len - 1) | 197 | if (write(ofd, p + 1, len - 1) != len - 1 || |
180 | err("write: %s", strerror(errno)); | 198 | write(ofd, "\n", 1) != 1) |
199 | dberr("write: %s", strerror(errno)); | ||
181 | break; | 200 | break; |
182 | case 'g': /* get */ | 201 | case 'g': /* get */ |
183 | if (state != COMMAND) | 202 | if (state != COMMAND) |
184 | err("line %lu: not expecting command", lineno); | 203 | dberr("line %lu: not expecting command", |
204 | lineno); | ||
185 | state = KEY; | 205 | state = KEY; |
186 | command = GET; | 206 | command = GET; |
187 | break; | 207 | break; |
188 | case 'p': /* put */ | 208 | case 'p': /* put */ |
189 | if (state != COMMAND) | 209 | if (state != COMMAND) |
190 | err("line %lu: not expecting command", lineno); | 210 | dberr("line %lu: not expecting command", |
211 | lineno); | ||
191 | state = KEY; | 212 | state = KEY; |
192 | command = PUT; | 213 | command = PUT; |
193 | break; | 214 | break; |
194 | case 'r': /* remove */ | 215 | case 'r': /* remove */ |
195 | if (state != COMMAND) | 216 | if (state != COMMAND) |
196 | err("line %lu: not expecting command", lineno); | 217 | dberr("line %lu: not expecting command", |
197 | state = KEY; | 218 | lineno); |
198 | command = REMOVE; | 219 | if (flags == R_CURSOR) { |
220 | rem(dbp, &key); | ||
221 | state = COMMAND; | ||
222 | } else { | ||
223 | state = KEY; | ||
224 | command = REMOVE; | ||
225 | } | ||
226 | break; | ||
227 | case 'S': /* sync */ | ||
228 | if (state != COMMAND) | ||
229 | dberr("line %lu: not expecting command", | ||
230 | lineno); | ||
231 | synk(dbp); | ||
232 | state = COMMAND; | ||
199 | break; | 233 | break; |
200 | case 's': /* seq */ | 234 | case 's': /* seq */ |
201 | if (state != COMMAND) | 235 | if (state != COMMAND) |
202 | err("line %lu: not expecting command", lineno); | 236 | dberr("line %lu: not expecting command", |
237 | lineno); | ||
203 | if (flags == R_CURSOR) { | 238 | if (flags == R_CURSOR) { |
204 | state = KEY; | 239 | state = KEY; |
205 | command = SEQ; | 240 | command = SEQ; |
@@ -211,15 +246,15 @@ main(argc, argv) | |||
211 | break; | 246 | break; |
212 | case 'D': /* data file */ | 247 | case 'D': /* data file */ |
213 | if (state != DATA) | 248 | if (state != DATA) |
214 | err("line %lu: not expecting data", lineno); | 249 | dberr("line %lu: not expecting data", lineno); |
215 | data.data = rfile(p + 1, &data.size); | 250 | data.data = rfile(p + 1, &data.size); |
216 | goto ldata; | 251 | goto ldata; |
217 | case 'd': /* data */ | 252 | case 'd': /* data */ |
218 | if (state != DATA) | 253 | if (state != DATA) |
219 | err("line %lu: not expecting data", lineno); | 254 | dberr("line %lu: not expecting data", lineno); |
220 | data.data = xmalloc(p + 1, len - 1); | 255 | data.data = xmalloc(p + 1, len - 1); |
221 | data.size = len - 1; | 256 | data.size = len - 1; |
222 | ldata: switch(command) { | 257 | ldata: switch (command) { |
223 | case COMPARE: | 258 | case COMPARE: |
224 | compare(&keydata, &data); | 259 | compare(&keydata, &data); |
225 | break; | 260 | break; |
@@ -227,7 +262,7 @@ ldata: switch(command) { | |||
227 | put(dbp, &key, &data); | 262 | put(dbp, &key, &data); |
228 | break; | 263 | break; |
229 | default: | 264 | default: |
230 | err("line %lu: command doesn't take data", | 265 | dberr("line %lu: command doesn't take data", |
231 | lineno); | 266 | lineno); |
232 | } | 267 | } |
233 | if (type != DB_RECNO) | 268 | if (type != DB_RECNO) |
@@ -237,15 +272,15 @@ ldata: switch(command) { | |||
237 | break; | 272 | break; |
238 | case 'K': /* key file */ | 273 | case 'K': /* key file */ |
239 | if (state != KEY) | 274 | if (state != KEY) |
240 | err("line %lu: not expecting a key", lineno); | 275 | dberr("line %lu: not expecting a key", lineno); |
241 | if (type == DB_RECNO) | 276 | if (type == DB_RECNO) |
242 | err("line %lu: 'K' not available for recno", | 277 | dberr("line %lu: 'K' not available for recno", |
243 | lineno); | 278 | lineno); |
244 | key.data = rfile(p + 1, &key.size); | 279 | key.data = rfile(p + 1, &key.size); |
245 | goto lkey; | 280 | goto lkey; |
246 | case 'k': /* key */ | 281 | case 'k': /* key */ |
247 | if (state != KEY) | 282 | if (state != KEY) |
248 | err("line %lu: not expecting a key", lineno); | 283 | dberr("line %lu: not expecting a key", lineno); |
249 | if (type == DB_RECNO) { | 284 | if (type == DB_RECNO) { |
250 | static recno_t recno; | 285 | static recno_t recno; |
251 | recno = atoi(p + 1); | 286 | recno = atoi(p + 1); |
@@ -255,7 +290,7 @@ ldata: switch(command) { | |||
255 | key.data = xmalloc(p + 1, len - 1); | 290 | key.data = xmalloc(p + 1, len - 1); |
256 | key.size = len - 1; | 291 | key.size = len - 1; |
257 | } | 292 | } |
258 | lkey: switch(command) { | 293 | lkey: switch (command) { |
259 | case COMPARE: | 294 | case COMPARE: |
260 | getdata(dbp, &key, &keydata); | 295 | getdata(dbp, &key, &keydata); |
261 | state = DATA; | 296 | state = DATA; |
@@ -271,18 +306,18 @@ lkey: switch(command) { | |||
271 | break; | 306 | break; |
272 | case REMOVE: | 307 | case REMOVE: |
273 | rem(dbp, &key); | 308 | rem(dbp, &key); |
274 | if (type != DB_RECNO) | 309 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
275 | free(key.data); | 310 | free(key.data); |
276 | state = COMMAND; | 311 | state = COMMAND; |
277 | break; | 312 | break; |
278 | case SEQ: | 313 | case SEQ: |
279 | seq(dbp, &key); | 314 | seq(dbp, &key); |
280 | if (type != DB_RECNO) | 315 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
281 | free(key.data); | 316 | free(key.data); |
282 | state = COMMAND; | 317 | state = COMMAND; |
283 | break; | 318 | break; |
284 | default: | 319 | default: |
285 | err("line %lu: command doesn't take a key", | 320 | dberr("line %lu: command doesn't take a key", |
286 | lineno); | 321 | lineno); |
287 | } | 322 | } |
288 | break; | 323 | break; |
@@ -290,22 +325,25 @@ lkey: switch(command) { | |||
290 | dump(dbp, p[1] == 'r'); | 325 | dump(dbp, p[1] == 'r'); |
291 | break; | 326 | break; |
292 | default: | 327 | default: |
293 | err("line %lu: %s: unknown command character", | 328 | dberr("line %lu: %s: unknown command character", |
294 | p, lineno); | 329 | lineno, p); |
295 | } | 330 | } |
296 | } | 331 | } |
297 | #ifdef STATISTICS | 332 | #ifdef STATISTICS |
298 | if (type == DB_BTREE) | 333 | /* |
334 | * -l must be used (DB_LOCK must be set) for this to be | ||
335 | * used, otherwise a page will be locked and it will fail. | ||
336 | */ | ||
337 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
299 | __bt_stat(dbp); | 338 | __bt_stat(dbp); |
300 | #endif | 339 | #endif |
301 | if (dbp->close(dbp)) | 340 | if (dbp->close(dbp)) |
302 | err("db->close: %s", strerror(errno)); | 341 | dberr("db->close: %s", strerror(errno)); |
303 | (void)close(ofd); | 342 | (void)close(ofd); |
304 | exit(0); | 343 | exit(0); |
305 | } | 344 | } |
306 | 345 | ||
307 | #define NOOVERWRITE "put failed, would overwrite key\n" | 346 | #define NOOVERWRITE "put failed, would overwrite key\n" |
308 | #define NOSUCHKEY "get failed, no such key\n" | ||
309 | 347 | ||
310 | void | 348 | void |
311 | compare(db1, db2) | 349 | compare(db1, db2) |
@@ -334,17 +372,23 @@ get(dbp, kp) | |||
334 | { | 372 | { |
335 | DBT data; | 373 | DBT data; |
336 | 374 | ||
337 | switch(dbp->get(dbp, kp, &data, flags)) { | 375 | switch (dbp->get(dbp, kp, &data, flags)) { |
338 | case 0: | 376 | case 0: |
339 | (void)write(ofd, data.data, data.size); | 377 | (void)write(ofd, data.data, data.size); |
378 | if (ofd == STDOUT_FILENO) | ||
379 | (void)write(ofd, "\n", 1); | ||
340 | break; | 380 | break; |
341 | case -1: | 381 | case -1: |
342 | err("line %lu: get: %s", lineno, strerror(errno)); | 382 | dberr("line %lu: get: %s", lineno, strerror(errno)); |
343 | /* NOTREACHED */ | 383 | /* NOTREACHED */ |
344 | case 1: | 384 | case 1: |
345 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 385 | #define NOSUCHKEY "get failed, no such key\n" |
346 | (void)fprintf(stderr, "%d: %.*s: %s\n", | 386 | if (ofd != STDOUT_FILENO) |
347 | lineno, kp->size, kp->data, NOSUCHKEY); | 387 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); |
388 | else | ||
389 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
390 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
391 | #undef NOSUCHKEY | ||
348 | break; | 392 | break; |
349 | } | 393 | } |
350 | } | 394 | } |
@@ -354,14 +398,14 @@ getdata(dbp, kp, dp) | |||
354 | DB *dbp; | 398 | DB *dbp; |
355 | DBT *kp, *dp; | 399 | DBT *kp, *dp; |
356 | { | 400 | { |
357 | switch(dbp->get(dbp, kp, dp, flags)) { | 401 | switch (dbp->get(dbp, kp, dp, flags)) { |
358 | case 0: | 402 | case 0: |
359 | return; | 403 | return; |
360 | case -1: | 404 | case -1: |
361 | err("line %lu: getdata: %s", lineno, strerror(errno)); | 405 | dberr("line %lu: getdata: %s", lineno, strerror(errno)); |
362 | /* NOTREACHED */ | 406 | /* NOTREACHED */ |
363 | case 1: | 407 | case 1: |
364 | err("line %lu: get failed, no such key", lineno); | 408 | dberr("line %lu: getdata failed, no such key", lineno); |
365 | /* NOTREACHED */ | 409 | /* NOTREACHED */ |
366 | } | 410 | } |
367 | } | 411 | } |
@@ -371,11 +415,11 @@ put(dbp, kp, dp) | |||
371 | DB *dbp; | 415 | DB *dbp; |
372 | DBT *kp, *dp; | 416 | DBT *kp, *dp; |
373 | { | 417 | { |
374 | switch(dbp->put(dbp, kp, dp, flags)) { | 418 | switch (dbp->put(dbp, kp, dp, flags)) { |
375 | case 0: | 419 | case 0: |
376 | break; | 420 | break; |
377 | case -1: | 421 | case -1: |
378 | err("line %lu: put: %s", lineno, strerror(errno)); | 422 | dberr("line %lu: put: %s", lineno, strerror(errno)); |
379 | /* NOTREACHED */ | 423 | /* NOTREACHED */ |
380 | case 1: | 424 | case 1: |
381 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | 425 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); |
@@ -388,34 +432,67 @@ rem(dbp, kp) | |||
388 | DB *dbp; | 432 | DB *dbp; |
389 | DBT *kp; | 433 | DBT *kp; |
390 | { | 434 | { |
391 | switch(dbp->del(dbp, kp, flags)) { | 435 | switch (dbp->del(dbp, kp, flags)) { |
392 | case 0: | 436 | case 0: |
393 | break; | 437 | break; |
394 | case -1: | 438 | case -1: |
395 | err("line %lu: get: %s", lineno, strerror(errno)); | 439 | dberr("line %lu: rem: %s", lineno, strerror(errno)); |
396 | /* NOTREACHED */ | 440 | /* NOTREACHED */ |
397 | case 1: | 441 | case 1: |
398 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 442 | #define NOSUCHKEY "rem failed, no such key\n" |
443 | if (ofd != STDOUT_FILENO) | ||
444 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
445 | else if (flags != R_CURSOR) | ||
446 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
447 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
448 | else | ||
449 | (void)fprintf(stderr, | ||
450 | "%d: rem of cursor failed\n", lineno); | ||
451 | #undef NOSUCHKEY | ||
399 | break; | 452 | break; |
400 | } | 453 | } |
401 | } | 454 | } |
402 | 455 | ||
403 | void | 456 | void |
457 | synk(dbp) | ||
458 | DB *dbp; | ||
459 | { | ||
460 | switch (dbp->sync(dbp, flags)) { | ||
461 | case 0: | ||
462 | break; | ||
463 | case -1: | ||
464 | dberr("line %lu: synk: %s", lineno, strerror(errno)); | ||
465 | /* NOTREACHED */ | ||
466 | } | ||
467 | } | ||
468 | |||
469 | void | ||
404 | seq(dbp, kp) | 470 | seq(dbp, kp) |
405 | DB *dbp; | 471 | DB *dbp; |
406 | DBT *kp; | 472 | DBT *kp; |
407 | { | 473 | { |
408 | DBT data; | 474 | DBT data; |
409 | 475 | ||
410 | switch(dbp->seq(dbp, kp, &data, flags)) { | 476 | switch (dbp->seq(dbp, kp, &data, flags)) { |
411 | case 0: | 477 | case 0: |
412 | (void)write(ofd, data.data, data.size); | 478 | (void)write(ofd, data.data, data.size); |
479 | if (ofd == STDOUT_FILENO) | ||
480 | (void)write(ofd, "\n", 1); | ||
413 | break; | 481 | break; |
414 | case -1: | 482 | case -1: |
415 | err("line %lu: seq: %s", lineno, strerror(errno)); | 483 | dberr("line %lu: seq: %s", lineno, strerror(errno)); |
416 | /* NOTREACHED */ | 484 | /* NOTREACHED */ |
417 | case 1: | 485 | case 1: |
418 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 486 | #define NOSUCHKEY "seq failed, no such key\n" |
487 | if (ofd != STDOUT_FILENO) | ||
488 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
489 | else if (flags == R_CURSOR) | ||
490 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
491 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
492 | else | ||
493 | (void)fprintf(stderr, | ||
494 | "%d: seq (%s) failed\n", lineno, sflags(flags)); | ||
495 | #undef NOSUCHKEY | ||
419 | break; | 496 | break; |
420 | } | 497 | } |
421 | } | 498 | } |
@@ -436,14 +513,16 @@ dump(dbp, rev) | |||
436 | nflags = R_NEXT; | 513 | nflags = R_NEXT; |
437 | } | 514 | } |
438 | for (;; flags = nflags) | 515 | for (;; flags = nflags) |
439 | switch(dbp->seq(dbp, &key, &data, flags)) { | 516 | switch (dbp->seq(dbp, &key, &data, flags)) { |
440 | case 0: | 517 | case 0: |
441 | (void)write(ofd, data.data, data.size); | 518 | (void)write(ofd, data.data, data.size); |
519 | if (ofd == STDOUT_FILENO) | ||
520 | (void)write(ofd, "\n", 1); | ||
442 | break; | 521 | break; |
443 | case 1: | 522 | case 1: |
444 | goto done; | 523 | goto done; |
445 | case -1: | 524 | case -1: |
446 | err("line %lu: (dump) seq: %s", | 525 | dberr("line %lu: (dump) seq: %s", |
447 | lineno, strerror(errno)); | 526 | lineno, strerror(errno)); |
448 | /* NOTREACHED */ | 527 | /* NOTREACHED */ |
449 | } | 528 | } |
@@ -454,34 +533,45 @@ u_int | |||
454 | setflags(s) | 533 | setflags(s) |
455 | char *s; | 534 | char *s; |
456 | { | 535 | { |
457 | char *p, *index(); | 536 | char *p; |
458 | 537 | ||
459 | for (; isspace(*s); ++s); | 538 | for (; isspace(*s); ++s); |
460 | if (*s == '\n') | 539 | if (*s == '\n' || *s == '\0') |
461 | return (0); | 540 | return (0); |
462 | if ((p = index(s, '\n')) != NULL) | 541 | if ((p = strchr(s, '\n')) != NULL) |
463 | *p = '\0'; | 542 | *p = '\0'; |
464 | if (!strcmp(s, "R_CURSOR")) | 543 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); |
465 | return (R_CURSOR); | 544 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); |
466 | if (!strcmp(s, "R_FIRST")) | 545 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); |
467 | return (R_FIRST); | 546 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); |
468 | if (!strcmp(s, "R_IAFTER")) | 547 | if (!strcmp(s, "R_LAST")) return (R_LAST); |
469 | return (R_IAFTER); | 548 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); |
470 | if (!strcmp(s, "R_IBEFORE")) | 549 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); |
471 | return (R_IBEFORE); | 550 | if (!strcmp(s, "R_PREV")) return (R_PREV); |
472 | if (!strcmp(s, "R_LAST")) | 551 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); |
473 | return (R_LAST); | 552 | |
474 | if (!strcmp(s, "R_NEXT")) | 553 | 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 */ | 554 | /* NOTREACHED */ |
484 | } | 555 | } |
556 | |||
557 | char * | ||
558 | sflags(flags) | ||
559 | int flags; | ||
560 | { | ||
561 | switch (flags) { | ||
562 | case R_CURSOR: return ("R_CURSOR"); | ||
563 | case R_FIRST: return ("R_FIRST"); | ||
564 | case R_IAFTER: return ("R_IAFTER"); | ||
565 | case R_IBEFORE: return ("R_IBEFORE"); | ||
566 | case R_LAST: return ("R_LAST"); | ||
567 | case R_NEXT: return ("R_NEXT"); | ||
568 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
569 | case R_PREV: return ("R_PREV"); | ||
570 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
571 | } | ||
572 | |||
573 | return ("UNKNOWN!"); | ||
574 | } | ||
485 | 575 | ||
486 | DBTYPE | 576 | DBTYPE |
487 | dbtype(s) | 577 | dbtype(s) |
@@ -493,7 +583,7 @@ dbtype(s) | |||
493 | return (DB_HASH); | 583 | return (DB_HASH); |
494 | if (!strcmp(s, "recno")) | 584 | if (!strcmp(s, "recno")) |
495 | return (DB_RECNO); | 585 | return (DB_RECNO); |
496 | err("%s: unknown type (use btree, hash or recno)", s); | 586 | dberr("%s: unknown type (use btree, hash or recno)", s); |
497 | /* NOTREACHED */ | 587 | /* NOTREACHED */ |
498 | } | 588 | } |
499 | 589 | ||
@@ -505,15 +595,15 @@ setinfo(type, s) | |||
505 | static BTREEINFO ib; | 595 | static BTREEINFO ib; |
506 | static HASHINFO ih; | 596 | static HASHINFO ih; |
507 | static RECNOINFO rh; | 597 | static RECNOINFO rh; |
508 | char *eq, *index(); | 598 | char *eq; |
509 | 599 | ||
510 | if ((eq = index(s, '=')) == NULL) | 600 | if ((eq = strchr(s, '=')) == NULL) |
511 | err("%s: illegal structure set statement", s); | 601 | dberr("%s: illegal structure set statement", s); |
512 | *eq++ = '\0'; | 602 | *eq++ = '\0'; |
513 | if (!isdigit(*eq)) | 603 | if (!isdigit(*eq)) |
514 | err("%s: structure set statement must be a number", s); | 604 | dberr("%s: structure set statement must be a number", s); |
515 | 605 | ||
516 | switch(type) { | 606 | switch (type) { |
517 | case DB_BTREE: | 607 | case DB_BTREE: |
518 | if (!strcmp("flags", s)) { | 608 | if (!strcmp("flags", s)) { |
519 | ib.flags = atoi(eq); | 609 | ib.flags = atoi(eq); |
@@ -589,7 +679,7 @@ setinfo(type, s) | |||
589 | } | 679 | } |
590 | break; | 680 | break; |
591 | } | 681 | } |
592 | err("%s: unknown structure value", s); | 682 | dberr("%s: unknown structure value", s); |
593 | /* NOTREACHED */ | 683 | /* NOTREACHED */ |
594 | } | 684 | } |
595 | 685 | ||
@@ -601,20 +691,20 @@ rfile(name, lenp) | |||
601 | struct stat sb; | 691 | struct stat sb; |
602 | void *p; | 692 | void *p; |
603 | int fd; | 693 | int fd; |
604 | char *np, *index(); | 694 | char *np; |
605 | 695 | ||
606 | for (; isspace(*name); ++name); | 696 | for (; isspace(*name); ++name); |
607 | if ((np = index(name, '\n')) != NULL) | 697 | if ((np = strchr(name, '\n')) != NULL) |
608 | *np = '\0'; | 698 | *np = '\0'; |
609 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | 699 | if ((fd = open(name, O_RDONLY, 0)) < 0 || |
610 | fstat(fd, &sb)) | 700 | fstat(fd, &sb)) |
611 | err("%s: %s\n", name, strerror(errno)); | 701 | dberr("%s: %s\n", name, strerror(errno)); |
612 | #ifdef NOT_PORTABLE | 702 | #ifdef NOT_PORTABLE |
613 | if (sb.st_size > (off_t)SIZE_T_MAX) | 703 | if (sb.st_size > (off_t)SIZE_T_MAX) |
614 | err("%s: %s\n", name, strerror(E2BIG)); | 704 | dberr("%s: %s\n", name, strerror(E2BIG)); |
615 | #endif | 705 | #endif |
616 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | 706 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) |
617 | err("%s", strerror(errno)); | 707 | dberr("%s", strerror(errno)); |
618 | (void)read(fd, p, (int)sb.st_size); | 708 | (void)read(fd, p, (int)sb.st_size); |
619 | *lenp = sb.st_size; | 709 | *lenp = sb.st_size; |
620 | (void)close(fd); | 710 | (void)close(fd); |
@@ -629,7 +719,7 @@ xmalloc(text, len) | |||
629 | void *p; | 719 | void *p; |
630 | 720 | ||
631 | if ((p = (void *)malloc(len)) == NULL) | 721 | if ((p = (void *)malloc(len)) == NULL) |
632 | err("%s", strerror(errno)); | 722 | dberr("%s", strerror(errno)); |
633 | memmove(p, text, len); | 723 | memmove(p, text, len); |
634 | return (p); | 724 | return (p); |
635 | } | 725 | } |
@@ -642,27 +732,12 @@ usage() | |||
642 | exit(1); | 732 | exit(1); |
643 | } | 733 | } |
644 | 734 | ||
645 | #if __STDC__ | ||
646 | #include <stdarg.h> | ||
647 | #else | ||
648 | #include <varargs.h> | ||
649 | #endif | ||
650 | |||
651 | void | 735 | void |
652 | #if __STDC__ | 736 | 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 | { | 737 | { |
660 | va_list ap; | 738 | va_list ap; |
661 | #if __STDC__ | 739 | |
662 | va_start(ap, fmt); | 740 | va_start(ap, fmt); |
663 | #else | ||
664 | va_start(ap); | ||
665 | #endif | ||
666 | (void)fprintf(stderr, "dbtest: "); | 741 | (void)fprintf(stderr, "dbtest: "); |
667 | (void)vfprintf(stderr, fmt, ap); | 742 | (void)vfprintf(stderr, fmt, ap); |
668 | va_end(ap); | 743 | 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/fnmatch/Makefile b/src/regress/lib/libc/fnmatch/Makefile new file mode 100644 index 0000000000..b2f357105f --- /dev/null +++ b/src/regress/lib/libc/fnmatch/Makefile | |||
@@ -0,0 +1,8 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:58 millert Exp $ | ||
2 | |||
3 | PROG= fnm_test | ||
4 | |||
5 | run-regress-${PROG}: | ||
6 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
7 | |||
8 | .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..e987010095 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* $OpenBSD: fnm_test.c,v 1.1 2008/10/01 23:04:58 millert 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 | |||
12 | int | ||
13 | main(int argc, char **argv) | ||
14 | { | ||
15 | FILE *fp = stdin; | ||
16 | char pattern[1024], string[1024]; | ||
17 | int errors = 0, flags, got, want; | ||
18 | |||
19 | if (argc > 1) { | ||
20 | if ((fp = fopen(argv[1], "r")) == NULL) | ||
21 | err(1, "%s", argv[1]); | ||
22 | } | ||
23 | |||
24 | /* | ||
25 | * Read in test file, which is formatted thusly: | ||
26 | * | ||
27 | * pattern string flags expected_result | ||
28 | * | ||
29 | */ | ||
30 | for (;;) { | ||
31 | got = fscanf(fp, "%s %s 0x%x %d\n", pattern, string, &flags, | ||
32 | &want); | ||
33 | if (got == EOF) | ||
34 | break; | ||
35 | if (got == 4) { | ||
36 | got = fnmatch(pattern, string, flags); | ||
37 | if (got != want) { | ||
38 | warnx("%s %s %d: want %d, got %d", pattern, | ||
39 | string, flags, want, got); | ||
40 | errors++; | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | exit(errors); | ||
45 | } | ||
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..3c707f8a19 --- /dev/null +++ b/src/regress/lib/libc/fnmatch/fnm_test.in | |||
@@ -0,0 +1,5 @@ | |||
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 | ||
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/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile new file mode 100644 index 0000000000..4d4978a6a2 --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/Makefile | |||
@@ -0,0 +1,19 @@ | |||
1 | # $OpenBSD: Makefile,v 1.3 2002/09/02 20:01:43 avsm 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 -u 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..fa4985958f --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/answer | |||
@@ -0,0 +1,104 @@ | |||
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 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
8 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.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 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69 | ||
15 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.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 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7 | ||
24 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7 | ||
25 | ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7 | ||
26 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.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 | service not supported for ai_socktype | ||
48 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http | ||
49 | ai1: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80 | ||
50 | ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80 | ||
51 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo | ||
52 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7 | ||
53 | ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7 | ||
54 | ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7 | ||
55 | ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7 | ||
56 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp | ||
57 | ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69 | ||
58 | ai2: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69 | ||
59 | arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 | ||
60 | service not supported for ai_socktype | ||
61 | arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 | ||
62 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80 | ||
63 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80 | ||
64 | arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 | ||
65 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80 | ||
66 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80 | ||
67 | |||
68 | == empty servname | ||
69 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) | ||
70 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
71 | ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
72 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) | ||
73 | ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
74 | ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
75 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
76 | ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 | ||
77 | ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 | ||
78 | ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 | ||
79 | ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 | ||
80 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) | ||
81 | name or service is not known | ||
82 | |||
83 | == sock_raw | ||
84 | arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) | ||
85 | ai1: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 | ||
86 | ai2: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 | ||
87 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) | ||
88 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
89 | ai2: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 | ||
90 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 | ||
91 | service not supported for ai_socktype | ||
92 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www | ||
93 | service not supported for ai_socktype | ||
94 | arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) | ||
95 | ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 | ||
96 | |||
97 | == unsupported family | ||
98 | arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) | ||
99 | ai_family not supported | ||
100 | |||
101 | == the following items are specified in jinmei scopeaddr format doc. | ||
102 | arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http | ||
103 | ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80 | ||
104 | |||
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c new file mode 100644 index 0000000000..059c1aaa1a --- /dev/null +++ b/src/regress/lib/libc/getaddrinfo/gaitest.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* $OpenBSD: gaitest.c,v 1.5 2004/06/21 21:56:19 itojun 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 | #include <sys/types.h> | ||
34 | #include <sys/socket.h> | ||
35 | #include <netinet/in.h> | ||
36 | #include <arpa/inet.h> | ||
37 | #include <netdb.h> | ||
38 | #include <stdio.h> | ||
39 | #include <stdlib.h> | ||
40 | #include <string.h> | ||
41 | #include <unistd.h> | ||
42 | |||
43 | struct addrinfo ai; | ||
44 | |||
45 | char host[NI_MAXHOST]; | ||
46 | char serv[NI_MAXSERV]; | ||
47 | int vflag = 0; | ||
48 | |||
49 | static void usage(void); | ||
50 | static void print1(const char *, const struct addrinfo *, char *, char *); | ||
51 | int main(int, char *[]); | ||
52 | |||
53 | static void | ||
54 | usage() | ||
55 | { | ||
56 | fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); | ||
57 | } | ||
58 | |||
59 | static void | ||
60 | print1(title, res, h, s) | ||
61 | const char *title; | ||
62 | const struct addrinfo *res; | ||
63 | char *h; | ||
64 | char *s; | ||
65 | { | ||
66 | char *start, *end; | ||
67 | int error; | ||
68 | const int niflag = NI_NUMERICHOST | NI_NUMERICSERV; | ||
69 | |||
70 | if (res->ai_addr) { | ||
71 | error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, | ||
72 | host, sizeof(host), serv, sizeof(serv), | ||
73 | niflag); | ||
74 | h = host; | ||
75 | s = serv; | ||
76 | } else | ||
77 | error = 0; | ||
78 | |||
79 | if (vflag) { | ||
80 | start = "\t"; | ||
81 | end = "\n"; | ||
82 | } else { | ||
83 | start = " "; | ||
84 | end = ""; | ||
85 | } | ||
86 | printf("%s%s", title, end); | ||
87 | printf("%sflags 0x%x%s", start, res->ai_flags, end); | ||
88 | printf("%sfamily %d%s", start, res->ai_family, end); | ||
89 | printf("%ssocktype %d%s", start, res->ai_socktype, end); | ||
90 | printf("%sprotocol %d%s", start, res->ai_protocol, end); | ||
91 | printf("%saddrlen %d%s", start, res->ai_addrlen, end); | ||
92 | if (error) | ||
93 | printf("%serror %d%s", start, error, end); | ||
94 | else { | ||
95 | printf("%shost %s%s", start, h, end); | ||
96 | printf("%sserv %s%s", start, s, end); | ||
97 | } | ||
98 | #if 0 | ||
99 | if (res->ai_canonname) | ||
100 | printf("%scname \"%s\"%s", start, res->ai_canonname, end); | ||
101 | #endif | ||
102 | if (!vflag) | ||
103 | printf("\n"); | ||
104 | |||
105 | } | ||
106 | |||
107 | int | ||
108 | main(argc, argv) | ||
109 | int argc; | ||
110 | char *argv[]; | ||
111 | { | ||
112 | struct addrinfo *res; | ||
113 | int error, i; | ||
114 | char *p, *q; | ||
115 | extern int optind; | ||
116 | extern char *optarg; | ||
117 | int c; | ||
118 | char nbuf[10]; | ||
119 | |||
120 | memset(&ai, 0, sizeof(ai)); | ||
121 | ai.ai_family = PF_UNSPEC; | ||
122 | ai.ai_flags |= AI_CANONNAME; | ||
123 | while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { | ||
124 | switch (c) { | ||
125 | case 'D': | ||
126 | ai.ai_socktype = SOCK_DGRAM; | ||
127 | break; | ||
128 | case 'f': | ||
129 | ai.ai_family = atoi(optarg); | ||
130 | break; | ||
131 | case 'p': | ||
132 | ai.ai_protocol = atoi(optarg); | ||
133 | break; | ||
134 | case 'P': | ||
135 | ai.ai_flags |= AI_PASSIVE; | ||
136 | break; | ||
137 | case 'R': | ||
138 | ai.ai_socktype = SOCK_RAW; | ||
139 | break; | ||
140 | case 's': | ||
141 | ai.ai_socktype = atoi(optarg); | ||
142 | break; | ||
143 | case 'S': | ||
144 | ai.ai_socktype = SOCK_STREAM; | ||
145 | break; | ||
146 | case 'v': | ||
147 | vflag++; | ||
148 | break; | ||
149 | case '4': | ||
150 | ai.ai_family = PF_INET; | ||
151 | break; | ||
152 | case '6': | ||
153 | ai.ai_family = PF_INET6; | ||
154 | break; | ||
155 | default: | ||
156 | usage(); | ||
157 | exit(1); | ||
158 | } | ||
159 | } | ||
160 | argc -= optind; | ||
161 | argv += optind; | ||
162 | |||
163 | if (argc != 2){ | ||
164 | usage(); | ||
165 | exit(1); | ||
166 | } | ||
167 | |||
168 | p = *argv[0] ? argv[0] : NULL; | ||
169 | q = *argv[1] ? argv[1] : NULL; | ||
170 | |||
171 | print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)"); | ||
172 | |||
173 | error = getaddrinfo(p, q, &ai, &res); | ||
174 | if (error) { | ||
175 | printf("%s\n", gai_strerror(error)); | ||
176 | exit(1); | ||
177 | } | ||
178 | |||
179 | i = 1; | ||
180 | do { | ||
181 | snprintf(nbuf, sizeof(nbuf), "ai%d:", i); | ||
182 | print1(nbuf, res, NULL, NULL); | ||
183 | |||
184 | i++; | ||
185 | } while ((res = res->ai_next) != NULL); | ||
186 | |||
187 | exit(0); | ||
188 | } | ||
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..d09c9846cc --- /dev/null +++ b/src/regress/lib/libc/getcap/Makefile | |||
@@ -0,0 +1,10 @@ | |||
1 | # $OpenBSD: Makefile,v 1.1 2006/03/10 05:28:57 ray Exp $ | ||
2 | |||
3 | PROG= getcaptest | ||
4 | |||
5 | REGRESS_TARGETS=shortcap | ||
6 | |||
7 | shortcap: | ||
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..6b93edfc38 --- /dev/null +++ b/src/regress/lib/libc/glob/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | # $OpenBSD: Makefile,v 1.2 2009/02/18 15:17:55 millert Exp $ | ||
2 | |||
3 | PROG= globtest | ||
4 | |||
5 | run-regress-${PROG}: | ||
6 | mkdir -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u` | ||
7 | touch `cat ${.CURDIR}/files` | ||
8 | ./${PROG} ${.CURDIR}/${PROG}.in | ||
9 | |||
10 | clean: | ||
11 | rm -rf fake ${PROG} ${OBJS} *.core | ||
12 | |||
13 | .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..f8f93573c6 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* $OpenBSD: globtest.c,v 1.1 2008/10/01 23:04:36 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 | }; | ||
21 | |||
22 | int test_glob(struct gl_entry *); | ||
23 | |||
24 | int | ||
25 | main(int argc, char **argv) | ||
26 | { | ||
27 | FILE *fp = stdin; | ||
28 | char *buf, *cp, *want, *got, *last; | ||
29 | const char *errstr; | ||
30 | int errors = 0, i, lineno; | ||
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 | ||
44 | * result2 | ||
45 | * result3 | ||
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 > 0x2000) | ||
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 | entry.results[entry.nresults++] = strdup(buf); | ||
92 | } | ||
93 | if (entry.pattern[0]) | ||
94 | errors += test_glob(&entry); /* test last pattern */ | ||
95 | exit(errors); | ||
96 | } | ||
97 | |||
98 | int test_glob(struct gl_entry *entry) | ||
99 | { | ||
100 | glob_t gl; | ||
101 | int i; | ||
102 | |||
103 | if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) | ||
104 | errx(1, "glob failed: %s", entry->pattern); | ||
105 | |||
106 | if (gl.gl_matchc != entry->nresults) | ||
107 | goto mismatch; | ||
108 | |||
109 | for (i = 0; i < gl.gl_matchc; i++) { | ||
110 | if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0) | ||
111 | goto mismatch; | ||
112 | free(entry->results[i]); | ||
113 | } | ||
114 | return (0); | ||
115 | mismatch: | ||
116 | warnx("mismatch for pattern %s, flags 0x%x", entry->pattern, | ||
117 | entry->flags); | ||
118 | while (i < gl.gl_matchc) { | ||
119 | free(entry->results[i++]); | ||
120 | } | ||
121 | return (0); | ||
122 | return (1); | ||
123 | } | ||
diff --git a/src/regress/lib/libc/glob/globtest.in b/src/regress/lib/libc/glob/globtest.in new file mode 100644 index 0000000000..5995fa4b31 --- /dev/null +++ b/src/regress/lib/libc/glob/globtest.in | |||
@@ -0,0 +1,64 @@ | |||
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/rm{,dir,ail}] <0x80> | ||
50 | fake/bin/rm | ||
51 | fake/bin/rmdir | ||
52 | fake/bin/rmail | ||
53 | |||
54 | [fake/bin/sha[[:digit:]]] <0x0> | ||
55 | fake/bin/sha1 | ||
56 | |||
57 | [fake/bin/sha[[:digit:]]*] <0x0> | ||
58 | fake/bin/sha1 | ||
59 | fake/bin/sha256 | ||
60 | fake/bin/sha384 | ||
61 | fake/bin/sha512 | ||
62 | |||
63 | [fake/bin/ca[a-z]] <0x0> | ||
64 | fake/bin/cat | ||
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..2972b54794 --- /dev/null +++ b/src/regress/lib/libc/hsearch/hsearchtest.c | |||
@@ -0,0 +1,131 @@ | |||
1 | /* $OpenBSD: hsearchtest.c,v 1.1 2004/06/24 04:33:07 millert 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 | #ifndef lint | ||
43 | static const char copyright[] = | ||
44 | "@(#) Copyright (c) 2001 Christopher G. Demetriou. All rights reserved.\n"; | ||
45 | #endif /* not lint */ | ||
46 | |||
47 | #ifndef lint | ||
48 | static const char rcsid[] = "$OpenBSD: hsearchtest.c,v 1.1 2004/06/24 04:33:07 millert Exp $"; | ||
49 | #endif /* not lint */ | ||
50 | |||
51 | #include <search.h> | ||
52 | #include <stdlib.h> | ||
53 | #include <stdio.h> | ||
54 | #include <string.h> | ||
55 | |||
56 | #define TEST(e) ((e) ? (void)0 : testfail(__FILE__, __LINE__, #e)) | ||
57 | |||
58 | static void | ||
59 | testfail(const char *file, unsigned long line, const char *expression) | ||
60 | { | ||
61 | |||
62 | fprintf(stderr, "TEST FAILED: %s: file %s, line %ld\n", | ||
63 | expression, file, line); | ||
64 | exit(1); | ||
65 | } | ||
66 | |||
67 | int | ||
68 | main(int argc, char *argv[]) | ||
69 | { | ||
70 | ENTRY e, *ep, *ep2; | ||
71 | int created_ok; | ||
72 | char ch[2]; | ||
73 | int i; | ||
74 | |||
75 | created_ok = hcreate(16); | ||
76 | TEST(created_ok); | ||
77 | |||
78 | /* ch[1] should be constant from here on down. */ | ||
79 | ch[1] = '\0'; | ||
80 | |||
81 | /* Basic insertions. Check enough that there'll be collisions. */ | ||
82 | for (i = 0; i < 26; i++) { | ||
83 | ch[0] = 'a' + i; | ||
84 | e.key = strdup(ch); /* ptr to provided key is kept! */ | ||
85 | TEST(e.key != NULL); | ||
86 | e.data = (void *)(long)i; | ||
87 | ep = hsearch(e, ENTER); | ||
88 | TEST(ep != NULL); | ||
89 | TEST(strcmp(ep->key, ch) == 0); | ||
90 | TEST((long)ep->data == i); | ||
91 | } | ||
92 | |||
93 | /* e.key should be constant from here on down. */ | ||
94 | e.key = ch; | ||
95 | |||
96 | /* Basic lookups. */ | ||
97 | for (i = 0; i < 26; i++) { | ||
98 | ch[0] = 'a' + i; | ||
99 | ep = hsearch(e, FIND); | ||
100 | TEST(ep != NULL); | ||
101 | TEST(strcmp(ep->key, ch) == 0); | ||
102 | TEST((long)ep->data == i); | ||
103 | } | ||
104 | |||
105 | /* Check duplicate entry. Should _not_ overwrite existing data. */ | ||
106 | ch[0] = 'a'; | ||
107 | e.data = (void *)(long)12345; | ||
108 | ep = hsearch(e, FIND); | ||
109 | TEST(ep != NULL); | ||
110 | TEST(strcmp(ep->key, ch) == 0); | ||
111 | TEST((long)ep->data == 0); | ||
112 | |||
113 | /* Check for something that's not there. */ | ||
114 | ch[0] = 'A'; | ||
115 | ep = hsearch(e, FIND); | ||
116 | TEST(ep == NULL); | ||
117 | |||
118 | /* Check two at once. */ | ||
119 | ch[0] = 'a'; | ||
120 | ep = hsearch(e, FIND); | ||
121 | ch[0] = 'b'; | ||
122 | ep2 = hsearch(e, FIND); | ||
123 | TEST(ep != NULL); | ||
124 | TEST(strcmp(ep->key, "a") == 0 && (long)ep->data == 0); | ||
125 | TEST(ep2 != NULL); | ||
126 | TEST(strcmp(ep2->key, "b") == 0 && (long)ep2->data == 1); | ||
127 | |||
128 | hdestroy(); | ||
129 | |||
130 | exit(0); | ||
131 | } | ||
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..0f25cadefc 100644 --- a/src/regress/lib/libc/ieeefp/except/except.c +++ b/src/regress/lib/libc/ieeefp/except/except.c | |||
@@ -1,21 +1,47 @@ | |||
1 | /* $OpenBSD: except.c,v 1.11 2007/10/22 21:07:10 miod Exp $ */ | ||
2 | |||
3 | #include <sys/types.h> | ||
4 | #include <unistd.h> | ||
1 | #include <stdio.h> | 5 | #include <stdio.h> |
6 | #include <stdlib.h> | ||
2 | #include <signal.h> | 7 | #include <signal.h> |
3 | #include <assert.h> | 8 | #include <assert.h> |
4 | #include <ieeefp.h> | 9 | #include <ieeefp.h> |
5 | #include <float.h> | 10 | #include <float.h> |
11 | #include <err.h> | ||
6 | 12 | ||
7 | void sigfpe(); | 13 | volatile sig_atomic_t signal_status; |
8 | volatile sig_atomic_t signal_cought; | ||
9 | 14 | ||
10 | static volatile const double one = 1.0; | 15 | volatile const double one = 1.0; |
11 | static volatile const double zero = 0.0; | 16 | volatile const double zero = 0.0; |
12 | static volatile const double huge = DBL_MAX; | 17 | volatile const double huge = DBL_MAX; |
13 | static volatile const double tiny = DBL_MIN; | 18 | volatile const double tiny = DBL_MIN; |
14 | 19 | ||
15 | main() | 20 | void |
21 | sigfpe(int sig, siginfo_t *si, void *v) | ||
16 | { | 22 | { |
23 | char buf[132]; | ||
24 | |||
25 | if (si) { | ||
26 | snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n", | ||
27 | si->si_addr, si->si_code); | ||
28 | write(1, buf, strlen(buf)); | ||
29 | } | ||
30 | _exit(signal_status); | ||
31 | } | ||
32 | |||
33 | |||
34 | int | ||
35 | main(int argc, char *argv[]) | ||
36 | { | ||
37 | struct sigaction sa; | ||
17 | volatile double x; | 38 | volatile double x; |
18 | 39 | ||
40 | if (argc != 2) { | ||
41 | fprintf(stderr, "usage: %s condition\n", argv[0]); | ||
42 | exit(1); | ||
43 | } | ||
44 | |||
19 | /* | 45 | /* |
20 | * check to make sure that all exceptions are masked and | 46 | * check to make sure that all exceptions are masked and |
21 | * that the accumulated exception status is clear. | 47 | * that the accumulated exception status is clear. |
@@ -23,65 +49,61 @@ main() | |||
23 | assert(fpgetmask() == 0); | 49 | assert(fpgetmask() == 0); |
24 | assert(fpgetsticky() == 0); | 50 | assert(fpgetsticky() == 0); |
25 | 51 | ||
26 | /* set up signal handler */ | 52 | memset(&sa, 0, sizeof(sa)); |
27 | signal (SIGFPE, sigfpe); | 53 | sa.sa_sigaction = sigfpe; |
28 | signal_cought = 0; | 54 | sa.sa_flags = SA_SIGINFO; |
29 | 55 | sigaction(SIGFPE, &sa, NULL); | |
30 | /* trip divide by zero */ | 56 | 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 | 57 | ||
83 | void | 58 | if (strcmp(argv[1], "fltdiv") == 0) { |
84 | sigfpe() | 59 | /* trip divide by zero */ |
85 | { | 60 | x = one / zero; |
86 | signal_cought = 1; | 61 | assert(fpgetsticky() & FP_X_DZ); |
62 | fpsetsticky(0); | ||
63 | |||
64 | /* and now unmask to get a signal */ | ||
65 | signal_status = 0; | ||
66 | fpsetmask(FP_X_DZ); | ||
67 | x = one / zero; | ||
68 | } else if (strcmp(argv[1], "fltinv") == 0) { | ||
69 | /* trip invalid operation */ | ||
70 | x = zero / zero; | ||
71 | assert(fpgetsticky() & FP_X_INV); | ||
72 | fpsetsticky(0); | ||
73 | |||
74 | /* and now unmask to get a signal */ | ||
75 | signal_status = 0; | ||
76 | fpsetmask(FP_X_INV); | ||
77 | x = zero / zero; | ||
78 | } else if (strcmp(argv[1], "fltovf") == 0) { | ||
79 | /* trip overflow */ | ||
80 | x = huge * huge; | ||
81 | assert(fpgetsticky() & FP_X_OFL); | ||
82 | fpsetsticky(0); | ||
83 | |||
84 | /* and now unmask to get a signal */ | ||
85 | signal_status = 0; | ||
86 | fpsetmask(FP_X_OFL); | ||
87 | x = huge * huge; | ||
88 | } else if (strcmp(argv[1], "fltund") == 0) { | ||
89 | /* trip underflow */ | ||
90 | x = tiny * tiny; | ||
91 | assert(fpgetsticky() & FP_X_UFL); | ||
92 | fpsetsticky(0); | ||
93 | |||
94 | /* and now unmask to get a signal */ | ||
95 | signal_status = 0; | ||
96 | fpsetmask(FP_X_UFL); | ||
97 | x = tiny * tiny; | ||
98 | } else { | ||
99 | errx(1, "unrecognized condition %s", argv[1]); | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * attempt to trigger the exception on machines where | ||
104 | * floating-point exceptions are deferred. | ||
105 | */ | ||
106 | x = one * one; | ||
107 | |||
108 | errx(1, "signal wasn't caught"); | ||
87 | } | 109 | } |
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/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..0082c1bd1b --- /dev/null +++ b/src/regress/lib/libc/netdb/netdb.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* $OpenBSD: netdb.c,v 1.1 2004/10/25 15:10:36 otto 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 | |||
11 | int ret = 0; | ||
12 | |||
13 | void | ||
14 | checkp(int n, struct protoent *p, int proto, const char *name, ...) | ||
15 | { | ||
16 | va_list va; | ||
17 | char *a; | ||
18 | int i; | ||
19 | |||
20 | if (p == NULL) { | ||
21 | warnx("%d proto struct is NULL", n); | ||
22 | ret = 1; | ||
23 | return; | ||
24 | } | ||
25 | if (p->p_proto != proto) { | ||
26 | warnx("%d proto num mismatch %d %d", n, p->p_proto, proto); | ||
27 | ret = 1; | ||
28 | } | ||
29 | if (strcmp(p->p_name, name) != 0) { | ||
30 | warnx("%d proto name mismatch %s %s", n, p->p_name, name); | ||
31 | ret = 1; | ||
32 | } | ||
33 | va_start(va, name); | ||
34 | a = va_arg(va, char *); | ||
35 | i = 0; | ||
36 | while (a != NULL) { | ||
37 | if (strcmp(p->p_aliases[i], a) != 0) { | ||
38 | warnx("%d proto alias mismatch %s %s", n, | ||
39 | p->p_aliases[i], a); | ||
40 | ret = 1; | ||
41 | } | ||
42 | i++; | ||
43 | a = va_arg(va, char *); | ||
44 | } | ||
45 | if (p->p_aliases[i] != NULL) { | ||
46 | warnx("%d proto alias list does not end with NULL", n); | ||
47 | ret = 1; | ||
48 | } | ||
49 | va_end(va); | ||
50 | } | ||
51 | |||
52 | |||
53 | void | ||
54 | checks(int n, struct servent *s, int port, const char *proto, | ||
55 | const char *name, ...) | ||
56 | { | ||
57 | va_list va; | ||
58 | char *a; | ||
59 | int i; | ||
60 | |||
61 | if (s == NULL) { | ||
62 | warnx("%d serv struct is NULL", n); | ||
63 | ret = 1; | ||
64 | return; | ||
65 | } | ||
66 | if (s->s_port != ntohs(port)) { | ||
67 | warnx("%d port num mismatch %d %d", n, s->s_port, port); | ||
68 | ret = 1; | ||
69 | } | ||
70 | if (strcmp(s->s_name, name) != 0) { | ||
71 | warnx("%d serv name mismatch %s %s", n, s->s_name, name); | ||
72 | ret = 1; | ||
73 | } | ||
74 | if (strcmp(s->s_proto, proto) != 0) { | ||
75 | warnx("%d serv proto mismatch %s %s", n, s->s_proto, proto); | ||
76 | ret = 1; | ||
77 | } | ||
78 | va_start(va, name); | ||
79 | a = va_arg(va, char *); | ||
80 | i = 0; | ||
81 | while (a != NULL) { | ||
82 | if (strcmp(s->s_aliases[i], a) != 0) { | ||
83 | warnx("%d serv alias mismatch %s %s", n, | ||
84 | s->s_aliases[i], a); | ||
85 | ret = 1; | ||
86 | } | ||
87 | i++; | ||
88 | a = va_arg(va, char *); | ||
89 | } | ||
90 | if (s->s_aliases[i] != NULL) { | ||
91 | warnx("%d serv alias list does not end with NULL", n); | ||
92 | ret = 1; | ||
93 | } | ||
94 | va_end(va); | ||
95 | } | ||
96 | |||
97 | int | ||
98 | main() | ||
99 | { | ||
100 | struct protoent *p; | ||
101 | struct protoent protoent; | ||
102 | struct protoent_data protoent_data; | ||
103 | struct servent *s; | ||
104 | struct servent servent; | ||
105 | struct servent_data servent_data; | ||
106 | int r; | ||
107 | |||
108 | p = getprotobynumber(35); | ||
109 | checkp(1, p, 35, "idpr", "IDPR", (char *)NULL); | ||
110 | |||
111 | p = getprotobyname("igp"); | ||
112 | checkp(2, p, 9, "igp", "IGP", (char *) NULL); | ||
113 | |||
114 | p = getprotobyname("RDP"); | ||
115 | checkp(3, p, 27, "rdp", "RDP", (char *) NULL); | ||
116 | |||
117 | p = getprotobyname("vrrp"); | ||
118 | checkp(4, p, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
119 | |||
120 | p = getprotobyname("nonexistent"); | ||
121 | if (p != NULL) | ||
122 | err(1, "nonexistent proto found"); | ||
123 | |||
124 | memset(&protoent_data, 0, sizeof(protoent_data)); | ||
125 | r = getprotobynumber_r(35, &protoent, &protoent_data); | ||
126 | if (r != 0) | ||
127 | err(1, "proto not found"); | ||
128 | |||
129 | checkp(5, &protoent, 35, "idpr", "IDPR", (char *)NULL); | ||
130 | |||
131 | r = getprotobyname_r("vrrp", &protoent, &protoent_data); | ||
132 | if (r != 0) | ||
133 | err(1, "proto not found"); | ||
134 | checkp(6, &protoent, 112, "carp", "CARP", "vrrp", (char *) NULL); | ||
135 | |||
136 | r = getprotobyname_r("nonexistent", &protoent, &protoent_data); | ||
137 | if (r != -1) | ||
138 | err(1, "nonexistent proto found"); | ||
139 | |||
140 | r = getprotobyname_r("", &protoent, &protoent_data); | ||
141 | if (r != -1) | ||
142 | err(1, "nonexistent proto found"); | ||
143 | |||
144 | |||
145 | r = getprotobynumber_r(256, &protoent, &protoent_data); | ||
146 | if (r != -1) | ||
147 | err(1, "nonexistent proto found"); | ||
148 | |||
149 | s = getservbyname("zip", NULL); | ||
150 | checks(7, s, 6, "ddp", "zip", (char *)NULL); | ||
151 | |||
152 | s = getservbyname("nicname", "tcp"); | ||
153 | checks(8, s, 43, "tcp", "whois", "nicname", (char *)NULL); | ||
154 | |||
155 | s = getservbyport(htons(42), "tcp"); | ||
156 | checks(9, s, 42, "tcp", "nameserver", "name", (char *)NULL); | ||
157 | |||
158 | memset(&servent_data, 0, sizeof(servent_data)); | ||
159 | r = getservbyname_r("zip", "ddp", &servent, &servent_data); | ||
160 | if (r != 0) | ||
161 | err(1, "servent not found"); | ||
162 | checks(10, &servent, 6, "ddp", "zip", (char *)NULL); | ||
163 | |||
164 | r = getservbyport_r(htons(520), NULL, &servent, &servent_data); | ||
165 | if (r != 0) | ||
166 | err(1, "servent not found"); | ||
167 | checks(11, &servent, 520, "udp", "route", "router", "routed", (char *)NULL); | ||
168 | |||
169 | r = getservbyname_r("nonexistent", NULL, &servent, &servent_data); | ||
170 | if (r != -1) | ||
171 | err(1, "nonexiststent servent found"); | ||
172 | |||
173 | r = getservbyport_r(htons(50000), NULL, &servent, &servent_data); | ||
174 | if (r != -1) | ||
175 | err(1, "nonexistent servent found"); | ||
176 | |||
177 | r = getservbyport_r(htons(520), "tcp", &servent, &servent_data); | ||
178 | if (r != -1) | ||
179 | err(1, "nonexistent servent found"); | ||
180 | |||
181 | return ret; | ||
182 | } | ||
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/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/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..ee602a4b13 --- /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 | User defined signal 2 | ||
61 | Unknown signal: 32 | ||
62 | Unknown signal: 100 | ||
63 | Unknown signal: 2147483647 | ||
64 | Unknown signal: 2147483648 | ||
65 | Unknown signal: 4294967295 | ||
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..40e5d9f503 --- /dev/null +++ b/src/regress/lib/libc/vis/vis_test.c | |||
@@ -0,0 +1,23 @@ | |||
1 | /* $OpenBSD */ | ||
2 | |||
3 | /* Public domain. 2005, Otto Moerbeek */ | ||
4 | |||
5 | #include <limits.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <stdio.h> | ||
8 | #include <vis.h> | ||
9 | |||
10 | int | ||
11 | main() | ||
12 | { | ||
13 | char inp[UCHAR_MAX + 1]; | ||
14 | char out[4 * UCHAR_MAX + 1]; | ||
15 | int i; | ||
16 | |||
17 | for (i = 0; i <= UCHAR_MAX; i++) { | ||
18 | inp[i] = i; | ||
19 | } | ||
20 | strvisx(out, inp, UCHAR_MAX + 1, 0); | ||
21 | printf("%s\n", out); | ||
22 | exit(0); | ||
23 | } | ||