1 /* test36: pathconf() fpathconf() Author: Jan-mark Wams */
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)
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 */
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
));
71 if (argc
== 2) m
= atoi(argv
[1]);
74 System("rm -rf DIR_36; mkdir DIR_36");
77 superuser
= (geteuid() == 0);
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();
89 { /* Test normal operation. */
91 System("rm -rf ../DIR_36/*");
93 #ifdef _POSIX_CHOWN_RESTRICTED
94 # if _POSIX_CHOWN_RESTRICTED - 0 == -1
95 if (not_provided_option(_PC_CHOWN_RESTRICTED
) != 0) e(1);
97 if (provided_option(_PC_CHOWN_RESTRICTED
, 0) != 0) e(2);
100 if (variating_option(_PC_CHOWN_RESTRICTED
, 0) != 0) e(3);
103 #ifdef _POSIX_NO_TRUNC
104 # if _POSIX_NO_TRUNC - 0 == -1
105 if (not_provided_option(_PC_NO_TRUNC
) != 0) e(4);
107 if (provided_option(_PC_NO_TRUNC
, 0) != 0) e(5);
110 if (variating_option(_PC_NO_TRUNC
, 0) != 0) e(6);
113 #ifdef _POSIX_VDISABLE
114 # if _POSIX_VDISABLE - 0 == -1
115 if (not_provided_option(_PC_VDISABLE
) != 0) e(7);
117 if (provided_option(_PC_VDISABLE
, 0) != 0) e(8);
120 if (variating_option(_PC_VDISABLE
, 0) != 0) e(9);
128 System("rm -rf ../DIR_36/*");
134 System("rm -rf ../DIR_36/*");
140 System("rm -rf ../DIR_36/*");
147 memset(MaxName
, 'a', NAME_MAX
);
148 MaxName
[NAME_MAX
] = '\0';
149 for (i
= 0; i
< PATH_MAX
- 1; i
++) { /* idem path */
153 MaxPath
[PATH_MAX
- 1] = '\0';
155 strcpy(ToLongName
, MaxName
); /* copy them Max to ToLong */
156 strcpy(ToLongPath
, MaxPath
);
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 */
167 int err_num
= errno
; /* Save in case printf clobbers it. */
169 printf("Subtest %d, error %d errno=%d: ", subtest
, n
, errno
);
172 if (errct
++ > MAX_ERROR
) {
173 printf("Too many errors; test aborted\n");
175 system("rm -rf DIR*");
184 System("rm -rf DIR_36");
190 printf("%d errors\n", errct
);
195 int not_provided_option(option
)
200 for (p
= testfiles
; *p
!= (char *) NULL
; p
++) {
201 if (pathconf(*p
, option
) != -1) return printf("*p == %s\n", *p
), 1;
206 int provided_option(option
, minimum
)
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
)
219 for (; *p
!= NULL
; p
++) {
220 if (pathconf(*p
, option
) < minimum
)
221 return printf("*p == %s\n", *p
), 1;
226 int variating_option(option
, minimum
)
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
)
239 for (; *p
!= NULL
; p
++) {
240 if (pathconf(*p
, option
) < minimum
)
241 return printf("*p == %s\n", *p
), 1;