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