1*433d6423SLionel Sambuc /* test36: pathconf() fpathconf() Author: Jan-mark Wams */
2*433d6423SLionel Sambuc
3*433d6423SLionel Sambuc #include <sys/types.h>
4*433d6423SLionel Sambuc #include <sys/stat.h>
5*433d6423SLionel Sambuc #include <sys/wait.h>
6*433d6423SLionel Sambuc #include <stdlib.h>
7*433d6423SLionel Sambuc #include <unistd.h>
8*433d6423SLionel Sambuc #include <string.h>
9*433d6423SLionel Sambuc #include <fcntl.h>
10*433d6423SLionel Sambuc #include <limits.h>
11*433d6423SLionel Sambuc #include <errno.h>
12*433d6423SLionel Sambuc #include <time.h>
13*433d6423SLionel Sambuc #include <stdio.h>
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc int max_error = 4;
16*433d6423SLionel Sambuc #include "common.h"
17*433d6423SLionel Sambuc
18*433d6423SLionel Sambuc #define ITERATIONS 10
19*433d6423SLionel Sambuc
20*433d6423SLionel Sambuc #define System(cmd) if (system(cmd) != 0) printf("``%s'' failed\n", cmd)
21*433d6423SLionel Sambuc #define Chdir(dir) if (chdir(dir) != 0) printf("Can't goto %s\n", dir)
22*433d6423SLionel Sambuc #define Stat(a,b) if (stat(a,b) != 0) printf("Can't stat %s\n", a)
23*433d6423SLionel Sambuc
24*433d6423SLionel Sambuc
25*433d6423SLionel Sambuc int superuser;
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc void test36a(void);
28*433d6423SLionel Sambuc void test36b(void);
29*433d6423SLionel Sambuc void test36c(void);
30*433d6423SLionel Sambuc void test36d(void);
31*433d6423SLionel Sambuc int not_provided_option(int _option);
32*433d6423SLionel Sambuc int provided_option(int _option, int _minimum_value);
33*433d6423SLionel Sambuc int variating_option(int _option, int _minimum_value);
34*433d6423SLionel Sambuc
35*433d6423SLionel Sambuc char *testdirs[] = {
36*433d6423SLionel Sambuc "/",
37*433d6423SLionel Sambuc "/etc",
38*433d6423SLionel Sambuc "/tmp",
39*433d6423SLionel Sambuc "/usr",
40*433d6423SLionel Sambuc "/usr/bin",
41*433d6423SLionel Sambuc ".",
42*433d6423SLionel Sambuc NULL
43*433d6423SLionel Sambuc };
44*433d6423SLionel Sambuc
45*433d6423SLionel Sambuc char *testfiles[] = {
46*433d6423SLionel Sambuc "/",
47*433d6423SLionel Sambuc "/etc",
48*433d6423SLionel Sambuc "/etc/passwd",
49*433d6423SLionel Sambuc "/tmp",
50*433d6423SLionel Sambuc "/dev/tty",
51*433d6423SLionel Sambuc "/usr",
52*433d6423SLionel Sambuc "/usr/bin",
53*433d6423SLionel Sambuc ".",
54*433d6423SLionel Sambuc NULL
55*433d6423SLionel Sambuc };
56*433d6423SLionel Sambuc
main(int argc,char * argv[])57*433d6423SLionel Sambuc int main(int argc, char *argv[])
58*433d6423SLionel Sambuc {
59*433d6423SLionel Sambuc int i, m = 0xFFFF;
60*433d6423SLionel Sambuc
61*433d6423SLionel Sambuc sync();
62*433d6423SLionel Sambuc start(36);
63*433d6423SLionel Sambuc if (argc == 2) m = atoi(argv[1]);
64*433d6423SLionel Sambuc superuser = (geteuid() == 0);
65*433d6423SLionel Sambuc
66*433d6423SLionel Sambuc for (i = 0; i < ITERATIONS; i++) {
67*433d6423SLionel Sambuc if (m & 0001) test36a();
68*433d6423SLionel Sambuc if (m & 0002) test36b();
69*433d6423SLionel Sambuc if (m & 0004) test36c();
70*433d6423SLionel Sambuc if (m & 0010) test36d();
71*433d6423SLionel Sambuc }
72*433d6423SLionel Sambuc quit();
73*433d6423SLionel Sambuc return 1;
74*433d6423SLionel Sambuc }
75*433d6423SLionel Sambuc
test36a()76*433d6423SLionel Sambuc void test36a()
77*433d6423SLionel Sambuc { /* Test normal operation. */
78*433d6423SLionel Sambuc subtest = 1;
79*433d6423SLionel Sambuc System("rm -rf ../DIR_36/*");
80*433d6423SLionel Sambuc
81*433d6423SLionel Sambuc #ifdef _POSIX_CHOWN_RESTRICTED
82*433d6423SLionel Sambuc # if _POSIX_CHOWN_RESTRICTED - 0 == -1
83*433d6423SLionel Sambuc if (not_provided_option(_PC_CHOWN_RESTRICTED) != 0) e(1);
84*433d6423SLionel Sambuc # else
85*433d6423SLionel Sambuc if (provided_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(2);
86*433d6423SLionel Sambuc # endif
87*433d6423SLionel Sambuc #else
88*433d6423SLionel Sambuc if (variating_option(_PC_CHOWN_RESTRICTED, 0) != 0) e(3);
89*433d6423SLionel Sambuc #endif
90*433d6423SLionel Sambuc
91*433d6423SLionel Sambuc #ifdef _POSIX_NO_TRUNC
92*433d6423SLionel Sambuc # if _POSIX_NO_TRUNC - 0 == -1
93*433d6423SLionel Sambuc if (not_provided_option(_PC_NO_TRUNC) != 0) e(4);
94*433d6423SLionel Sambuc # else
95*433d6423SLionel Sambuc if (provided_option(_PC_NO_TRUNC, 0) != 0) e(5);
96*433d6423SLionel Sambuc # endif
97*433d6423SLionel Sambuc #else
98*433d6423SLionel Sambuc if (variating_option(_PC_NO_TRUNC, 0) != 0) e(6);
99*433d6423SLionel Sambuc #endif
100*433d6423SLionel Sambuc
101*433d6423SLionel Sambuc #ifdef _POSIX_VDISABLE
102*433d6423SLionel Sambuc {
103*433d6423SLionel Sambuc int _posix_vdisable = _POSIX_VDISABLE;
104*433d6423SLionel Sambuc if(_posix_vdisable == -1) {
105*433d6423SLionel Sambuc if (not_provided_option(_PC_VDISABLE) != 0) e(7);
106*433d6423SLionel Sambuc } else {
107*433d6423SLionel Sambuc if (provided_option(_PC_VDISABLE, 0) != 0) e(8);
108*433d6423SLionel Sambuc }
109*433d6423SLionel Sambuc }
110*433d6423SLionel Sambuc #else
111*433d6423SLionel Sambuc if (variating_option(_PC_VDISABLE, 0) != 0) e(9);
112*433d6423SLionel Sambuc #endif
113*433d6423SLionel Sambuc
114*433d6423SLionel Sambuc }
115*433d6423SLionel Sambuc
test36b()116*433d6423SLionel Sambuc void test36b()
117*433d6423SLionel Sambuc {
118*433d6423SLionel Sambuc subtest = 2;
119*433d6423SLionel Sambuc System("rm -rf ../DIR_36/*");
120*433d6423SLionel Sambuc }
121*433d6423SLionel Sambuc
test36c()122*433d6423SLionel Sambuc void test36c()
123*433d6423SLionel Sambuc {
124*433d6423SLionel Sambuc subtest = 3;
125*433d6423SLionel Sambuc System("rm -rf ../DIR_36/*");
126*433d6423SLionel Sambuc }
127*433d6423SLionel Sambuc
test36d()128*433d6423SLionel Sambuc void test36d()
129*433d6423SLionel Sambuc {
130*433d6423SLionel Sambuc subtest = 4;
131*433d6423SLionel Sambuc System("rm -rf ../DIR_36/*");
132*433d6423SLionel Sambuc }
133*433d6423SLionel Sambuc
not_provided_option(option)134*433d6423SLionel Sambuc int not_provided_option(option)
135*433d6423SLionel Sambuc int option;
136*433d6423SLionel Sambuc {
137*433d6423SLionel Sambuc char **p;
138*433d6423SLionel Sambuc
139*433d6423SLionel Sambuc for (p = testfiles; *p != (char *) NULL; p++) {
140*433d6423SLionel Sambuc if (pathconf(*p, option) != -1) return printf("*p == %s\n", *p), 1;
141*433d6423SLionel Sambuc }
142*433d6423SLionel Sambuc return 0;
143*433d6423SLionel Sambuc }
144*433d6423SLionel Sambuc
provided_option(option,minimum)145*433d6423SLionel Sambuc int provided_option(option, minimum)
146*433d6423SLionel Sambuc int option, minimum;
147*433d6423SLionel Sambuc {
148*433d6423SLionel Sambuc char **p;
149*433d6423SLionel Sambuc
150*433d6423SLionel Sambuc /* These three options are only defined on directorys. */
151*433d6423SLionel Sambuc if (option == _PC_NO_TRUNC
152*433d6423SLionel Sambuc || option == _PC_NAME_MAX
153*433d6423SLionel Sambuc || option == _PC_PATH_MAX)
154*433d6423SLionel Sambuc p = testdirs;
155*433d6423SLionel Sambuc else
156*433d6423SLionel Sambuc p = testfiles;
157*433d6423SLionel Sambuc
158*433d6423SLionel Sambuc for (; *p != NULL; p++) {
159*433d6423SLionel Sambuc if (pathconf(*p, option) < minimum)
160*433d6423SLionel Sambuc return printf("*p == %s\n", *p), 1;
161*433d6423SLionel Sambuc }
162*433d6423SLionel Sambuc return 0;
163*433d6423SLionel Sambuc }
164*433d6423SLionel Sambuc
variating_option(option,minimum)165*433d6423SLionel Sambuc int variating_option(option, minimum)
166*433d6423SLionel Sambuc int option, minimum;
167*433d6423SLionel Sambuc {
168*433d6423SLionel Sambuc char **p;
169*433d6423SLionel Sambuc
170*433d6423SLionel Sambuc /* These three options are only defined on directorys. */
171*433d6423SLionel Sambuc if (option == _PC_NO_TRUNC
172*433d6423SLionel Sambuc || option == _PC_NAME_MAX
173*433d6423SLionel Sambuc || option == _PC_PATH_MAX)
174*433d6423SLionel Sambuc p = testdirs;
175*433d6423SLionel Sambuc else
176*433d6423SLionel Sambuc p = testfiles;
177*433d6423SLionel Sambuc
178*433d6423SLionel Sambuc for (; *p != NULL; p++) {
179*433d6423SLionel Sambuc if (pathconf(*p, option) < minimum)
180*433d6423SLionel Sambuc return printf("*p == %s\n", *p), 1;
181*433d6423SLionel Sambuc }
182*433d6423SLionel Sambuc return 0;
183*433d6423SLionel Sambuc }
184