1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1985-2012 AT&T Intellectual Property * 5* and is licensed under the * 6* Eclipse Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.eclipse.org/org/documents/epl-v10.html * 11* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 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 67int 68main() 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#ifdef F_DUPFD_CLOEXEC 223 printf("#define F_dupfd_cloexec F_DUPFD_CLOEXEC\n"); 224#else 225 printf("#define F_dupfd_cloexec F_DUPFD\n"); 226#endif 227 228#ifndef O_APPEND 229#define NEED_O 1 230#else 231 if (O_APPEND > o_local) o_local = O_APPEND; 232#endif 233#ifndef O_CREAT 234#define NEED_O 1 235#else 236 if (O_CREAT > o_local) o_local = O_CREAT; 237#endif 238#ifndef O_EXCL 239#define NEED_O 1 240#else 241 if (O_EXCL > o_local) o_local = O_EXCL; 242#endif 243#ifndef O_NOCTTY 244#ifdef TIOCNOTTY 245#define NEED_O 1 246#endif 247#else 248 if (O_NOCTTY > o_local) o_local = O_NOCTTY; 249#endif 250#ifndef O_NONBLOCK 251#ifndef O_NDELAY 252#define NEED_O 1 253#endif 254#else 255 if (O_NONBLOCK > o_local) o_local = O_NONBLOCK; 256#endif 257#ifndef O_RDONLY 258#define NEED_O 1 259#endif 260#ifndef O_RDWR 261#define NEED_O 1 262#endif 263#ifndef O_TRUNC 264#define NEED_O 1 265#else 266 if (O_TRUNC > o_local) o_local = O_TRUNC; 267#endif 268#ifndef O_WRONLY 269#define NEED_O 1 270#endif 271 272#if NEED_O 273 printf("#define open _ast_open\n"); 274 printf("#define _ast_O_LOCAL 0%o\n", o_local<<1); 275#ifndef O_RDONLY 276 printf("#define O_RDONLY 0\n"); 277#endif 278#ifndef O_WRONLY 279 printf("#define O_WRONLY 1\n"); 280#endif 281#ifndef O_RDWR 282 printf("#define O_RDWR 2\n"); 283#endif 284#ifndef O_APPEND 285 printf("#define O_APPEND 0%o\n", o_local <<= 1); 286#endif 287#ifndef O_CREAT 288 printf("#define O_CREAT 0%o\n", o_local <<= 1); 289#endif 290#ifndef O_EXCL 291 printf("#define O_EXCL 0%o\n", o_local <<= 1); 292#endif 293#ifndef O_NOCTTY 294#ifdef TIOCNOTTY 295 printf("#define O_NOCTTY 0%o\n", o_local <<= 1); 296#endif 297#endif 298#ifndef O_NONBLOCK 299#ifndef O_NDELAY 300 printf("#define O_NONBLOCK 0%o\n", o_local <<= 1); 301#endif 302#endif 303#ifndef O_TRUNC 304 printf("#define O_TRUNC 0%o\n", o_local <<= 1); 305#endif 306#endif 307#ifndef O_ACCMODE 308 printf("#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)\n"); 309#endif 310#ifndef O_NOCTTY 311#ifndef TIOCNOTTY 312 printf("#define O_NOCTTY 0\n"); 313#endif 314#endif 315#ifndef O_NONBLOCK 316#ifdef O_NDELAY 317 printf("#define O_NONBLOCK O_NDELAY\n"); 318#endif 319#endif 320#ifndef O_BINARY 321 printf("#define O_BINARY 0\n"); 322#endif 323#ifdef O_CLOEXEC 324 printf("#define O_cloexec O_CLOEXEC\n"); 325#else 326 printf("#define O_cloexec 0\n"); 327#endif 328#ifndef O_TEMPORARY 329 printf("#define O_TEMPORARY 0\n"); 330#endif 331#ifndef O_TEXT 332 printf("#define O_TEXT 0\n"); 333#endif 334#if NEED_F || NEED_O 335 printf("\n"); 336#if NEED_F 337 printf("extern int fcntl(int, int, ...);\n"); 338#endif 339#if NEED_O 340 printf("extern int open(const char*, int, ...);\n"); 341#endif 342#endif 343 printf("\n"); 344 printf("#include <ast_fs.h>\n"); 345 printf("#if _typ_off64_t\n"); 346 printf("#undef off_t\n"); 347 printf("#define off_t off64_t\n"); 348 printf("#endif\n"); 349 printf("#if _lib_fstat64\n"); 350 printf("#define fstat fstat64\n"); 351 printf("#endif\n"); 352 printf("#if _lib_lstat64\n"); 353 printf("#define lstat lstat64\n"); 354 printf("#endif\n"); 355 printf("#if _lib_stat64\n"); 356 printf("#define stat stat64\n"); 357 printf("#endif\n"); 358 printf("#if _lib_creat64\n"); 359 printf("#define creat creat64\n"); 360 printf("#endif\n"); 361 printf("#if _lib_mmap64\n"); 362 printf("#define mmap mmap64\n"); 363 printf("#endif\n"); 364 printf("#if _lib_open64\n"); 365 printf("#undef open\n"); 366 printf("#define open open64\n"); 367 printf("#endif\n"); 368 369 return 0; 370} 371