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