summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/env
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/env
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/env')
-rw-r--r--src/regress/lib/libc/env/Makefile5
-rw-r--r--src/regress/lib/libc/env/envtest.c122
2 files changed, 0 insertions, 127 deletions
diff --git a/src/regress/lib/libc/env/Makefile b/src/regress/lib/libc/env/Makefile
deleted file mode 100644
index 92e04369f4..0000000000
--- a/src/regress/lib/libc/env/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1# $OpenBSD: Makefile,v 1.1 2010/08/23 22:34:37 millert Exp $
2
3PROG= envtest
4
5.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/env/envtest.c b/src/regress/lib/libc/env/envtest.c
deleted file mode 100644
index 79a5c0655f..0000000000
--- a/src/regress/lib/libc/env/envtest.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/* $OpenBSD: envtest.c,v 1.3 2021/09/01 09:26:32 jasper Exp $ */
2
3/*
4 * Copyright (c) 2010 Todd C. Miller <millert@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 <sys/types.h>
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25
26extern char **environ;
27
28static int
29count_instances(const char *name)
30{
31 int count = 0;
32 size_t namelen;
33 char **ep;
34
35 namelen = strlen(name);
36 for (ep = environ; *ep != NULL; ep++) {
37 if (strncmp(name, *ep, namelen) == 0 && (*ep)[namelen] == '=')
38 count++;
39 }
40
41 return count;
42}
43
44static void
45fake_env(void)
46{
47 static char *fakenv[7];
48
49 fakenv[0] = "HOME=/root";
50 fakenv[1] = "USER=root";
51 fakenv[2] = "LOGNAME=root";
52 fakenv[3] = "SHELL=/bin/sh";
53 fakenv[4] = "USER=root";
54 fakenv[5] = NULL;
55
56 environ = fakenv;
57}
58
59int
60main(int argc, char *argv[])
61{
62 char *buf;
63 int n, failures = 0;
64 size_t len, bufsize;
65
66 fake_env();
67 n = count_instances("USER");
68 if (n != 2) {
69 fprintf(stderr, "initial: %d instances of USER, expected %d\n",
70 n, 2);
71 failures++;
72 }
73
74 if (unsetenv("USER") != 0) {
75 fprintf(stderr, "unsetenv: failed to remove USER\n");
76 failures++;
77 }
78 n = count_instances("USER");
79 if (n != 0) {
80 fprintf(stderr, "unsetenv: %d instances of USER, expected %d\n",
81 n, 0);
82 failures++;
83 }
84
85 fake_env();
86 if (setenv("USER", "nobody", 0) != 0) {
87 fprintf(stderr, "setenv: failed to set USER\n");
88 failures++;
89 }
90 n = count_instances("USER");
91 if (n != 2) {
92 fprintf(stderr, "setenv: %d instances of USER, expected %d\n",
93 n, 2);
94 failures++;
95 }
96
97 fake_env();
98 if (setenv("USER", "nobody", 1) != 0) {
99 fprintf(stderr, "setenv: failed to set USER\n");
100 failures++;
101 }
102 n = count_instances("USER");
103 if (n != 1) {
104 fprintf(stderr, "setenv: %d instances of USER, expected %d\n",
105 n, 1);
106 failures++;
107 }
108
109 fake_env();
110 if (putenv("USER=nobody") != 0) {
111 fprintf(stderr, "putenv: failed to set USER\n");
112 failures++;
113 }
114 n = count_instances("USER");
115 if (n != 1) {
116 fprintf(stderr, "putenv: %d instances of USER, expected %d\n",
117 n, 1);
118 failures++;
119 }
120
121 return failures;
122}