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