1 | /* test36: pathconf() fpathconf() Author: Jan-mark Wams */
|
---|
2 |
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <sys/stat.h>
|
---|
5 | #include <sys/wait.h>
|
---|
6 | #include <stdlib.h>
|
---|
7 | #include <unistd.h>
|
---|
8 | #include <string.h>
|
---|
9 | #include <fcntl.h>
|
---|
10 | #include <limits.h>
|
---|
11 | #include <errno.h>
|
---|
12 | #include <time.h>
|
---|
13 | #include <stdio.h>
|
---|
14 |
|
---|
15 | #define MAX_ERROR 4
|
---|
16 | #define ITERATIONS 10
|
---|
17 |
|
---|
18 | #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd)
|
---|
19 | #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir)
|
---|
20 | #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a)
|
---|
21 |
|
---|
22 | int errct = 0;
|
---|
23 | int subtest = 1;
|
---|
24 | int superuser;
|
---|
25 | char MaxName[NAME_MAX + 1]; /* Name of maximum length */
|
---|
26 | char MaxPath[PATH_MAX]; /* Same for path */
|
---|
27 | char ToLongName[NAME_MAX + 2]; /* Name of maximum +1 length */
|
---|
28 | char ToLongPath[PATH_MAX + 1]; /* Same for path, both too long */
|
---|
29 |
|
---|
30 | _PROTOTYPE(void main, (int argc, char *argv[]));
|
---|
31 | _PROTOTYPE(void test36a, (void));
|
---|
32 | _PROTOTYPE(void test36b, (void));
|
---|
33 | _PROTOTYPE(void test36c, (void));
|
---|
34 | _PROTOTYPE(void test36d, (void));
|
---|
35 | _PROTOTYPE(void makelongnames, (void));
|
---|
36 | _PROTOTYPE(void e, (int number));
|
---|
37 | _PROTOTYPE(void quit, (void));
|
---|
38 | _PROTOTYPE(int not_provided_option, (int _option));
|
---|
39 | _PROTOTYPE(int provided_option, (int _option, int _minimum_value));
|
---|
40 | _PROTOTYPE(int variating_option, (int _option, int _minimum_value));
|
---|
41 |
|
---|
42 | char *testdirs[] = {
|
---|
43 | "/",
|
---|
44 | "/etc",
|
---|
45 | "/tmp",
|
---|
46 | "/usr",
|
---|
47 | "/usr/bin",
|
---|
48 | ".",
|
---|
49 | NULL
|
---|
50 | };
|
---|
51 |
|
---|
52 | char *testfiles[] = {
|
---|
53 | "/",
|
---|
54 | "/etc",
|
---|
55 | "/etc/passwd",
|
---|
56 | "/tmp",
|
---|
57 | "/dev/tty",
|
---|
58 | "/usr",
|
---|
59 | "/usr/bin",
|
---|
60 | ".",
|
---|
61 | NULL
|
---|
62 | };
|
---|
63 |
|
---|
64 | void main(argc, argv)
|
---|
65 | int argc;
|
---|
66 | char *argv[];
|
---|
67 | {
|
---|
68 | int i, m = 0xFFFF;
|
---|
69 |
|
---|
70 | sync();
|
---|
71 | if (argc == 2) m = atoi(argv[1]);
|
---|
72 | printf("Test 36 ");
|
---|
73 | fflush(stdout);
|
---|
74 | System("rm -rf DIR_36; mkdir DIR_36");
|
---|
75 | Chdir("DIR_36");
|
---|
76 | makelongnames();
|
---|
77 | superuser = (geteuid() == 0);
|
---|
78 |
|
---|
79 | for (i = 0; i < ITERATIONS; i++) {
|
---|
80 | if (m & 0001) test36a();
|
---|
81 | if (m & 0002) test36b();
|
---|
82 | if (m & 0004) test36c();
|
---|
83 | if (m & 0010) test36d();
|
---|
84 | }
|
---|
85 | quit();
|
---|
86 | }
|
---|
87 |
|
---|
88 | void test36a()
|
---|
89 | { /* Test normal operation. */
|
---|
90 | subtest = 1;
|
---|
91 | System("rm -rf ../DIR_36/*");
|
---|
92 |
|
---|
93 | #ifdef _POSIX_CHOWN_RESTRICTED
|
---|
94 | # if _POSIX_CHOWN_RESTRICTED - 0 == -1
|
---|
95 | if (not_provided_option(_PC_CHOWN_RESTRICTED) != 0) e(1);
|
---|
96 | # else
|
---|
97 | if (provided_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(2);
|
---|
98 | # endif
|
---|
99 | #else
|
---|
100 | if (variating_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(3);
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | #ifdef _POSIX_NO_TRUNC
|
---|
104 | # if _POSIX_NO_TRUNC - 0 == -1
|
---|
105 | if (not_provided_option(_PC_NO_TRUNC) != 0) e(4);
|
---|
106 | # else
|
---|
107 | if (provided_option(_PC_NO_TRUNC, 0) != 0) e(5);
|
---|
108 | # endif
|
---|
109 | #else
|
---|
110 | if (variating_option(_PC_NO_TRUNC, 0) != 0) e(6);
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | #ifdef _POSIX_VDISABLE
|
---|
114 | # if _POSIX_VDISABLE - 0 == -1
|
---|
115 | if (not_provided_option(_PC_VDISABLE) != 0) e(7);
|
---|
116 | # else
|
---|
117 | if (provided_option(_PC_VDISABLE, 0) != 0) e(8);
|
---|
118 | # endif
|
---|
119 | #else
|
---|
120 | if (variating_option(_PC_VDISABLE, 0) != 0) e(9);
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | }
|
---|
124 |
|
---|
125 | void test36b()
|
---|
126 | {
|
---|
127 | subtest = 2;
|
---|
128 | System("rm -rf ../DIR_36/*");
|
---|
129 | }
|
---|
130 |
|
---|
131 | void test36c()
|
---|
132 | {
|
---|
133 | subtest = 3;
|
---|
134 | System("rm -rf ../DIR_36/*");
|
---|
135 | }
|
---|
136 |
|
---|
137 | void test36d()
|
---|
138 | {
|
---|
139 | subtest = 4;
|
---|
140 | System("rm -rf ../DIR_36/*");
|
---|
141 | }
|
---|
142 |
|
---|
143 | void makelongnames()
|
---|
144 | {
|
---|
145 | register int i;
|
---|
146 |
|
---|
147 | memset(MaxName, 'a', NAME_MAX);
|
---|
148 | MaxName[NAME_MAX] = '\0';
|
---|
149 | for (i = 0; i < PATH_MAX - 1; i++) { /* idem path */
|
---|
150 | MaxPath[i++] = '.';
|
---|
151 | MaxPath[i] = '/';
|
---|
152 | }
|
---|
153 | MaxPath[PATH_MAX - 1] = '\0';
|
---|
154 |
|
---|
155 | strcpy(ToLongName, MaxName); /* copy them Max to ToLong */
|
---|
156 | strcpy(ToLongPath, MaxPath);
|
---|
157 |
|
---|
158 | ToLongName[NAME_MAX] = 'a';
|
---|
159 | ToLongName[NAME_MAX + 1] = '\0'; /* extend ToLongName by one too many */
|
---|
160 | ToLongPath[PATH_MAX - 1] = '/';
|
---|
161 | ToLongPath[PATH_MAX] = '\0'; /* inc ToLongPath by one */
|
---|
162 | }
|
---|
163 |
|
---|
164 | void e(n)
|
---|
165 | int n;
|
---|
166 | {
|
---|
167 | int err_num = errno; /* Save in case printf clobbers it. */
|
---|
168 |
|
---|
169 | printf("Subtest %d, error %d errno=%d: ", subtest, n, errno);
|
---|
170 | errno = err_num;
|
---|
171 | perror("");
|
---|
172 | if (errct++ > MAX_ERROR) {
|
---|
173 | printf("Too many errors; test aborted\n");
|
---|
174 | chdir("..");
|
---|
175 | system("rm -rf DIR*");
|
---|
176 | exit(1);
|
---|
177 | }
|
---|
178 | errno = 0;
|
---|
179 | }
|
---|
180 |
|
---|
181 | void quit()
|
---|
182 | {
|
---|
183 | Chdir("..");
|
---|
184 | System("rm -rf DIR_36");
|
---|
185 |
|
---|
186 | if (errct == 0) {
|
---|
187 | printf("ok\n");
|
---|
188 | exit(0);
|
---|
189 | } else {
|
---|
190 | printf("%d errors\n", errct);
|
---|
191 | exit(1);
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | int not_provided_option(option)
|
---|
196 | int option;
|
---|
197 | {
|
---|
198 | char **p;
|
---|
199 |
|
---|
200 | for (p = testfiles; *p != (char *) NULL; p++) {
|
---|
201 | if (pathconf(*p, option) != -1) return printf("*p == %s\n", *p), 1;
|
---|
202 | }
|
---|
203 | return 0;
|
---|
204 | }
|
---|
205 |
|
---|
206 | int provided_option(option, minimum)
|
---|
207 | int option, minimum;
|
---|
208 | {
|
---|
209 | char **p;
|
---|
210 |
|
---|
211 | /* These three options are only defined on directorys. */
|
---|
212 | if (option == _PC_NO_TRUNC
|
---|
213 | || option == _PC_NAME_MAX
|
---|
214 | || option == _PC_PATH_MAX)
|
---|
215 | p = testdirs;
|
---|
216 | else
|
---|
217 | p = testfiles;
|
---|
218 |
|
---|
219 | for (; *p != NULL; p++) {
|
---|
220 | if (pathconf(*p, option) < minimum)
|
---|
221 | return printf("*p == %s\n", *p), 1;
|
---|
222 | }
|
---|
223 | return 0;
|
---|
224 | }
|
---|
225 |
|
---|
226 | int variating_option(option, minimum)
|
---|
227 | int option, minimum;
|
---|
228 | {
|
---|
229 | char **p;
|
---|
230 |
|
---|
231 | /* These three options are only defined on directorys. */
|
---|
232 | if (option == _PC_NO_TRUNC
|
---|
233 | || option == _PC_NAME_MAX
|
---|
234 | || option == _PC_PATH_MAX)
|
---|
235 | p = testdirs;
|
---|
236 | else
|
---|
237 | p = testfiles;
|
---|
238 |
|
---|
239 | for (; *p != NULL; p++) {
|
---|
240 | if (pathconf(*p, option) < minimum)
|
---|
241 | return printf("*p == %s\n", *p), 1;
|
---|
242 | }
|
---|
243 | return 0;
|
---|
244 | }
|
---|