Further ANSI changes now builds and passes (most) tests
[p5sagit/p5-mst-13.2.git] / ext / Fcntl / Fcntl.xs
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #ifdef VMS
6 #  include <file.h>
7 #else
8 #  include <fcntl.h>
9 #endif
10
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
25 static int
26 not_here(char *s)
27 {
28     croak("%s not implemented on this architecture", s);
29     return -1;
30 }
31
32 static double
33 constant(char *name, int arg)
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
45             if (strEQ(name, "F_GETFD"))
46 #ifdef F_GETFD
47                 return F_GETFD;
48 #else
49                 goto not_there;
50 #endif
51             if (strEQ(name, "F_GETLK"))
52 #ifdef F_GETLK
53                 return F_GETLK;
54 #else
55                 goto not_there;
56 #endif
57             if (strEQ(name, "F_GETOWN"))
58 #ifdef F_GETOWN
59                 return F_GETOWN;
60 #else
61                 goto not_there;
62 #endif
63             if (strEQ(name, "F_SETFD"))
64 #ifdef F_SETFD
65                 return F_SETFD;
66 #else
67                 goto not_there;
68 #endif
69             if (strEQ(name, "F_GETFL"))
70 #ifdef F_GETFL
71                 return F_GETFL;
72 #else
73                 goto not_there;
74 #endif
75             if (strEQ(name, "F_POSIX"))
76 #ifdef F_POSIX
77                 return F_POSIX;
78 #else
79                 goto not_there;
80 #endif
81             if (strEQ(name, "F_SETFL"))
82 #ifdef F_SETFL
83                 return F_SETFL;
84 #else
85                 goto not_there;
86 #endif
87             if (strEQ(name, "F_SETLK"))
88 #ifdef F_SETLK
89                 return F_SETLK;
90 #else
91                 goto not_there;
92 #endif
93             if (strEQ(name, "F_SETLKW"))
94 #ifdef F_SETLKW
95                 return F_SETLKW;
96 #else
97                 goto not_there;
98 #endif
99             if (strEQ(name, "F_SETOWN"))
100 #ifdef F_SETOWN
101                 return F_SETOWN;
102 #else
103                 goto not_there;
104 #endif
105             if (strEQ(name, "F_RDLCK"))
106 #ifdef F_RDLCK
107                 return F_RDLCK;
108 #else
109                 goto not_there;
110 #endif
111             if (strEQ(name, "F_UNLCK"))
112 #ifdef F_UNLCK
113                 return F_UNLCK;
114 #else
115                 goto not_there;
116 #endif
117             if (strEQ(name, "F_WRLCK"))
118 #ifdef F_WRLCK
119                 return F_WRLCK;
120 #else
121                 goto not_there;
122 #endif
123             errno = EINVAL;
124             return 0;
125         }
126         if (strEQ(name, "FAPPEND"))
127 #ifdef FAPPEND
128             return FAPPEND;
129 #else
130             goto not_there;
131 #endif
132         if (strEQ(name, "FASYNC"))
133 #ifdef FASYNC
134             return FASYNC;
135 #else
136             goto not_there;
137 #endif
138         if (strEQ(name, "FCREAT"))
139 #ifdef FCREAT
140             return FCREAT;
141 #else
142             goto not_there;
143 #endif
144         if (strEQ(name, "FD_CLOEXEC"))
145 #ifdef FD_CLOEXEC
146             return FD_CLOEXEC;
147 #else
148             goto not_there;
149 #endif
150         if (strEQ(name, "FEXCL"))
151 #ifdef FEXCL
152             return FEXCL;
153 #else
154             goto not_there;
155 #endif
156         if (strEQ(name, "FNDELAY"))
157 #ifdef FNDELAY
158             return FNDELAY;
159 #else
160             goto not_there;
161 #endif
162         if (strEQ(name, "FNONBLOCK"))
163 #ifdef FNONBLOCK
164             return FNONBLOCK;
165 #else
166             goto not_there;
167 #endif
168         if (strEQ(name, "FSYNC"))
169 #ifdef FSYNC
170             return FSYNC;
171 #else
172             goto not_there;
173 #endif
174         if (strEQ(name, "FTRUNC"))
175 #ifdef FTRUNC
176             return FTRUNC;
177 #else
178             goto not_there;
179 #endif
180         break;
181     case 'L':
182         if (strnEQ(name, "LOCK_", 5)) {
183             /* We support flock() on systems which don't have it, so
184                always supply the constants. */
185             if (strEQ(name, "LOCK_SH"))
186 #ifdef LOCK_SH
187                 return LOCK_SH;
188 #else
189                 return 1;
190 #endif
191             if (strEQ(name, "LOCK_EX"))
192 #ifdef LOCK_EX
193                 return LOCK_EX;
194 #else
195                 return 2;
196 #endif
197             if (strEQ(name, "LOCK_NB"))
198 #ifdef LOCK_NB
199                 return LOCK_NB;
200 #else
201                 return 4;
202 #endif
203             if (strEQ(name, "LOCK_UN"))
204 #ifdef LOCK_UN
205                 return LOCK_UN;
206 #else
207                 return 8;
208 #endif
209         } else
210           goto not_there;
211         break;
212     case 'O':
213         if (strnEQ(name, "O_", 2)) {
214             if (strEQ(name, "O_CREAT"))
215 #ifdef O_CREAT
216                 return O_CREAT;
217 #else
218                 goto not_there;
219 #endif
220             if (strEQ(name, "O_EXCL"))
221 #ifdef O_EXCL
222                 return O_EXCL;
223 #else
224                 goto not_there;
225 #endif
226             if (strEQ(name, "O_NOCTTY"))
227 #ifdef O_NOCTTY
228                 return O_NOCTTY;
229 #else
230                 goto not_there;
231 #endif
232             if (strEQ(name, "O_TRUNC"))
233 #ifdef O_TRUNC
234                 return O_TRUNC;
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_NONBLOCK"))
245 #ifdef O_NONBLOCK
246                 return O_NONBLOCK;
247 #else
248                 goto not_there;
249 #endif
250             if (strEQ(name, "O_NDELAY"))
251 #ifdef O_NDELAY
252                 return O_NDELAY;
253 #else
254                 goto not_there;
255 #endif
256             if (strEQ(name, "O_RDONLY"))
257 #ifdef O_RDONLY
258                 return O_RDONLY;
259 #else
260                 goto not_there;
261 #endif
262             if (strEQ(name, "O_RDWR"))
263 #ifdef O_RDWR
264                 return O_RDWR;
265 #else
266                 goto not_there;
267 #endif
268             if (strEQ(name, "O_WRONLY"))
269 #ifdef O_WRONLY
270                 return O_WRONLY;
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
280             if (strEQ(name, "O_EXLOCK"))
281 #ifdef O_EXLOCK
282                 return O_EXLOCK;
283 #else
284                 goto not_there;
285 #endif
286             if (strEQ(name, "O_SHLOCK"))
287 #ifdef O_SHLOCK
288                 return O_SHLOCK;
289 #else
290                 goto not_there;
291 #endif
292             if (strEQ(name, "O_ASYNC"))
293 #ifdef O_ASYNC
294                 return O_ASYNC;
295 #else
296                 goto not_there;
297 #endif
298             if (strEQ(name, "O_DSYNC"))
299 #ifdef O_DSYNC
300                 return O_DSYNC;
301 #else
302                 goto not_there;
303 #endif
304             if (strEQ(name, "O_RSYNC"))
305 #ifdef O_RSYNC
306                 return O_RSYNC;
307 #else
308                 goto not_there;
309 #endif
310             if (strEQ(name, "O_SYNC"))
311 #ifdef O_SYNC
312                 return O_SYNC;
313 #else
314                 goto not_there;
315 #endif
316             if (strEQ(name, "O_DEFER"))
317 #ifdef O_DEFER
318                 return O_DEFER;
319 #else
320                 goto not_there;
321 #endif
322         } else
323           goto not_there;
324         break;
325     }
326     errno = EINVAL;
327     return 0;
328
329 not_there:
330     errno = ENOENT;
331     return 0;
332 }
333
334
335 MODULE = Fcntl          PACKAGE = Fcntl
336
337 double
338 constant(name,arg)
339         char *          name
340         int             arg
341