change#3612 was buggy and failed to build Tk; applied Ilya's
[p5sagit/p5-mst-13.2.git] / ext / Fcntl / Fcntl.xs
CommitLineData
a0d0e21e 1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
75ced34b 5#ifdef VMS
6# include <file.h>
7#else
cd661bb6 8#if defined(__GNUC__) && defined(__cplusplus) && defined(WIN32)
9#define _NO_OLDNAMES
10#endif
75ced34b 11# include <fcntl.h>
cd661bb6 12#if defined(__GNUC__) && defined(__cplusplus) && defined(WIN32)
13#undef _NO_OLDNAMES
14#endif
75ced34b 15#endif
a0d0e21e 16
8e07c86e 17/* This comment is a kludge to get metaconfig to see the symbols
18 VAL_O_NONBLOCK
19 VAL_EAGAIN
20 RD_NODATA
21 EOF_NONBLOCK
22 and include the appropriate metaconfig unit
23 so that Configure will test how to turn on non-blocking I/O
24 for a file descriptor. See config.h for how to use these
25 in your extension.
26
27 While I'm at it, I'll have metaconfig look for HAS_POLL too.
28 --AD October 16, 1995
29*/
30
a0d0e21e 31static int
f0f333f4 32not_here(char *s)
a0d0e21e 33{
34 croak("%s not implemented on this architecture", s);
35 return -1;
36}
37
38static double
f0f333f4 39constant(char *name, int arg)
a0d0e21e 40{
41 errno = 0;
42 switch (*name) {
43 case 'F':
44 if (strnEQ(name, "F_", 2)) {
45 if (strEQ(name, "F_DUPFD"))
46#ifdef F_DUPFD
47 return F_DUPFD;
48#else
49 goto not_there;
50#endif
0fd60c2a 51 if (strEQ(name, "F_EXLCK"))
52#ifdef F_EXLCK
53 return F_EXLCK;
54#else
55 goto not_there;
56#endif
a0d0e21e 57 if (strEQ(name, "F_GETFD"))
58#ifdef F_GETFD
59 return F_GETFD;
60#else
61 goto not_there;
62#endif
0fd60c2a 63 if (strEQ(name, "F_GETFL"))
64#ifdef F_GETFL
65 return F_GETFL;
66#else
67 goto not_there;
68#endif
a0d0e21e 69 if (strEQ(name, "F_GETLK"))
70#ifdef F_GETLK
71 return F_GETLK;
72#else
73 goto not_there;
74#endif
5ff3f7a4 75 if (strEQ(name, "F_GETLK64"))
76#ifdef F_GETLK64
77 return F_GETLK64;
78#else
79 goto not_there;
80#endif
5f832ef3 81 if (strEQ(name, "F_GETOWN"))
82#ifdef F_GETOWN
83 return F_GETOWN;
84#else
85 goto not_there;
86#endif
0fd60c2a 87 if (strEQ(name, "F_POSIX"))
88#ifdef F_POSIX
89 return F_POSIX;
a0d0e21e 90#else
91 goto not_there;
92#endif
0fd60c2a 93 if (strEQ(name, "F_RDLCK"))
94#ifdef F_RDLCK
95 return F_RDLCK;
a0d0e21e 96#else
97 goto not_there;
98#endif
0fd60c2a 99 if (strEQ(name, "F_SETFD"))
100#ifdef F_SETFD
101 return F_SETFD;
3e3baf6d 102#else
103 goto not_there;
104#endif
232e078e 105 if (strEQ(name, "F_SETFL"))
106#ifdef F_SETFL
107 return F_SETFL;
a0d0e21e 108#else
109 goto not_there;
110#endif
d9fde92e 111 if (strEQ(name, "F_SETLK"))
112#ifdef F_SETLK
113 return F_SETLK;
114#else
115 goto not_there;
116#endif
5ff3f7a4 117 if (strEQ(name, "F_SETLK64"))
118#ifdef F_SETLK64
119 return F_SETLK64;
a0d0e21e 120#else
121 goto not_there;
122#endif
123 if (strEQ(name, "F_SETLKW"))
124#ifdef F_SETLKW
125 return F_SETLKW;
126#else
127 goto not_there;
128#endif
5ff3f7a4 129 if (strEQ(name, "F_SETLKW64"))
130#ifdef F_SETLKW64
131 return F_SETLKW64;
132#else
133 goto not_there;
134#endif
5f832ef3 135 if (strEQ(name, "F_SETOWN"))
136#ifdef F_SETOWN
137 return F_SETOWN;
138#else
139 goto not_there;
140#endif
0fd60c2a 141 if (strEQ(name, "F_SHLCK"))
142#ifdef F_SHLCK
143 return F_SHLCK;
a0d0e21e 144#else
145 goto not_there;
146#endif
147 if (strEQ(name, "F_UNLCK"))
148#ifdef F_UNLCK
149 return F_UNLCK;
150#else
151 goto not_there;
152#endif
153 if (strEQ(name, "F_WRLCK"))
154#ifdef F_WRLCK
155 return F_WRLCK;
156#else
157 goto not_there;
158#endif
159 errno = EINVAL;
160 return 0;
3e3baf6d 161 }
162 if (strEQ(name, "FAPPEND"))
163#ifdef FAPPEND
164 return FAPPEND;
165#else
166 goto not_there;
167#endif
168 if (strEQ(name, "FASYNC"))
169#ifdef FASYNC
170 return FASYNC;
171#else
172 goto not_there;
173#endif
174 if (strEQ(name, "FCREAT"))
175#ifdef FCREAT
176 return FCREAT;
177#else
178 goto not_there;
179#endif
180 if (strEQ(name, "FD_CLOEXEC"))
a0d0e21e 181#ifdef FD_CLOEXEC
182 return FD_CLOEXEC;
183#else
184 goto not_there;
185#endif
0fd60c2a 186 if (strEQ(name, "FDEFER"))
187#ifdef FDEFER
188 return FDEFER;
189#else
190 goto not_there;
191#endif
3e3baf6d 192 if (strEQ(name, "FEXCL"))
193#ifdef FEXCL
194 return FEXCL;
195#else
196 goto not_there;
197#endif
198 if (strEQ(name, "FNDELAY"))
199#ifdef FNDELAY
200 return FNDELAY;
201#else
202 goto not_there;
203#endif
204 if (strEQ(name, "FNONBLOCK"))
205#ifdef FNONBLOCK
206 return FNONBLOCK;
207#else
208 goto not_there;
209#endif
210 if (strEQ(name, "FSYNC"))
211#ifdef FSYNC
212 return FSYNC;
213#else
214 goto not_there;
215#endif
216 if (strEQ(name, "FTRUNC"))
217#ifdef FTRUNC
218 return FTRUNC;
219#else
220 goto not_there;
221#endif
a0d0e21e 222 break;
7e1af8bc 223 case 'L':
224 if (strnEQ(name, "LOCK_", 5)) {
225 /* We support flock() on systems which don't have it, so
226 always supply the constants. */
227 if (strEQ(name, "LOCK_SH"))
228#ifdef LOCK_SH
229 return LOCK_SH;
230#else
231 return 1;
232#endif
233 if (strEQ(name, "LOCK_EX"))
234#ifdef LOCK_EX
235 return LOCK_EX;
236#else
237 return 2;
238#endif
239 if (strEQ(name, "LOCK_NB"))
240#ifdef LOCK_NB
241 return LOCK_NB;
242#else
243 return 4;
244#endif
245 if (strEQ(name, "LOCK_UN"))
246#ifdef LOCK_UN
247 return LOCK_UN;
248#else
249 return 8;
250#endif
251 } else
252 goto not_there;
253 break;
a0d0e21e 254 case 'O':
255 if (strnEQ(name, "O_", 2)) {
0fd60c2a 256 if (strEQ(name, "O_ACCMODE"))
257#ifdef O_ACCMODE
258 return O_ACCMODE;
259#else
260 goto not_there;
261#endif
262 if (strEQ(name, "O_APPEND"))
263#ifdef O_APPEND
264 return O_APPEND;
265#else
266 goto not_there;
267#endif
268 if (strEQ(name, "O_ASYNC"))
269#ifdef O_ASYNC
270 return O_ASYNC;
271#else
272 goto not_there;
273#endif
274 if (strEQ(name, "O_BINARY"))
275#ifdef O_BINARY
276 return O_BINARY;
277#else
278 goto not_there;
279#endif
a0d0e21e 280 if (strEQ(name, "O_CREAT"))
281#ifdef O_CREAT
282 return O_CREAT;
283#else
284 goto not_there;
285#endif
0fd60c2a 286 if (strEQ(name, "O_DEFER"))
287#ifdef O_DEFER
288 return O_DEFER;
289#else
290 goto not_there;
291#endif
292 if (strEQ(name, "O_DSYNC"))
293#ifdef O_DSYNC
294 return O_DSYNC;
295#else
296 goto not_there;
297#endif
a0d0e21e 298 if (strEQ(name, "O_EXCL"))
299#ifdef O_EXCL
300 return O_EXCL;
301#else
302 goto not_there;
303#endif
0fd60c2a 304 if (strEQ(name, "O_EXLOCK"))
305#ifdef O_EXLOCK
306 return O_EXLOCK;
a0d0e21e 307#else
308 goto not_there;
309#endif
5ff3f7a4 310 if (strEQ(name, "O_LARGEFILE"))
311#ifdef O_LARGEFILE
312 return O_LARGEFILE;
313#else
314 goto not_there;
315#endif
0fd60c2a 316 if (strEQ(name, "O_NDELAY"))
317#ifdef O_NDELAY
318 return O_NDELAY;
a0d0e21e 319#else
320 goto not_there;
321#endif
0fd60c2a 322 if (strEQ(name, "O_NOCTTY"))
323#ifdef O_NOCTTY
324 return O_NOCTTY;
a0d0e21e 325#else
326 goto not_there;
327#endif
328 if (strEQ(name, "O_NONBLOCK"))
329#ifdef O_NONBLOCK
330 return O_NONBLOCK;
331#else
332 goto not_there;
333#endif
a0d0e21e 334 if (strEQ(name, "O_RDONLY"))
335#ifdef O_RDONLY
336 return O_RDONLY;
337#else
338 goto not_there;
339#endif
340 if (strEQ(name, "O_RDWR"))
341#ifdef O_RDWR
342 return O_RDWR;
343#else
344 goto not_there;
345#endif
0fd60c2a 346 if (strEQ(name, "O_RSYNC"))
347#ifdef O_RSYNC
348 return O_RSYNC;
705af498 349#else
350 goto not_there;
351#endif
352 if (strEQ(name, "O_SHLOCK"))
353#ifdef O_SHLOCK
354 return O_SHLOCK;
355#else
356 goto not_there;
357#endif
0fd60c2a 358 if (strEQ(name, "O_SYNC"))
359#ifdef O_SYNC
360 return O_SYNC;
705af498 361#else
362 goto not_there;
363#endif
0fd60c2a 364 if (strEQ(name, "O_TEXT"))
365#ifdef O_TEXT
366 return O_TEXT;
705af498 367#else
368 goto not_there;
369#endif
0fd60c2a 370 if (strEQ(name, "O_TRUNC"))
371#ifdef O_TRUNC
372 return O_TRUNC;
705af498 373#else
374 goto not_there;
375#endif
0fd60c2a 376 if (strEQ(name, "O_WRONLY"))
377#ifdef O_WRONLY
378 return O_WRONLY;
705af498 379#else
380 goto not_there;
381#endif
a0d0e21e 382 } else
383 goto not_there;
384 break;
385 }
386 errno = EINVAL;
387 return 0;
388
389not_there:
390 errno = ENOENT;
391 return 0;
392}
393
394
395MODULE = Fcntl PACKAGE = Fcntl
396
397double
398constant(name,arg)
399 char * name
400 int arg
401