fixes to enable ISC to build IPC/SysV
[p5sagit/p5-mst-13.2.git] / ext / IPC / SysV / SysV.xs
CommitLineData
0ade1984 1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4
5#include <sys/types.h>
6#ifdef __linux__
7#include <asm/page.h>
8#endif
9#if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
10#include <sys/ipc.h>
11#ifdef HAS_MSG
12#include <sys/msg.h>
13#endif
14#ifdef HAS_SEM
15#include <sys/sem.h>
16#endif
17#ifdef HAS_SHM
a696a92a 18#if defined(PERL_SCO5) || defined(PERL_ISC)
93502d79 19#include <sys/sysmacros.h>
20#endif
0ade1984 21#include <sys/shm.h>
22# ifndef HAS_SHMAT_PROTOTYPE
23 extern Shmat_t shmat _((int, char *, int));
24# endif
25#endif
26#endif
27
1e509ade 28/* Required in BSDI to get PAGE_SIZE definition for SHMLBA.
29 * Ugly. More beautiful solutions welcome.
30 * Shouting at BSDI sounds quite beautiful. */
31#ifdef __bsdi__
32# include <vm/vm_param.h>
33#endif
34
0ade1984 35MODULE=IPC::SysV PACKAGE=IPC::Msg::stat
36
37PROTOTYPES: ENABLE
38
39void
40pack(obj)
41 SV * obj
42PPCODE:
43{
6087ac44 44#ifdef HAS_MSG
0ade1984 45 SV *sv;
46 struct msqid_ds ds;
47 AV *list = (AV*)SvRV(obj);
48 sv = *av_fetch(list,0,TRUE); ds.msg_perm.uid = SvIV(sv);
49 sv = *av_fetch(list,1,TRUE); ds.msg_perm.gid = SvIV(sv);
50 sv = *av_fetch(list,4,TRUE); ds.msg_perm.mode = SvIV(sv);
51 sv = *av_fetch(list,6,TRUE); ds.msg_qbytes = SvIV(sv);
52 ST(0) = sv_2mortal(newSVpv((char *)&ds,sizeof(ds)));
53 XSRETURN(1);
6087ac44 54#else
55 croak("System V msgxxx is not implemented on this machine");
56#endif
0ade1984 57}
58
59void
60unpack(obj,buf)
61 SV * obj
62 SV * buf
63PPCODE:
64{
6087ac44 65#ifdef HAS_MSG
0ade1984 66 STRLEN len;
67 SV **sv_ptr;
68 struct msqid_ds *ds = (struct msqid_ds *)SvPV(buf,len);
69 AV *list = (AV*)SvRV(obj);
70 if (len != sizeof(*ds)) {
71 croak("Bad arg length for %s, length is %d, should be %d",
72 "IPC::Msg::stat",
73 len, sizeof(*ds));
74 }
75 sv_ptr = av_fetch(list,0,TRUE);
76 sv_setiv(*sv_ptr, ds->msg_perm.uid);
77 sv_ptr = av_fetch(list,1,TRUE);
78 sv_setiv(*sv_ptr, ds->msg_perm.gid);
79 sv_ptr = av_fetch(list,2,TRUE);
80 sv_setiv(*sv_ptr, ds->msg_perm.cuid);
81 sv_ptr = av_fetch(list,3,TRUE);
82 sv_setiv(*sv_ptr, ds->msg_perm.cgid);
83 sv_ptr = av_fetch(list,4,TRUE);
84 sv_setiv(*sv_ptr, ds->msg_perm.mode);
85 sv_ptr = av_fetch(list,5,TRUE);
86 sv_setiv(*sv_ptr, ds->msg_qnum);
87 sv_ptr = av_fetch(list,6,TRUE);
88 sv_setiv(*sv_ptr, ds->msg_qbytes);
89 sv_ptr = av_fetch(list,7,TRUE);
90 sv_setiv(*sv_ptr, ds->msg_lspid);
91 sv_ptr = av_fetch(list,8,TRUE);
92 sv_setiv(*sv_ptr, ds->msg_lrpid);
93 sv_ptr = av_fetch(list,9,TRUE);
94 sv_setiv(*sv_ptr, ds->msg_stime);
95 sv_ptr = av_fetch(list,10,TRUE);
96 sv_setiv(*sv_ptr, ds->msg_rtime);
97 sv_ptr = av_fetch(list,11,TRUE);
98 sv_setiv(*sv_ptr, ds->msg_ctime);
99 XSRETURN(1);
6087ac44 100#else
101 croak("System V msgxxx is not implemented on this machine");
102#endif
0ade1984 103}
104
105MODULE=IPC::SysV PACKAGE=IPC::Semaphore::stat
106
107void
108unpack(obj,ds)
109 SV * obj
110 SV * ds
111PPCODE:
112{
6087ac44 113#ifdef HAS_SEM
0ade1984 114 STRLEN len;
115 AV *list = (AV*)SvRV(obj);
116 struct semid_ds *data = (struct semid_ds *)SvPV(ds,len);
117 if(!sv_isa(obj, "IPC::Semaphore::stat"))
118 croak("method %s not called a %s object",
119 "unpack","IPC::Semaphore::stat");
120 if (len != sizeof(*data)) {
121 croak("Bad arg length for %s, length is %d, should be %d",
122 "IPC::Semaphore::stat",
123 len, sizeof(*data));
124 }
125 sv_setiv(*av_fetch(list,0,TRUE), data[0].sem_perm.uid);
126 sv_setiv(*av_fetch(list,1,TRUE), data[0].sem_perm.gid);
127 sv_setiv(*av_fetch(list,2,TRUE), data[0].sem_perm.cuid);
128 sv_setiv(*av_fetch(list,3,TRUE), data[0].sem_perm.cgid);
129 sv_setiv(*av_fetch(list,4,TRUE), data[0].sem_perm.mode);
130 sv_setiv(*av_fetch(list,5,TRUE), data[0].sem_ctime);
131 sv_setiv(*av_fetch(list,6,TRUE), data[0].sem_otime);
132 sv_setiv(*av_fetch(list,7,TRUE), data[0].sem_nsems);
133 XSRETURN(1);
6087ac44 134#else
135 croak("System V semxxx is not implemented on this machine");
136#endif
0ade1984 137}
138
139void
140pack(obj)
141 SV * obj
142PPCODE:
143{
6087ac44 144#ifdef HAS_SEM
0ade1984 145 SV **sv_ptr;
146 SV *sv;
147 struct semid_ds ds;
148 AV *list = (AV*)SvRV(obj);
149 if(!sv_isa(obj, "IPC::Semaphore::stat"))
150 croak("method %s not called a %s object",
151 "pack","IPC::Semaphore::stat");
152 if((sv_ptr = av_fetch(list,0,TRUE)) && (sv = *sv_ptr))
153 ds.sem_perm.uid = SvIV(*sv_ptr);
154 if((sv_ptr = av_fetch(list,1,TRUE)) && (sv = *sv_ptr))
155 ds.sem_perm.gid = SvIV(*sv_ptr);
156 if((sv_ptr = av_fetch(list,2,TRUE)) && (sv = *sv_ptr))
157 ds.sem_perm.cuid = SvIV(*sv_ptr);
158 if((sv_ptr = av_fetch(list,3,TRUE)) && (sv = *sv_ptr))
159 ds.sem_perm.cgid = SvIV(*sv_ptr);
160 if((sv_ptr = av_fetch(list,4,TRUE)) && (sv = *sv_ptr))
161 ds.sem_perm.mode = SvIV(*sv_ptr);
162 if((sv_ptr = av_fetch(list,5,TRUE)) && (sv = *sv_ptr))
163 ds.sem_ctime = SvIV(*sv_ptr);
164 if((sv_ptr = av_fetch(list,6,TRUE)) && (sv = *sv_ptr))
165 ds.sem_otime = SvIV(*sv_ptr);
166 if((sv_ptr = av_fetch(list,7,TRUE)) && (sv = *sv_ptr))
167 ds.sem_nsems = SvIV(*sv_ptr);
168 ST(0) = sv_2mortal(newSVpv((char *)&ds,sizeof(ds)));
169 XSRETURN(1);
6087ac44 170#else
171 croak("System V semxxx is not implemented on this machine");
172#endif
0ade1984 173}
174
175MODULE=IPC::SysV PACKAGE=IPC::SysV
176
177int
178ftok(path, id)
179 char * path
180 int id
181 CODE:
182#if defined(HAS_SEM) || defined(HAS_SHM)
183 key_t k = ftok(path, id);
6b88bc9c 184 ST(0) = k == (key_t) -1 ? &PL_sv_undef : sv_2mortal(newSViv(k));
0ade1984 185#else
186 DIE(no_func, "ftok");
187#endif
188
189int
190SHMLBA()
191 CODE:
192#ifdef SHMLBA
193 ST(0) = sv_2mortal(newSViv(SHMLBA));
194#else
195 croak("SHMLBA is not defined on this architecture");
196#endif
197
198BOOT:
199{
200 HV *stash = gv_stashpvn("IPC::SysV", 9, TRUE);
201 /*
202 * constant subs for IPC::SysV
203 */
204 struct { char *n; I32 v; } IPC__SysV__const[] = {
205#ifdef GETVAL
206 {"GETVAL", GETVAL},
207#endif
208#ifdef GETPID
209 {"GETPID", GETPID},
210#endif
211#ifdef GETNCNT
212 {"GETNCNT", GETNCNT},
213#endif
214#ifdef GETZCNT
215 {"GETZCNT", GETZCNT},
216#endif
217#ifdef GETALL
218 {"GETALL", GETALL},
219#endif
220#ifdef IPC_ALLOC
221 {"IPC_ALLOC", IPC_ALLOC},
222#endif
223#ifdef IPC_CREAT
224 {"IPC_CREAT", IPC_CREAT},
225#endif
226#ifdef IPC_EXCL
227 {"IPC_EXCL", IPC_EXCL},
228#endif
229#ifdef IPC_GETACL
230 {"IPC_GETACL", IPC_EXCL},
231#endif
232#ifdef IPC_LOCKED
233 {"IPC_LOCKED", IPC_LOCKED},
234#endif
235#ifdef IPC_M
236 {"IPC_M", IPC_M},
237#endif
238#ifdef IPC_NOERROR
239 {"IPC_NOERROR", IPC_NOERROR},
240#endif
241#ifdef IPC_NOWAIT
242 {"IPC_NOWAIT", IPC_NOWAIT},
243#endif
244#ifdef IPC_PRIVATE
245 {"IPC_PRIVATE", IPC_PRIVATE},
246#endif
247#ifdef IPC_R
248 {"IPC_R", IPC_R},
249#endif
250#ifdef IPC_RMID
251 {"IPC_RMID", IPC_RMID},
252#endif
253#ifdef IPC_SET
254 {"IPC_SET", IPC_SET},
255#endif
256#ifdef IPC_SETACL
257 {"IPC_SETACL", IPC_SETACL},
258#endif
259#ifdef IPC_SETLABEL
260 {"IPC_SETLABEL", IPC_SETLABEL},
261#endif
262#ifdef IPC_STAT
263 {"IPC_STAT", IPC_STAT},
264#endif
265#ifdef IPC_W
266 {"IPC_W", IPC_W},
267#endif
268#ifdef IPC_WANTED
269 {"IPC_WANTED", IPC_WANTED},
270#endif
271#ifdef MSG_NOERROR
272 {"MSG_NOERROR", MSG_NOERROR},
273#endif
274#ifdef MSG_FWAIT
275 {"MSG_FWAIT", MSG_FWAIT},
276#endif
277#ifdef MSG_LOCKED
278 {"MSG_LOCKED", MSG_LOCKED},
279#endif
280#ifdef MSG_MWAIT
281 {"MSG_MWAIT", MSG_MWAIT},
282#endif
283#ifdef MSG_WAIT
284 {"MSG_WAIT", MSG_WAIT},
285#endif
286#ifdef MSG_R
287 {"MSG_R", MSG_R},
288#endif
289#ifdef MSG_RWAIT
290 {"MSG_RWAIT", MSG_RWAIT},
291#endif
292#ifdef MSG_STAT
293 {"MSG_STAT", MSG_STAT},
294#endif
295#ifdef MSG_W
296 {"MSG_W", MSG_W},
297#endif
298#ifdef MSG_WWAIT
299 {"MSG_WWAIT", MSG_WWAIT},
300#endif
301#ifdef SEM_A
302 {"SEM_A", SEM_A},
303#endif
304#ifdef SEM_ALLOC
305 {"SEM_ALLOC", SEM_ALLOC},
306#endif
307#ifdef SEM_DEST
308 {"SEM_DEST", SEM_DEST},
309#endif
310#ifdef SEM_ERR
311 {"SEM_ERR", SEM_ERR},
312#endif
313#ifdef SEM_R
314 {"SEM_R", SEM_R},
315#endif
316#ifdef SEM_ORDER
317 {"SEM_ORDER", SEM_ORDER},
318#endif
319#ifdef SEM_UNDO
320 {"SEM_UNDO", SEM_UNDO},
321#endif
322#ifdef SETVAL
323 {"SETVAL", SETVAL},
324#endif
325#ifdef SETALL
326 {"SETALL", SETALL},
327#endif
328#ifdef SHM_CLEAR
329 {"SHM_CLEAR", SHM_CLEAR},
330#endif
331#ifdef SHM_COPY
332 {"SHM_COPY", SHM_COPY},
333#endif
334#ifdef SHM_DCACHE
335 {"SHM_DCACHE", SHM_DCACHE},
336#endif
337#ifdef SHM_DEST
338 {"SHM_DEST", SHM_DEST},
339#endif
340#ifdef SHM_ECACHE
341 {"SHM_ECACHE", SHM_ECACHE},
342#endif
343#ifdef SHM_FMAP
344 {"SHM_FMAP", SHM_FMAP},
345#endif
346#ifdef SHM_ICACHE
347 {"SHM_ICACHE", SHM_ICACHE},
348#endif
349#ifdef SHM_INIT
350 {"SHM_INIT", SHM_INIT},
351#endif
352#ifdef SHM_LOCK
353 {"SHM_LOCK", SHM_LOCK},
354#endif
355#ifdef SHM_LOCKED
356 {"SHM_LOCKED", SHM_LOCKED},
357#endif
358#ifdef SHM_MAP
359 {"SHM_MAP", SHM_MAP},
360#endif
361#ifdef SHM_NOSWAP
362 {"SHM_NOSWAP", SHM_NOSWAP},
363#endif
364#ifdef SHM_RDONLY
365 {"SHM_RDONLY", SHM_RDONLY},
366#endif
367#ifdef SHM_REMOVED
368 {"SHM_REMOVED", SHM_REMOVED},
369#endif
370#ifdef SHM_RND
371 {"SHM_RND", SHM_RND},
372#endif
373#ifdef SHM_SHARE_MMU
374 {"SHM_SHARE_MMU", SHM_SHARE_MMU},
375#endif
376#ifdef SHM_SHATTR
377 {"SHM_SHATTR", SHM_SHATTR},
378#endif
379#ifdef SHM_SIZE
380 {"SHM_SIZE", SHM_SIZE},
381#endif
382#ifdef SHM_UNLOCK
383 {"SHM_UNLOCK", SHM_UNLOCK},
384#endif
385#ifdef SHM_W
386 {"SHM_W", SHM_W},
387#endif
388#ifdef S_IRUSR
389 {"S_IRUSR", S_IRUSR},
390#endif
391#ifdef S_IWUSR
392 {"S_IWUSR", S_IWUSR},
393#endif
394#ifdef S_IRWXU
395 {"S_IRWXU", S_IRWXU},
396#endif
397#ifdef S_IRGRP
398 {"S_IRGRP", S_IRGRP},
399#endif
400#ifdef S_IWGRP
401 {"S_IWGRP", S_IWGRP},
402#endif
403#ifdef S_IRWXG
404 {"S_IRWXG", S_IRWXG},
405#endif
406#ifdef S_IROTH
407 {"S_IROTH", S_IROTH},
408#endif
409#ifdef S_IWOTH
410 {"S_IWOTH", S_IWOTH},
411#endif
412#ifdef S_IRWXO
413 {"S_IRWXO", S_IRWXO},
414#endif
415 {Nullch,0}};
416 char *name;
417 int i;
418
419 for(i = 0 ; name = IPC__SysV__const[i].n ; i++) {
420 newCONSTSUB(stash,name, newSViv(IPC__SysV__const[i].v));
421 }
422}
423