File: ShareLite.xs

package info (click to toggle)
libipc-sharelite-perl 0.17-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: ansic: 585; perl: 436; makefile: 13
file content (340 lines) | stat: -rw-r--r-- 5,960 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/ipc.h>
#include "sharestuff.h"
/*
 * Some perl version compatibility stuff.
 * Taken from HTML::Parser
 */
#include "patchlevel.h"
#if PATCHLEVEL <= 4             /* perl5.004_XX */
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#define PL_sv_yes   sv_yes
#endif
#ifndef PL_hexdigit
#define PL_hexdigit hexdigit
#endif
#if (PATCHLEVEL == 4 && SUBVERSION <= 4)
/* The newSVpvn function was introduced in perl5.004_05 */ static SV *
newSVpvn( char *s, STRLEN len ) {
  register SV *sv = newSV( 0 );
  sv_setpvn( sv, s, len );
  return sv;
}
#endif                          /* not perl5.004_05 */
#endif                          /* perl5.004_XX */

static double
constant( char *name, int arg ) {
  errno = 0;
  switch ( *name ) {
  case 'A':
    break;
  case 'B':
    break;
  case 'C':
    break;
  case 'D':
    break;
  case 'E':
    break;
  case 'F':
    break;
  case 'G':
    if ( strEQ( name, "GETALL" ) )
#ifdef GETALL
      return GETALL;
#else
      goto not_there;
#endif
    if ( strEQ( name, "GETNCNT" ) )
#ifdef GETNCNT
      return GETNCNT;
#else
      goto not_there;
#endif
    if ( strEQ( name, "GETPID" ) )
#ifdef GETPID
      return GETPID;
#else
      goto not_there;
#endif
    if ( strEQ( name, "GETVAL" ) )
#ifdef GETVAL
      return GETVAL;
#else
      goto not_there;
#endif
    if ( strEQ( name, "GETZCNT" ) )
#ifdef GETZCNT
      return GETZCNT;
#else
      goto not_there;
#endif
    break;
  case 'H':
    break;
  case 'I':
    if ( strEQ( name, "IPC_ALLOC" ) )
#ifdef IPC_ALLOC
      return IPC_ALLOC;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_CREAT" ) )
#ifdef IPC_CREAT
      return IPC_CREAT;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_EXCL" ) )
#ifdef IPC_EXCL
      return IPC_EXCL;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_NOWAIT" ) )
#ifdef IPC_NOWAIT
      return IPC_NOWAIT;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_O_RMID" ) )
#ifdef IPC_O_RMID
      return IPC_O_RMID;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_O_SET" ) )
#ifdef IPC_O_SET
      return IPC_O_SET;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_O_STAT" ) )
#ifdef IPC_O_STAT
      return IPC_O_STAT;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_PRIVATE" ) )
#ifdef IPC_PRIVATE
      return IPC_PRIVATE;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_RMID" ) )
#ifdef IPC_RMID
      return IPC_RMID;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_SET" ) )
#ifdef IPC_SET
      return IPC_SET;
#else
      goto not_there;
#endif
    if ( strEQ( name, "IPC_STAT" ) )
#ifdef IPC_STAT
      return IPC_STAT;
#else
      goto not_there;
#endif
    break;
  case 'J':
    break;
  case 'K':
    break;
  case 'L':
    if ( strEQ( name, "LOCK_EX" ) )
#ifdef LOCK_EX
      return LOCK_EX;
#else
      goto not_there;
#endif
    if ( strEQ( name, "LOCK_SH" ) )
#ifdef LOCK_SH
      return LOCK_SH;
#else
      goto not_there;
#endif
    if ( strEQ( name, "LOCK_NB" ) )
#ifdef LOCK_NB
      return LOCK_NB;
#else
      goto not_there;
#endif
    if ( strEQ( name, "LOCK_UN" ) )
#ifdef LOCK_UN
      return LOCK_UN;
#else
      goto not_there;
#endif
    break;
  case 'M':
    break;
  case 'N':
    break;
  case 'O':
    break;
  case 'P':
    break;
  case 'Q':
    break;
  case 'R':
    break;
  case 'S':
    if ( strEQ( name, "SEM_A" ) )
#ifdef SEM_A
      return SEM_A;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SEM_R" ) )
#ifdef SEM_R
      return SEM_R;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SEM_UNDO" ) )
#ifdef SEM_UNDO
      return SEM_UNDO;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SETALL" ) )
#ifdef SETALL
      return SETALL;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SETVAL" ) )
#ifdef SETVAL
      return SETVAL;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_LOCK" ) )
#ifdef SHM_LOCK
      return SHM_LOCK;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_R" ) )
#ifdef SHM_R
      return SHM_R;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_RDONLY" ) )
#ifdef SHM_RDONLY
      return SHM_RDONLY;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_RND" ) )
#ifdef SHM_RND
      return SHM_RND;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_SHARE_MMU" ) )
#ifdef SHM_SHARE_MMU
      return SHM_SHARE_MMU;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_UNLOCK" ) )
#ifdef SHM_UNLOCK
      return SHM_UNLOCK;
#else
      goto not_there;
#endif
    if ( strEQ( name, "SHM_W" ) )
#ifdef SHM_W
      return SHM_W;
#else
      goto not_there;
#endif
    break;
  case 'T':
    break;
  case 'U':
    break;
  case 'V':
    break;
  case 'W':
    break;
  case 'X':
    break;
  case 'Y':
    break;
  case 'Z':
    break;
  }
  errno = EINVAL;
  return 0;

not_there:
  errno = ENOENT;
  return 0;
}

/* *INDENT-OFF* */

MODULE = IPC::ShareLite PACKAGE = IPC::ShareLite

PROTOTYPES: DISABLE

double
constant( char *name, int arg)

Share*
new_share(key_t key, int segment_size, int flags)

int
write_share(Share *share, char *data, int length)

char* 
read_share(Share *share)
  PREINIT:
    char*    data; 
    int      length;
  CODE:
    length = read_share(share, &data);
    ST(0) = sv_newmortal();
    if (length >= 0) {
#ifdef sv_usepvn_flags
        sv_usepvn_flags((SV*)ST(0), data, length, SV_HAS_TRAILING_NUL);
#else
        sv_usepvn((SV*)ST(0), data, length);
#endif
    } else {
        sv_setsv(ST(0), &PL_sv_undef);
    }
 
int
destroy_share(Share *share, int rmid)

int
sharelite_lock(Share *share, int flags)

int
sharelite_unlock(Share *share)

unsigned int
sharelite_version(Share *share)

int
sharelite_num_segments(Share *share)