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