1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2008 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Common Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.opensource.org/licenses/cpl1.0.txt * 11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * Phong Vo <kpv@research.att.com> * 20 * * 21 ***********************************************************************/ 22 #pragma prototyped 23 /* 24 * Glenn Fowler 25 * AT&T Research 26 * 27 * generate POSIX fcntl.h 28 */ 29 30 #include <sys/types.h> 31 32 #include "FEATURE/lib" 33 34 #define getdtablesize ______getdtablesize 35 #define getpagesize ______getpagesize 36 #define ioctl ______ioctl 37 38 #if _typ_off64_t 39 #undef off_t 40 #ifdef __STDC__ 41 #define off_t off_t 42 #endif 43 #endif 44 45 #if _hdr_fcntl 46 #include <fcntl.h> 47 #endif 48 #if _hdr_unistd 49 #include <unistd.h> 50 #endif 51 52 #include <sys/stat.h> 53 54 #include "FEATURE/fs" 55 56 #undef getdtablesize 57 #undef getpagesize 58 #undef ioctl 59 60 #include "FEATURE/tty" 61 62 #if _typ_off64_t 63 #undef off_t 64 #define off_t off64_t 65 #endif 66 67 int 68 main() 69 { 70 int f_local = 0; 71 int f_lck = 0; 72 int o_local = 2; 73 74 printf("#pragma prototyped\n"); 75 printf("\n"); 76 printf("#if _typ_off64_t\n"); 77 printf("#undef off_t\n"); 78 printf("#ifdef __STDC__\n"); 79 printf("#define off_t off_t\n"); 80 printf("#endif\n"); 81 printf("#endif\n"); 82 printf("\n"); 83 printf("#include <ast_fs.h>\n"); 84 printf("\n"); 85 printf("#if _typ_off64_t\n"); 86 printf("#undef off_t\n"); 87 printf("#ifdef __STDC__\n"); 88 printf("#define off_t off_t\n"); 89 printf("#endif\n"); 90 printf("#endif\n"); 91 printf("\n"); 92 printf("#include <fcntl.h>\n"); 93 #if _hdr_mman 94 printf("#include <mman.h>\n"); 95 #else 96 #if _sys_mman 97 printf("#include <sys/mman.h>\n"); 98 #endif 99 #endif 100 printf("\n"); 101 #ifndef FD_CLOEXEC 102 printf("#define FD_CLOEXEC 1\n"); 103 printf("\n"); 104 #endif 105 106 #ifndef F_DUPFD 107 #define NEED_F 1 108 #else 109 if (F_DUPFD > f_local) f_local = F_DUPFD; 110 #endif 111 #ifndef F_GETFD 112 #define NEED_F 1 113 #else 114 if (F_GETFD > f_local) f_local = F_GETFD; 115 #endif 116 #ifndef F_GETFL 117 #define NEED_F 1 118 #else 119 if (F_GETFL > f_local) f_local = F_GETFL; 120 #endif 121 #ifndef F_GETLK 122 #define NEED_F 1 123 #else 124 if (F_GETLK > f_local) f_local = F_GETLK; 125 #endif 126 #ifndef F_RDLCK 127 #define NEED_F 1 128 #define NEED_LCK 1 129 #else 130 if (F_RDLCK > f_lck) f_lck = F_RDLCK; 131 #endif 132 #ifndef F_SETFD 133 #define NEED_F 1 134 #else 135 if (F_SETFD > f_local) f_local = F_SETFD; 136 #endif 137 #ifndef F_SETFL 138 #define NEED_F 1 139 #else 140 if (F_SETFL > f_local) f_local = F_SETFL; 141 #endif 142 #ifndef F_SETLK 143 #define NEED_F 1 144 #else 145 if (F_SETLK > f_local) f_local = F_SETLK; 146 #endif 147 #ifndef F_SETLKW 148 #define NEED_F 1 149 #else 150 if (F_SETLKW > f_local) f_local = F_SETLKW; 151 #endif 152 #ifndef F_UNLCK 153 #define NEED_F 1 154 #define NEED_LCK 1 155 #else 156 if (F_UNLCK > f_lck) f_lck = F_UNLCK; 157 #endif 158 #ifndef F_WRLCK 159 #define NEED_F 1 160 #define NEED_LCK 1 161 #else 162 if (F_WRLCK > f_lck) f_lck = F_WRLCK; 163 #endif 164 165 #if NEED_F 166 printf("#define fcntl _ast_fcntl\n"); 167 #if _lib_fcntl 168 printf("#define _lib_fcntl 1\n"); 169 #endif 170 printf("#define _ast_F_LOCAL %d\n", f_local + 1); 171 #ifndef F_DUPFD 172 printf("#define F_DUPFD %d\n", ++f_local); 173 #endif 174 #ifndef F_GETFD 175 printf("#define F_GETFD %d\n", ++f_local); 176 #endif 177 #ifndef F_GETFL 178 printf("#define F_GETFL %d\n", ++f_local); 179 #endif 180 #ifndef F_GETLK 181 printf("#define F_GETLK %d\n", ++f_local); 182 #endif 183 #ifndef F_SETFD 184 printf("#define F_SETFD %d\n", ++f_local); 185 #endif 186 #ifndef F_SETFL 187 printf("#define F_SETFL %d\n", ++f_local); 188 #endif 189 #ifndef F_SETLK 190 printf("#define F_SETLK %d\n", ++f_local); 191 #endif 192 #ifndef F_SETLKW 193 printf("#define F_SETLKW %d\n", ++f_local); 194 #endif 195 #if NEED_LCK 196 printf("\n"); 197 #ifndef F_RDLCK 198 printf("#define F_RDLCK %d\n", f_lck++); 199 #endif 200 #ifndef F_WRLCK 201 printf("#define F_WRLCK %d\n", f_lck++); 202 #endif 203 #ifndef F_UNLCK 204 printf("#define F_UNLCK %d\n", f_lck++); 205 #endif 206 #endif 207 printf("\n"); 208 if (f_lck == 3) 209 { 210 printf("struct flock\n"); 211 printf("{\n"); 212 printf(" short l_type;\n"); 213 printf(" short l_whence;\n"); 214 printf(" off_t l_start;\n"); 215 printf(" off_t l_len;\n"); 216 printf(" short l_pid;\n"); 217 printf("};\n"); 218 printf("\n"); 219 } 220 printf("\n"); 221 #endif 222 223 #ifndef O_APPEND 224 #define NEED_O 1 225 #else 226 if (O_APPEND > o_local) o_local = O_APPEND; 227 #endif 228 #ifndef O_CREAT 229 #define NEED_O 1 230 #else 231 if (O_CREAT > o_local) o_local = O_CREAT; 232 #endif 233 #ifndef O_EXCL 234 #define NEED_O 1 235 #else 236 if (O_EXCL > o_local) o_local = O_EXCL; 237 #endif 238 #ifndef O_NOCTTY 239 #ifdef TIOCNOTTY 240 #define NEED_O 1 241 #endif 242 #else 243 if (O_NOCTTY > o_local) o_local = O_NOCTTY; 244 #endif 245 #ifndef O_NONBLOCK 246 #ifndef O_NDELAY 247 #define NEED_O 1 248 #endif 249 #else 250 if (O_NONBLOCK > o_local) o_local = O_NONBLOCK; 251 #endif 252 #ifndef O_RDONLY 253 #define NEED_O 1 254 #endif 255 #ifndef O_RDWR 256 #define NEED_O 1 257 #endif 258 #ifndef O_TRUNC 259 #define NEED_O 1 260 #else 261 if (O_TRUNC > o_local) o_local = O_TRUNC; 262 #endif 263 #ifndef O_WRONLY 264 #define NEED_O 1 265 #endif 266 267 #if NEED_O 268 printf("#define open _ast_open\n"); 269 printf("#define _ast_O_LOCAL 0%o\n", o_local<<1); 270 #ifndef O_RDONLY 271 printf("#define O_RDONLY 0\n"); 272 #endif 273 #ifndef O_WRONLY 274 printf("#define O_WRONLY 1\n"); 275 #endif 276 #ifndef O_RDWR 277 printf("#define O_RDWR 2\n"); 278 #endif 279 #ifndef O_APPEND 280 printf("#define O_APPEND 0%o\n", o_local <<= 1); 281 #endif 282 #ifndef O_CREAT 283 printf("#define O_CREAT 0%o\n", o_local <<= 1); 284 #endif 285 #ifndef O_EXCL 286 printf("#define O_EXCL 0%o\n", o_local <<= 1); 287 #endif 288 #ifndef O_NOCTTY 289 #ifdef TIOCNOTTY 290 printf("#define O_NOCTTY 0%o\n", o_local <<= 1); 291 #endif 292 #endif 293 #ifndef O_NONBLOCK 294 #ifndef O_NDELAY 295 printf("#define O_NONBLOCK 0%o\n", o_local <<= 1); 296 #endif 297 #endif 298 #ifndef O_TRUNC 299 printf("#define O_TRUNC 0%o\n", o_local <<= 1); 300 #endif 301 #endif 302 #ifndef O_ACCMODE 303 printf("#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)\n"); 304 #endif 305 #ifndef O_NOCTTY 306 #ifndef TIOCNOTTY 307 printf("#define O_NOCTTY 0\n"); 308 #endif 309 #endif 310 #ifndef O_NONBLOCK 311 #ifdef O_NDELAY 312 printf("#define O_NONBLOCK O_NDELAY\n"); 313 #endif 314 #endif 315 #ifndef O_BINARY 316 printf("#define O_BINARY 0\n"); 317 #endif 318 #ifndef O_TEMPORARY 319 printf("#define O_TEMPORARY 0\n"); 320 #endif 321 #ifndef O_TEXT 322 printf("#define O_TEXT 0\n"); 323 #endif 324 #if NEED_F || NEED_O 325 printf("\n"); 326 #if NEED_F 327 printf("extern int fcntl(int, int, ...);\n"); 328 #endif 329 #if NEED_O 330 printf("extern int open(const char*, int, ...);\n"); 331 #endif 332 #endif 333 printf("\n"); 334 printf("#include <ast_fs.h>\n"); 335 printf("#if _typ_off64_t\n"); 336 printf("#undef off_t\n"); 337 printf("#define off_t off64_t\n"); 338 printf("#endif\n"); 339 printf("#if _lib_fstat64\n"); 340 printf("#define fstat fstat64\n"); 341 printf("#endif\n"); 342 printf("#if _lib_lstat64\n"); 343 printf("#define lstat lstat64\n"); 344 printf("#endif\n"); 345 printf("#if _lib_stat64\n"); 346 printf("#define stat stat64\n"); 347 printf("#endif\n"); 348 printf("#if _lib_creat64\n"); 349 printf("#define creat creat64\n"); 350 printf("#endif\n"); 351 printf("#if _lib_mmap64\n"); 352 printf("#define mmap mmap64\n"); 353 printf("#endif\n"); 354 printf("#if _lib_open64\n"); 355 printf("#undef open\n"); 356 printf("#define open open64\n"); 357 printf("#endif\n"); 358 359 return 0; 360 } 361