retire nonsymbolic rootdev, dev2name
[minix.git] / test / test36.c
blob1e668da244356446ec8cc2dd47db9f9b616e68c8
1 /* test36: pathconf() fpathconf() Author: Jan-mark Wams */
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>
15 #define MAX_ERROR 4
16 #define ITERATIONS 10
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)
22 #include "common.c"
24 int superuser;
26 void test36a(void);
27 void test36b(void);
28 void test36c(void);
29 void test36d(void);
30 int not_provided_option(int _option);
31 int provided_option(int _option, int _minimum_value);
32 int variating_option(int _option, int _minimum_value);
34 char *testdirs[] = {
35 "/",
36 "/etc",
37 "/tmp",
38 "/usr",
39 "/usr/bin",
40 ".",
41 NULL
44 char *testfiles[] = {
45 "/",
46 "/etc",
47 "/etc/passwd",
48 "/tmp",
49 "/dev/tty",
50 "/usr",
51 "/usr/bin",
52 ".",
53 NULL
56 int main(int argc, char *argv[])
58 int i, m = 0xFFFF;
60 sync();
61 start(36);
62 if (argc == 2) m = atoi(argv[1]);
63 superuser = (geteuid() == 0);
65 for (i = 0; i < ITERATIONS; i++) {
66 if (m & 0001) test36a();
67 if (m & 0002) test36b();
68 if (m & 0004) test36c();
69 if (m & 0010) test36d();
71 quit();
72 return 1;
75 void test36a()
76 { /* Test normal operation. */
77 subtest = 1;
78 System("rm -rf ../DIR_36/*");
80 #ifdef _POSIX_CHOWN_RESTRICTED
81 # if _POSIX_CHOWN_RESTRICTED - 0 == -1
82 if (not_provided_option(_PC_CHOWN_RESTRICTED) != 0) e(1);
83 # else
84 if (provided_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(2);
85 # endif
86 #else
87 if (variating_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(3);
88 #endif
90 #ifdef _POSIX_NO_TRUNC
91 # if _POSIX_NO_TRUNC - 0 == -1
92 if (not_provided_option(_PC_NO_TRUNC) != 0) e(4);
93 # else
94 if (provided_option(_PC_NO_TRUNC, 0) != 0) e(5);
95 # endif
96 #else
97 if (variating_option(_PC_NO_TRUNC, 0) != 0) e(6);
98 #endif
100 #ifdef _POSIX_VDISABLE
102 int _posix_vdisable = _POSIX_VDISABLE;
103 if(_posix_vdisable == -1) {
104 if (not_provided_option(_PC_VDISABLE) != 0) e(7);
105 } else {
106 if (provided_option(_PC_VDISABLE, 0) != 0) e(8);
109 #else
110 if (variating_option(_PC_VDISABLE, 0) != 0) e(9);
111 #endif
115 void test36b()
117 subtest = 2;
118 System("rm -rf ../DIR_36/*");
121 void test36c()
123 subtest = 3;
124 System("rm -rf ../DIR_36/*");
127 void test36d()
129 subtest = 4;
130 System("rm -rf ../DIR_36/*");
133 int not_provided_option(option)
134 int option;
136 char **p;
138 for (p = testfiles; *p != (char *) NULL; p++) {
139 if (pathconf(*p, option) != -1) return printf("*p == %s\n", *p), 1;
141 return 0;
144 int provided_option(option, minimum)
145 int option, minimum;
147 char **p;
149 /* These three options are only defined on directorys. */
150 if (option == _PC_NO_TRUNC
151 || option == _PC_NAME_MAX
152 || option == _PC_PATH_MAX)
153 p = testdirs;
154 else
155 p = testfiles;
157 for (; *p != NULL; p++) {
158 if (pathconf(*p, option) < minimum)
159 return printf("*p == %s\n", *p), 1;
161 return 0;
164 int variating_option(option, minimum)
165 int option, minimum;
167 char **p;
169 /* These three options are only defined on directorys. */
170 if (option == _PC_NO_TRUNC
171 || option == _PC_NAME_MAX
172 || option == _PC_PATH_MAX)
173 p = testdirs;
174 else
175 p = testfiles;
177 for (; *p != NULL; p++) {
178 if (pathconf(*p, option) < minimum)
179 return printf("*p == %s\n", *p), 1;
181 return 0;