Commit | Line | Data |
011f1a1a |
1 | |
2 | /* |
3 | * Copyright © 2001 Novell, Inc. All Rights Reserved. |
4 | * |
5 | * You may distribute under the terms of either the GNU General Public |
6 | * License or the Artistic License, as specified in the README file. |
7 | * |
8 | */ |
9 | |
10 | /* |
11 | * FILENAME : nwperlhost.h |
12 | * DESCRIPTION : This is modelled on the perlhost.h module of Win32 port. |
13 | * This is the host that include all the functions for running Perl within a class. |
14 | * Author : SGP, HYAK |
15 | * Date : January 2001. |
16 | * |
17 | */ |
18 | |
19 | |
20 | |
21 | #ifndef ___NWPerlHost_H___ |
22 | #define ___NWPerlHost_H___ |
23 | |
24 | |
25 | #include "iperlsys.h" |
26 | #include "nwvmem.h" |
27 | |
28 | #include "nw5sck.h" |
29 | #include "netware.h" |
30 | |
31 | #define LPBYTE unsigned char * |
32 | |
33 | #if !defined(PERL_OBJECT) |
34 | START_EXTERN_C |
35 | #endif /* PERL_OBJECT */ |
36 | |
37 | extern int do_spawn2(char *cmd, int exectype); |
38 | extern int do_aspawn(void *vreally, void **vmark, void **vsp); |
39 | extern void Perl_init_os_extras(void); |
40 | |
41 | #if !defined(PERL_OBJECT) |
42 | END_EXTERN_C |
43 | #endif /* PERL_OBJECT */ |
44 | |
45 | #ifdef PERL_OBJECT |
46 | extern int g_do_aspawn(void *vreally, void **vmark, void **vsp); |
47 | #define do_aspawn g_do_aspawn |
48 | #endif /* PERL_OBJECT */ |
49 | |
50 | class CPerlHost |
51 | { |
52 | public: |
53 | CPerlHost(void); |
54 | CPerlHost(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared, |
55 | struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv, |
56 | struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO, |
57 | struct IPerlDir** ppDir, struct IPerlSock** ppSock, |
58 | struct IPerlProc** ppProc); |
59 | CPerlHost(const CPerlHost& host); |
60 | virtual ~CPerlHost(void); |
61 | |
62 | static CPerlHost* IPerlMem2Host(struct IPerlMem* piPerl); |
63 | static CPerlHost* IPerlMemShared2Host(struct IPerlMem* piPerl); |
64 | static CPerlHost* IPerlMemParse2Host(struct IPerlMem* piPerl); |
65 | static CPerlHost* IPerlEnv2Host(struct IPerlEnv* piPerl); |
66 | static CPerlHost* IPerlStdIO2Host(struct IPerlStdIO* piPerl); |
67 | static CPerlHost* IPerlLIO2Host(struct IPerlLIO* piPerl); |
68 | static CPerlHost* IPerlDir2Host(struct IPerlDir* piPerl); |
69 | static CPerlHost* IPerlSock2Host(struct IPerlSock* piPerl); |
70 | static CPerlHost* IPerlProc2Host(struct IPerlProc* piPerl); |
71 | |
72 | /* IPerlMem */ |
73 | inline void* Malloc(size_t size) { return m_pVMem->Malloc(size); }; |
74 | inline void* Realloc(void* ptr, size_t size) { return m_pVMem->Realloc(ptr, size); }; |
75 | inline void Free(void* ptr) { m_pVMem->Free(ptr); }; |
76 | inline void* Calloc(size_t num, size_t size){ return m_pVMem->Calloc(num, size); }; |
77 | |
78 | /* IPerlMemShared */ |
79 | inline void* MallocShared(size_t size) |
80 | { |
81 | return m_pVMemShared->Malloc(size); |
82 | }; |
83 | inline void* ReallocShared(void* ptr, size_t size) { return m_pVMemShared->Realloc(ptr, size); }; |
84 | inline void FreeShared(void* ptr) { m_pVMemShared->Free(ptr); }; |
85 | inline void* CallocShared(size_t num, size_t size) |
86 | { |
87 | size_t count = num*size; |
88 | void* lpVoid = MallocShared(count); |
89 | |
90 | return lpVoid; |
91 | }; |
92 | |
93 | /* IPerlMemParse */ |
94 | inline void* MallocParse(size_t size) { return m_pVMemParse->Malloc(size); }; |
95 | inline void* ReallocParse(void* ptr, size_t size) { return m_pVMemParse->Realloc(ptr, size); }; |
96 | inline void FreeParse(void* ptr) { m_pVMemParse->Free(ptr); }; |
97 | inline void* CallocParse(size_t num, size_t size) |
98 | { |
99 | size_t count = num*size; |
100 | void* lpVoid = MallocParse(count); |
101 | |
102 | return lpVoid; |
103 | }; |
104 | |
105 | /* IPerlEnv */ |
106 | char *Getenv(const char *varname); |
107 | int Putenv(const char *envstring); |
108 | inline char *Getenv(const char *varname, unsigned long *len) |
109 | { |
110 | *len = 0; |
111 | char *e = Getenv(varname); |
112 | if (e) |
113 | *len = strlen(e); |
114 | return e; |
115 | } |
116 | |
117 | |
118 | public: |
119 | |
120 | /* IPerlDIR */ |
121 | |
122 | |
123 | /* IPerllProc */ |
124 | void Abort(void); |
125 | void Exit(int status); |
126 | void _Exit(int status); |
127 | int Execl(const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3); |
128 | int Execv(const char *cmdname, const char *const *argv); |
129 | int Execvp(const char *cmdname, const char *const *argv); |
130 | |
131 | public: |
132 | |
133 | struct IPerlMem m_hostperlMem; |
134 | struct IPerlMem m_hostperlMemShared; |
135 | struct IPerlMem m_hostperlMemParse; |
136 | struct IPerlEnv m_hostperlEnv; |
137 | struct IPerlStdIO m_hostperlStdIO; |
138 | struct IPerlLIO m_hostperlLIO; |
139 | struct IPerlDir m_hostperlDir; |
140 | struct IPerlSock m_hostperlSock; |
141 | struct IPerlProc m_hostperlProc; |
142 | |
143 | struct IPerlMem* m_pHostperlMem; |
144 | struct IPerlMem* m_pHostperlMemShared; |
145 | struct IPerlMem* m_pHostperlMemParse; |
146 | struct IPerlEnv* m_pHostperlEnv; |
147 | struct IPerlStdIO* m_pHostperlStdIO; |
148 | struct IPerlLIO* m_pHostperlLIO; |
149 | struct IPerlDir* m_pHostperlDir; |
150 | struct IPerlSock* m_pHostperlSock; |
151 | struct IPerlProc* m_pHostperlProc; |
152 | |
153 | protected: |
154 | |
155 | VMem* m_pVMem; |
156 | VMem* m_pVMemShared; |
157 | VMem* m_pVMemParse; |
158 | }; |
159 | |
160 | |
161 | #define STRUCT2PTR(x, y) (CPerlHost*)(((LPBYTE)x)-offsetof(CPerlHost, y)) |
162 | |
163 | inline CPerlHost* IPerlMem2Host(struct IPerlMem* piPerl) |
164 | { |
165 | return STRUCT2PTR(piPerl, m_hostperlMem); |
166 | } |
167 | |
168 | inline CPerlHost* IPerlMemShared2Host(struct IPerlMem* piPerl) |
169 | { |
170 | return STRUCT2PTR(piPerl, m_hostperlMemShared); |
171 | } |
172 | |
173 | inline CPerlHost* IPerlMemParse2Host(struct IPerlMem* piPerl) |
174 | { |
175 | return STRUCT2PTR(piPerl, m_hostperlMemParse); |
176 | } |
177 | |
178 | inline CPerlHost* IPerlEnv2Host(struct IPerlEnv* piPerl) |
179 | { |
180 | return STRUCT2PTR(piPerl, m_hostperlEnv); |
181 | } |
182 | |
183 | inline CPerlHost* IPerlStdIO2Host(struct IPerlStdIO* piPerl) |
184 | { |
185 | return STRUCT2PTR(piPerl, m_hostperlStdIO); |
186 | } |
187 | |
188 | inline CPerlHost* IPerlLIO2Host(struct IPerlLIO* piPerl) |
189 | { |
190 | return STRUCT2PTR(piPerl, m_hostperlLIO); |
191 | } |
192 | |
193 | inline CPerlHost* IPerlDir2Host(struct IPerlDir* piPerl) |
194 | { |
195 | return STRUCT2PTR(piPerl, m_hostperlDir); |
196 | } |
197 | |
198 | inline CPerlHost* IPerlSock2Host(struct IPerlSock* piPerl) |
199 | { |
200 | return STRUCT2PTR(piPerl, m_hostperlSock); |
201 | } |
202 | |
203 | inline CPerlHost* IPerlProc2Host(struct IPerlProc* piPerl) |
204 | { |
205 | return STRUCT2PTR(piPerl, m_hostperlProc); |
206 | } |
207 | |
208 | |
209 | #undef IPERL2HOST |
210 | #define IPERL2HOST(x) IPerlMem2Host(x) |
211 | |
212 | |
213 | /* IPerlMem */ |
214 | void* |
215 | PerlMemMalloc(struct IPerlMem* piPerl, size_t size) |
216 | { |
217 | return IPERL2HOST(piPerl)->Malloc(size); |
218 | } |
219 | void* |
220 | PerlMemRealloc(struct IPerlMem* piPerl, void* ptr, size_t size) |
221 | { |
222 | return IPERL2HOST(piPerl)->Realloc(ptr, size); |
223 | } |
224 | void |
225 | PerlMemFree(struct IPerlMem* piPerl, void* ptr) |
226 | { |
227 | IPERL2HOST(piPerl)->Free(ptr); |
228 | } |
229 | void* |
230 | PerlMemCalloc(struct IPerlMem* piPerl, size_t num, size_t size) |
231 | { |
232 | return IPERL2HOST(piPerl)->Calloc(num, size); |
233 | } |
234 | |
235 | |
236 | struct IPerlMem perlMem = |
237 | { |
238 | PerlMemMalloc, |
239 | PerlMemRealloc, |
240 | PerlMemFree, |
241 | PerlMemCalloc, |
242 | }; |
243 | |
244 | #undef IPERL2HOST |
245 | #define IPERL2HOST(x) IPerlMemShared2Host(x) |
246 | |
247 | /* IPerlMemShared */ |
248 | void* |
249 | PerlMemSharedMalloc(struct IPerlMem* piPerl, size_t size) |
250 | { |
251 | return IPERL2HOST(piPerl)->MallocShared(size); |
252 | } |
253 | void* |
254 | PerlMemSharedRealloc(struct IPerlMem* piPerl, void* ptr, size_t size) |
255 | { |
256 | return IPERL2HOST(piPerl)->ReallocShared(ptr, size); |
257 | } |
258 | void |
259 | PerlMemSharedFree(struct IPerlMem* piPerl, void* ptr) |
260 | { |
261 | IPERL2HOST(piPerl)->FreeShared(ptr); |
262 | } |
263 | void* |
264 | PerlMemSharedCalloc(struct IPerlMem* piPerl, size_t num, size_t size) |
265 | { |
266 | return IPERL2HOST(piPerl)->CallocShared(num, size); |
267 | } |
268 | |
269 | |
270 | struct IPerlMem perlMemShared = |
271 | { |
272 | PerlMemSharedMalloc, |
273 | PerlMemSharedRealloc, |
274 | PerlMemSharedFree, |
275 | PerlMemSharedCalloc, |
276 | }; |
277 | |
278 | #undef IPERL2HOST |
279 | #define IPERL2HOST(x) IPerlMemParse2Host(x) |
280 | |
281 | /* IPerlMemParse */ |
282 | void* |
283 | PerlMemParseMalloc(struct IPerlMem* piPerl, size_t size) |
284 | { |
285 | return IPERL2HOST(piPerl)->MallocParse(size); |
286 | } |
287 | void* |
288 | PerlMemParseRealloc(struct IPerlMem* piPerl, void* ptr, size_t size) |
289 | { |
290 | return IPERL2HOST(piPerl)->ReallocParse(ptr, size); |
291 | } |
292 | void |
293 | PerlMemParseFree(struct IPerlMem* piPerl, void* ptr) |
294 | { |
295 | IPERL2HOST(piPerl)->FreeParse(ptr); |
296 | } |
297 | void* |
298 | PerlMemParseCalloc(struct IPerlMem* piPerl, size_t num, size_t size) |
299 | { |
300 | return IPERL2HOST(piPerl)->CallocParse(num, size); |
301 | } |
302 | |
303 | |
304 | struct IPerlMem perlMemParse = |
305 | { |
306 | PerlMemParseMalloc, |
307 | PerlMemParseRealloc, |
308 | PerlMemParseFree, |
309 | PerlMemParseCalloc, |
310 | }; |
311 | |
312 | |
313 | #undef IPERL2HOST |
314 | #define IPERL2HOST(x) IPerlEnv2Host(x) |
315 | |
316 | /* IPerlEnv */ |
317 | char* |
318 | PerlEnvGetenv(struct IPerlEnv* piPerl, const char *varname) |
319 | { |
320 | return IPERL2HOST(piPerl)->Getenv(varname); |
321 | }; |
322 | |
323 | int |
324 | PerlEnvPutenv(struct IPerlEnv* piPerl, const char *envstring) |
325 | { |
326 | return IPERL2HOST(piPerl)->Putenv(envstring); |
327 | }; |
328 | |
329 | char* |
330 | PerlEnvGetenv_len(struct IPerlEnv* piPerl, const char* varname, unsigned long* len) |
331 | { |
332 | return IPERL2HOST(piPerl)->Getenv(varname, len); |
333 | } |
334 | |
335 | int |
336 | PerlEnvUname(struct IPerlEnv* piPerl, struct utsname *name) |
337 | { |
338 | return nw_uname(name); |
339 | } |
340 | |
341 | void |
342 | PerlEnvClearenv(struct IPerlEnv* piPerl) |
343 | { |
344 | // If removed, compilation fails while compiling CGI2Perl. |
345 | } |
346 | |
347 | void* |
348 | PerlEnvGetChildenv(struct IPerlEnv* piPerl) |
349 | { |
350 | // If removed, compilation fails while compiling CGI2Perl. |
351 | return NULL; |
352 | } |
353 | |
354 | void |
355 | PerlEnvFreeChildenv(struct IPerlEnv* piPerl, void* childEnv) |
356 | { |
357 | // If removed, compilation fails while compiling CGI2Perl. |
358 | } |
359 | |
360 | char* |
361 | PerlEnvGetChilddir(struct IPerlEnv* piPerl) |
362 | { |
363 | // If removed, compilation fails while compiling CGI2Perl. |
364 | return NULL; |
365 | } |
366 | |
367 | void |
368 | PerlEnvFreeChilddir(struct IPerlEnv* piPerl, char* childDir) |
369 | { |
370 | // If removed, compilation fails while compiling CGI2Perl. |
371 | } |
372 | |
373 | struct IPerlEnv perlEnv = |
374 | { |
375 | PerlEnvGetenv, |
376 | PerlEnvPutenv, |
377 | PerlEnvGetenv_len, |
378 | PerlEnvUname, |
379 | PerlEnvClearenv, |
380 | PerlEnvGetChildenv, |
381 | PerlEnvFreeChildenv, |
382 | PerlEnvGetChilddir, |
383 | PerlEnvFreeChilddir, |
384 | }; |
385 | |
386 | #undef IPERL2HOST |
387 | #define IPERL2HOST(x) IPerlStdIO2Host(x) |
388 | |
389 | /* PerlStdIO */ |
390 | PerlIO* |
391 | PerlStdIOStdin(struct IPerlStdIO* piPerl) |
392 | { |
393 | return (PerlIO*)nw_stdin(); |
394 | } |
395 | |
396 | PerlIO* |
397 | PerlStdIOStdout(struct IPerlStdIO* piPerl) |
398 | { |
399 | return (PerlIO*)nw_stdout(); |
400 | } |
401 | |
402 | PerlIO* |
403 | PerlStdIOStderr(struct IPerlStdIO* piPerl) |
404 | { |
405 | return (PerlIO*)nw_stderr(); |
406 | } |
407 | |
408 | PerlIO* |
409 | PerlStdIOOpen(struct IPerlStdIO* piPerl, const char *path, const char *mode) |
410 | { |
411 | return (PerlIO*)nw_fopen(path, mode); |
412 | } |
413 | |
414 | int |
415 | PerlStdIOClose(struct IPerlStdIO* piPerl, PerlIO* pf) |
416 | { |
417 | return nw_fclose(((FILE*)pf)); |
418 | } |
419 | |
420 | int |
421 | PerlStdIOEof(struct IPerlStdIO* piPerl, PerlIO* pf) |
422 | { |
423 | return nw_feof((FILE*)pf); |
424 | } |
425 | |
426 | int |
427 | PerlStdIOError(struct IPerlStdIO* piPerl, PerlIO* pf) |
428 | { |
429 | return nw_ferror((FILE*)pf); |
430 | } |
431 | |
432 | void |
433 | PerlStdIOClearerr(struct IPerlStdIO* piPerl, PerlIO* pf) |
434 | { |
435 | nw_clearerr((FILE*)pf); |
436 | } |
437 | |
438 | int |
439 | PerlStdIOGetc(struct IPerlStdIO* piPerl, PerlIO* pf) |
440 | { |
441 | return nw_getc((FILE*)pf); |
442 | } |
443 | |
444 | char* |
445 | PerlStdIOGetBase(struct IPerlStdIO* piPerl, PerlIO* pf) |
446 | { |
447 | #ifdef FILE_base |
448 | FILE *f = (FILE*)pf; |
449 | return FILE_base(f); |
450 | #else |
451 | return Nullch; |
452 | #endif |
453 | } |
454 | |
455 | int |
456 | PerlStdIOGetBufsiz(struct IPerlStdIO* piPerl, PerlIO* pf) |
457 | { |
458 | #ifdef FILE_bufsiz |
459 | FILE *f = (FILE*)pf; |
460 | return FILE_bufsiz(f); |
461 | #else |
462 | return (-1); |
463 | #endif |
464 | } |
465 | |
466 | int |
467 | PerlStdIOGetCnt(struct IPerlStdIO* piPerl, PerlIO* pf) |
468 | { |
469 | #ifdef USE_STDIO_PTR |
470 | FILE *f = (FILE*)pf; |
471 | return FILE_cnt(f); |
472 | #else |
473 | return (-1); |
474 | #endif |
475 | } |
476 | |
477 | char* |
478 | PerlStdIOGetPtr(struct IPerlStdIO* piPerl, PerlIO* pf) |
479 | { |
480 | #ifdef USE_STDIO_PTR |
481 | FILE *f = (FILE*)pf; |
482 | return FILE_ptr(f); |
483 | #else |
484 | return Nullch; |
485 | #endif |
486 | } |
487 | |
488 | char* |
489 | PerlStdIOGets(struct IPerlStdIO* piPerl, PerlIO* pf, char* s, int n) |
490 | { |
491 | return nw_fgets(s, n, (FILE*)pf); |
492 | } |
493 | |
494 | int |
495 | PerlStdIOPutc(struct IPerlStdIO* piPerl, PerlIO* pf, int c) |
496 | { |
497 | return nw_fputc(c, (FILE*)pf); |
498 | } |
499 | |
500 | int |
501 | PerlStdIOPuts(struct IPerlStdIO* piPerl, PerlIO* pf, const char *s) |
502 | { |
503 | return nw_fputs(s, (FILE*)pf); |
504 | } |
505 | |
506 | int |
507 | PerlStdIOFlush(struct IPerlStdIO* piPerl, PerlIO* pf) |
508 | { |
509 | return nw_fflush((FILE*)pf); |
510 | } |
511 | |
512 | int |
513 | PerlStdIOUngetc(struct IPerlStdIO* piPerl, int c, PerlIO* pf) //(J) |
514 | { |
515 | return nw_ungetc(c, (FILE*)pf); |
516 | } |
517 | |
518 | int |
519 | PerlStdIOFileno(struct IPerlStdIO* piPerl, PerlIO* pf) |
520 | { |
521 | return nw_fileno((FILE*)pf); |
522 | } |
523 | |
524 | PerlIO* |
525 | PerlStdIOFdopen(struct IPerlStdIO* piPerl, int fd, const char *mode) |
526 | { |
527 | return (PerlIO*)nw_fdopen(fd, mode); |
528 | } |
529 | |
530 | PerlIO* |
531 | PerlStdIOReopen(struct IPerlStdIO* piPerl, const char*path, const char*mode, PerlIO* pf) |
532 | { |
533 | return (PerlIO*)nw_freopen(path, mode, (FILE*)pf); |
534 | } |
535 | |
536 | SSize_t |
537 | PerlStdIORead(struct IPerlStdIO* piPerl, void *buffer, Size_t size, Size_t dummy, PerlIO* pf) |
538 | { |
539 | return nw_fread(buffer, 1, size, (FILE*)pf); |
540 | } |
541 | |
542 | SSize_t |
543 | PerlStdIOWrite(struct IPerlStdIO* piPerl, const void *buffer, Size_t size, Size_t dummy, PerlIO* pf) |
544 | //PerlStdIOWrite(struct IPerlStdIO* piPerl, PerlIO* pf, const void *buffer, Size_t size) |
545 | { |
546 | return nw_fwrite(buffer, 1, size, (FILE*)pf); |
547 | } |
548 | |
549 | void |
550 | PerlStdIOSetBuf(struct IPerlStdIO* piPerl, PerlIO* pf, char* buffer) |
551 | { |
552 | nw_setbuf((FILE*)pf, buffer); |
553 | } |
554 | |
555 | int |
556 | PerlStdIOSetVBuf(struct IPerlStdIO* piPerl, PerlIO* pf, char* buffer, int type, Size_t size) |
557 | { |
558 | return nw_setvbuf((FILE*)pf, buffer, type, size); |
559 | } |
560 | |
561 | void |
562 | PerlStdIOSetCnt(struct IPerlStdIO* piPerl, PerlIO* pf, int n) |
563 | { |
564 | #ifdef STDIO_CNT_LVALUE |
565 | FILE *f = (FILE*)pf; |
566 | FILE_cnt(f) = n; |
567 | #endif |
568 | } |
569 | |
570 | void |
571 | PerlStdIOSetPtrCnt(struct IPerlStdIO* piPerl, PerlIO* pf, char * ptr, int n) |
572 | { |
573 | #ifdef STDIO_PTR_LVALUE |
574 | FILE *f = (FILE*)pf; |
575 | FILE_ptr(f) = ptr; |
576 | FILE_cnt(f) = n; |
577 | #endif |
578 | } |
579 | |
580 | void |
581 | PerlStdIOSetlinebuf(struct IPerlStdIO* piPerl, PerlIO* pf) |
582 | { |
583 | nw_setvbuf((FILE*)pf, NULL, _IOLBF, 0); |
584 | } |
585 | |
586 | int |
587 | PerlStdIOPrintf(struct IPerlStdIO* piPerl, PerlIO* pf, const char *format,...) |
588 | { |
589 | va_list(arglist); |
590 | va_start(arglist, format); |
591 | return nw_vfprintf((FILE*)pf, format, arglist); |
592 | } |
593 | |
594 | int |
595 | PerlStdIOVprintf(struct IPerlStdIO* piPerl, PerlIO* pf, const char *format, va_list arglist) |
596 | { |
597 | return nw_vfprintf((FILE*)pf, format, arglist); |
598 | } |
599 | |
600 | long |
601 | PerlStdIOTell(struct IPerlStdIO* piPerl, PerlIO* pf) |
602 | { |
603 | return nw_ftell((FILE*)pf); |
604 | } |
605 | |
606 | int |
607 | PerlStdIOSeek(struct IPerlStdIO* piPerl, PerlIO* pf, off_t offset, int origin) |
608 | { |
609 | return nw_fseek((FILE*)pf, offset, origin); |
610 | } |
611 | |
612 | void |
613 | PerlStdIORewind(struct IPerlStdIO* piPerl, PerlIO* pf) |
614 | { |
615 | nw_rewind((FILE*)pf); |
616 | } |
617 | |
618 | PerlIO* |
619 | PerlStdIOTmpfile(struct IPerlStdIO* piPerl) |
620 | { |
621 | return (PerlIO*)nw_tmpfile(); |
622 | } |
623 | |
624 | int |
625 | PerlStdIOGetpos(struct IPerlStdIO* piPerl, PerlIO* pf, Fpos_t *p) |
626 | { |
627 | return nw_fgetpos((FILE*)pf, p); |
628 | } |
629 | |
630 | int |
631 | PerlStdIOSetpos(struct IPerlStdIO* piPerl, PerlIO* pf, const Fpos_t *p) |
632 | { |
633 | return nw_fsetpos((FILE*)pf, p); |
634 | } |
635 | |
636 | void |
637 | PerlStdIOInit(struct IPerlStdIO* piPerl) |
638 | { |
639 | // If removed, compilation error occurs. |
640 | } |
641 | |
642 | void |
643 | PerlStdIOInitOSExtras(struct IPerlStdIO* piPerl) |
644 | { |
645 | Perl_init_os_extras(); |
646 | } |
647 | |
648 | |
649 | int |
650 | PerlStdIOOpenOSfhandle(struct IPerlStdIO* piPerl, long osfhandle, int flags) |
651 | { |
652 | return nw_open_osfhandle(osfhandle, flags); |
653 | } |
654 | |
655 | int |
656 | PerlStdIOGetOSfhandle(struct IPerlStdIO* piPerl, int filenum) |
657 | { |
658 | return nw_get_osfhandle(filenum); |
659 | } |
660 | |
661 | PerlIO* |
662 | PerlStdIOFdupopen(struct IPerlStdIO* piPerl, PerlIO* pf) |
663 | { |
664 | PerlIO* pfdup=NULL; |
665 | fpos_t pos=0; |
666 | char mode[3]={'\0'}; |
667 | int fileno = nw_dup(nw_fileno((FILE*)pf)); |
668 | |
669 | /* open the file in the same mode */ |
670 | if(((FILE*)pf)->_flag & _IOREAD) { |
671 | mode[0] = 'r'; |
672 | mode[1] = 0; |
673 | } |
674 | else if(((FILE*)pf)->_flag & _IOWRT) { |
675 | mode[0] = 'a'; |
676 | mode[1] = 0; |
677 | } |
678 | else if(((FILE*)pf)->_flag & _IORW) { |
679 | mode[0] = 'r'; |
680 | mode[1] = '+'; |
681 | mode[2] = 0; |
682 | } |
683 | |
684 | /* it appears that the binmode is attached to the |
685 | * file descriptor so binmode files will be handled |
686 | * correctly |
687 | */ |
688 | pfdup = (PerlIO*)nw_fdopen(fileno, mode); |
689 | |
690 | /* move the file pointer to the same position */ |
691 | if (!fgetpos((FILE*)pf, &pos)) { |
692 | fsetpos((FILE*)pfdup, &pos); |
693 | } |
694 | return pfdup; |
695 | } |
696 | |
697 | struct IPerlStdIO perlStdIO = |
698 | { |
699 | PerlStdIOStdin, |
700 | PerlStdIOStdout, |
701 | PerlStdIOStderr, |
702 | PerlStdIOOpen, |
703 | PerlStdIOClose, |
704 | PerlStdIOEof, |
705 | PerlStdIOError, |
706 | PerlStdIOClearerr, |
707 | PerlStdIOGetc, |
708 | PerlStdIOGetBase, |
709 | PerlStdIOGetBufsiz, |
710 | PerlStdIOGetCnt, |
711 | PerlStdIOGetPtr, |
712 | PerlStdIOGets, |
713 | PerlStdIOPutc, |
714 | PerlStdIOPuts, |
715 | PerlStdIOFlush, |
716 | PerlStdIOUngetc, |
717 | PerlStdIOFileno, |
718 | PerlStdIOFdopen, |
719 | PerlStdIOReopen, |
720 | PerlStdIORead, |
721 | PerlStdIOWrite, |
722 | PerlStdIOSetBuf, |
723 | PerlStdIOSetVBuf, |
724 | PerlStdIOSetCnt, |
725 | PerlStdIOSetPtrCnt, |
726 | PerlStdIOSetlinebuf, |
727 | PerlStdIOPrintf, |
728 | PerlStdIOVprintf, |
729 | PerlStdIOTell, |
730 | PerlStdIOSeek, |
731 | PerlStdIORewind, |
732 | PerlStdIOTmpfile, |
733 | PerlStdIOGetpos, |
734 | PerlStdIOSetpos, |
735 | PerlStdIOInit, |
736 | PerlStdIOInitOSExtras, |
737 | PerlStdIOFdupopen, |
738 | }; |
739 | |
740 | |
741 | #undef IPERL2HOST |
742 | #define IPERL2HOST(x) IPerlLIO2Host(x) |
743 | |
744 | /* IPerlLIO */ |
745 | int |
746 | PerlLIOAccess(struct IPerlLIO* piPerl, const char *path, int mode) |
747 | { |
748 | return nw_access(path, mode); |
749 | } |
750 | |
751 | int |
752 | PerlLIOChmod(struct IPerlLIO* piPerl, const char *filename, int pmode) |
753 | { |
754 | return nw_chmod(filename, pmode); |
755 | } |
756 | |
757 | int |
758 | PerlLIOChown(struct IPerlLIO* piPerl, const char *filename, uid_t owner, gid_t group) |
759 | { |
760 | // If removed, compilation error occurs. |
761 | return 0; |
762 | } |
763 | |
764 | int |
765 | PerlLIOChsize(struct IPerlLIO* piPerl, int handle, long size) |
766 | { |
767 | return (nw_chsize(handle,size)); |
768 | } |
769 | |
770 | int |
771 | PerlLIOClose(struct IPerlLIO* piPerl, int handle) |
772 | { |
773 | return nw_close(handle); |
774 | } |
775 | |
776 | int |
777 | PerlLIODup(struct IPerlLIO* piPerl, int handle) |
778 | { |
779 | return nw_dup(handle); |
780 | } |
781 | |
782 | int |
783 | PerlLIODup2(struct IPerlLIO* piPerl, int handle1, int handle2) |
784 | { |
785 | return nw_dup2(handle1, handle2); |
786 | } |
787 | |
788 | int |
789 | PerlLIOFlock(struct IPerlLIO* piPerl, int fd, int oper) |
790 | { |
791 | //On NetWare simulate flock by locking a range on the file |
792 | return nw_flock(fd, oper); |
793 | } |
794 | |
795 | int |
796 | PerlLIOFileStat(struct IPerlLIO* piPerl, int handle, struct stat *buffer) |
797 | { |
798 | return fstat(handle, buffer); |
799 | } |
800 | |
801 | int |
802 | PerlLIOIOCtl(struct IPerlLIO* piPerl, int i, unsigned int u, char *data) |
803 | { |
804 | // If removed, compilation error occurs. |
805 | return 0; |
806 | } |
807 | |
808 | int |
809 | PerlLIOIsatty(struct IPerlLIO* piPerl, int fd) |
810 | { |
811 | return nw_isatty(fd); |
812 | } |
813 | |
814 | int |
815 | PerlLIOLink(struct IPerlLIO* piPerl, const char*oldname, const char *newname) |
816 | { |
817 | return nw_link(oldname, newname); |
818 | } |
819 | |
820 | long |
821 | PerlLIOLseek(struct IPerlLIO* piPerl, int handle, long offset, int origin) |
822 | { |
823 | return nw_lseek(handle, offset, origin); |
824 | } |
825 | |
826 | int |
827 | PerlLIOLstat(struct IPerlLIO* piPerl, const char *path, struct stat *buffer) |
828 | { |
829 | return nw_stat(path, buffer); |
830 | } |
831 | |
832 | char* |
833 | PerlLIOMktemp(struct IPerlLIO* piPerl, char *Template) |
834 | { |
835 | return(nw_mktemp(Template)); |
836 | } |
837 | |
838 | int |
839 | PerlLIOOpen(struct IPerlLIO* piPerl, const char *filename, int oflag) |
840 | { |
841 | return nw_open(filename, oflag); |
842 | } |
843 | |
844 | int |
845 | PerlLIOOpen3(struct IPerlLIO* piPerl, const char *filename, int oflag, int pmode) |
846 | { |
847 | return nw_open(filename, oflag, pmode); |
848 | } |
849 | |
850 | int |
851 | PerlLIORead(struct IPerlLIO* piPerl, int handle, void *buffer, unsigned int count) |
852 | { |
853 | return nw_read(handle, buffer, count); |
854 | } |
855 | |
856 | int |
857 | PerlLIORename(struct IPerlLIO* piPerl, const char *OldFileName, const char *newname) |
858 | { |
859 | return nw_rename(OldFileName, newname); |
860 | } |
861 | |
862 | int |
863 | PerlLIOSetmode(struct IPerlLIO* piPerl, FILE *fp, int mode) |
864 | { |
865 | return nw_setmode(fp, mode); |
866 | } |
867 | |
868 | int |
869 | PerlLIONameStat(struct IPerlLIO* piPerl, const char *path, struct stat *buffer) |
870 | { |
871 | return nw_stat(path, buffer); |
872 | } |
873 | |
874 | char* |
875 | PerlLIOTmpnam(struct IPerlLIO* piPerl, char *string) |
876 | { |
877 | return tmpnam(string); |
878 | } |
879 | |
880 | int |
881 | PerlLIOUmask(struct IPerlLIO* piPerl, int pmode) |
882 | { |
883 | return umask(pmode); |
884 | } |
885 | |
886 | int |
887 | PerlLIOUnlink(struct IPerlLIO* piPerl, const char *filename) |
888 | { |
889 | return nw_unlink(filename); |
890 | } |
891 | |
892 | int |
893 | PerlLIOUtime(struct IPerlLIO* piPerl, char *filename, struct utimbuf *times) |
894 | { |
895 | return nw_utime(filename, times); |
896 | } |
897 | |
898 | int |
899 | PerlLIOWrite(struct IPerlLIO* piPerl, int handle, const void *buffer, unsigned int count) |
900 | { |
901 | return nw_write(handle, buffer, count); |
902 | } |
903 | |
904 | struct IPerlLIO perlLIO = |
905 | { |
906 | PerlLIOAccess, |
907 | PerlLIOChmod, |
908 | PerlLIOChown, |
909 | PerlLIOChsize, |
910 | PerlLIOClose, |
911 | PerlLIODup, |
912 | PerlLIODup2, |
913 | PerlLIOFlock, |
914 | PerlLIOFileStat, |
915 | PerlLIOIOCtl, |
916 | PerlLIOIsatty, |
917 | PerlLIOLink, |
918 | PerlLIOLseek, |
919 | PerlLIOLstat, |
920 | PerlLIOMktemp, |
921 | PerlLIOOpen, |
922 | PerlLIOOpen3, |
923 | PerlLIORead, |
924 | PerlLIORename, |
925 | PerlLIOSetmode, |
926 | PerlLIONameStat, |
927 | PerlLIOTmpnam, |
928 | PerlLIOUmask, |
929 | PerlLIOUnlink, |
930 | PerlLIOUtime, |
931 | PerlLIOWrite, |
932 | }; |
933 | |
934 | |
935 | #undef IPERL2HOST |
936 | #define IPERL2HOST(x) IPerlDir2Host(x) |
937 | |
938 | /* IPerlDIR */ |
939 | int |
940 | PerlDirMakedir(struct IPerlDir* piPerl, const char *dirname, int mode) |
941 | { |
942 | return mkdir(dirname); |
943 | } |
944 | |
945 | int |
946 | PerlDirChdir(struct IPerlDir* piPerl, const char *dirname) |
947 | { |
948 | return nw_chdir(dirname); |
949 | } |
950 | |
951 | int |
952 | PerlDirRmdir(struct IPerlDir* piPerl, const char *dirname) |
953 | { |
954 | return nw_rmdir(dirname); |
955 | } |
956 | |
957 | int |
958 | PerlDirClose(struct IPerlDir* piPerl, DIR *dirp) |
959 | { |
960 | return nw_closedir(dirp); |
961 | } |
962 | |
963 | DIR* |
964 | PerlDirOpen(struct IPerlDir* piPerl, char *filename) |
965 | { |
966 | return nw_opendir(filename); |
967 | } |
968 | |
969 | struct direct * |
970 | PerlDirRead(struct IPerlDir* piPerl, DIR *dirp) |
971 | { |
972 | return nw_readdir(dirp); |
973 | } |
974 | |
975 | void |
976 | PerlDirRewind(struct IPerlDir* piPerl, DIR *dirp) |
977 | { |
978 | nw_rewinddir(dirp); |
979 | } |
980 | |
981 | void |
982 | PerlDirSeek(struct IPerlDir* piPerl, DIR *dirp, long loc) |
983 | { |
984 | nw_seekdir(dirp, loc); |
985 | } |
986 | |
987 | long |
988 | PerlDirTell(struct IPerlDir* piPerl, DIR *dirp) |
989 | { |
990 | return nw_telldir(dirp); |
991 | } |
992 | |
993 | struct IPerlDir perlDir = |
994 | { |
995 | PerlDirMakedir, |
996 | PerlDirChdir, |
997 | PerlDirRmdir, |
998 | PerlDirClose, |
999 | PerlDirOpen, |
1000 | PerlDirRead, |
1001 | PerlDirRewind, |
1002 | PerlDirSeek, |
1003 | PerlDirTell, |
1004 | }; |
1005 | |
1006 | |
1007 | /* IPerlSock */ |
1008 | u_long |
1009 | PerlSockHtonl(struct IPerlSock* piPerl, u_long hostlong) |
1010 | { |
1011 | return(nw_htonl(hostlong)); |
1012 | } |
1013 | |
1014 | u_short |
1015 | PerlSockHtons(struct IPerlSock* piPerl, u_short hostshort) |
1016 | { |
1017 | return(nw_htons(hostshort)); |
1018 | } |
1019 | |
1020 | u_long |
1021 | PerlSockNtohl(struct IPerlSock* piPerl, u_long netlong) |
1022 | { |
1023 | return nw_ntohl(netlong); |
1024 | } |
1025 | |
1026 | u_short |
1027 | PerlSockNtohs(struct IPerlSock* piPerl, u_short netshort) |
1028 | { |
1029 | return nw_ntohs(netshort); |
1030 | } |
1031 | |
1032 | SOCKET PerlSockAccept(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* addr, int* addrlen) |
1033 | { |
1034 | return nw_accept(s, addr, addrlen); |
1035 | } |
1036 | |
1037 | int |
1038 | PerlSockBind(struct IPerlSock* piPerl, SOCKET s, const struct sockaddr* name, int namelen) |
1039 | { |
1040 | return nw_bind(s, name, namelen); |
1041 | } |
1042 | |
1043 | int |
1044 | PerlSockConnect(struct IPerlSock* piPerl, SOCKET s, const struct sockaddr* name, int namelen) |
1045 | { |
1046 | return nw_connect(s, name, namelen); |
1047 | } |
1048 | |
1049 | void |
1050 | PerlSockEndhostent(struct IPerlSock* piPerl) |
1051 | { |
1052 | nw_endhostent(); |
1053 | } |
1054 | |
1055 | void |
1056 | PerlSockEndnetent(struct IPerlSock* piPerl) |
1057 | { |
1058 | nw_endnetent(); |
1059 | } |
1060 | |
1061 | void |
1062 | PerlSockEndprotoent(struct IPerlSock* piPerl) |
1063 | { |
1064 | nw_endprotoent(); |
1065 | } |
1066 | |
1067 | void |
1068 | PerlSockEndservent(struct IPerlSock* piPerl) |
1069 | { |
1070 | nw_endservent(); |
1071 | } |
1072 | |
1073 | struct hostent* |
1074 | PerlSockGethostbyaddr(struct IPerlSock* piPerl, const char* addr, int len, int type) |
1075 | { |
1076 | return(nw_gethostbyaddr(addr,len,type)); |
1077 | } |
1078 | |
1079 | struct hostent* |
1080 | PerlSockGethostbyname(struct IPerlSock* piPerl, const char* name) |
1081 | { |
1082 | return nw_gethostbyname(name); |
1083 | } |
1084 | |
1085 | struct hostent* |
1086 | PerlSockGethostent(struct IPerlSock* piPerl) |
1087 | { |
1088 | return(nw_gethostent()); |
1089 | } |
1090 | |
1091 | int |
1092 | PerlSockGethostname(struct IPerlSock* piPerl, char* name, int namelen) |
1093 | { |
1094 | return nw_gethostname(name,namelen); |
1095 | } |
1096 | |
1097 | struct netent * |
1098 | PerlSockGetnetbyaddr(struct IPerlSock* piPerl, long net, int type) |
1099 | { |
1100 | return nw_getnetbyaddr(net, type); |
1101 | } |
1102 | |
1103 | struct netent * |
1104 | PerlSockGetnetbyname(struct IPerlSock* piPerl, const char *name) |
1105 | { |
1106 | return nw_getnetbyname((char*)name); |
1107 | } |
1108 | |
1109 | struct netent * |
1110 | PerlSockGetnetent(struct IPerlSock* piPerl) |
1111 | { |
1112 | return nw_getnetent(); |
1113 | } |
1114 | |
1115 | int PerlSockGetpeername(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* name, int* namelen) |
1116 | { |
1117 | return nw_getpeername(s, name, namelen); |
1118 | } |
1119 | |
1120 | struct protoent* |
1121 | PerlSockGetprotobyname(struct IPerlSock* piPerl, const char* name) |
1122 | { |
1123 | return nw_getprotobyname(name); |
1124 | } |
1125 | |
1126 | struct protoent* |
1127 | PerlSockGetprotobynumber(struct IPerlSock* piPerl, int number) |
1128 | { |
1129 | return nw_getprotobynumber(number); |
1130 | } |
1131 | |
1132 | struct protoent* |
1133 | PerlSockGetprotoent(struct IPerlSock* piPerl) |
1134 | { |
1135 | return nw_getprotoent(); |
1136 | } |
1137 | |
1138 | struct servent* |
1139 | PerlSockGetservbyname(struct IPerlSock* piPerl, const char* name, const char* proto) |
1140 | { |
1141 | return nw_getservbyname((char*)name, (char*)proto); |
1142 | } |
1143 | |
1144 | struct servent* |
1145 | PerlSockGetservbyport(struct IPerlSock* piPerl, int port, const char* proto) |
1146 | { |
1147 | return nw_getservbyport(port, proto); |
1148 | } |
1149 | |
1150 | struct servent* |
1151 | PerlSockGetservent(struct IPerlSock* piPerl) |
1152 | { |
1153 | return nw_getservent(); |
1154 | } |
1155 | |
1156 | int |
1157 | PerlSockGetsockname(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* name, int* namelen) |
1158 | { |
1159 | return nw_getsockname(s, name, namelen); |
1160 | } |
1161 | |
1162 | int |
1163 | PerlSockGetsockopt(struct IPerlSock* piPerl, SOCKET s, int level, int optname, char* optval, int* optlen) |
1164 | { |
1165 | return nw_getsockopt(s, level, optname, optval, optlen); |
1166 | } |
1167 | |
1168 | unsigned long |
1169 | PerlSockInetAddr(struct IPerlSock* piPerl, const char* cp) |
1170 | { |
1171 | return(nw_inet_addr(cp)); |
1172 | } |
1173 | |
1174 | char* |
1175 | PerlSockInetNtoa(struct IPerlSock* piPerl, struct in_addr in) |
1176 | { |
1177 | return nw_inet_ntoa(in); |
1178 | } |
1179 | |
1180 | int |
1181 | PerlSockListen(struct IPerlSock* piPerl, SOCKET s, int backlog) |
1182 | { |
1183 | return (nw_listen(s, backlog)); |
1184 | } |
1185 | |
1186 | int |
1187 | PerlSockRecv(struct IPerlSock* piPerl, SOCKET s, char* buffer, int len, int flags) |
1188 | { |
1189 | return (nw_recv(s, buffer, len, flags)); |
1190 | } |
1191 | |
1192 | int |
1193 | PerlSockRecvfrom(struct IPerlSock* piPerl, SOCKET s, char* buffer, int len, int flags, struct sockaddr* from, int* fromlen) |
1194 | { |
1195 | return nw_recvfrom(s, buffer, len, flags, from, fromlen); |
1196 | } |
1197 | |
1198 | int |
1199 | PerlSockSelect(struct IPerlSock* piPerl, int nfds, char* readfds, char* writefds, char* exceptfds, const struct timeval* timeout) |
1200 | { |
1201 | return nw_select(nfds, (fd_set*) readfds, (fd_set*) writefds, (fd_set*) exceptfds, timeout); |
1202 | } |
1203 | |
1204 | int |
1205 | PerlSockSend(struct IPerlSock* piPerl, SOCKET s, const char* buffer, int len, int flags) |
1206 | { |
1207 | return (nw_send(s, buffer, len, flags)); |
1208 | } |
1209 | |
1210 | int |
1211 | PerlSockSendto(struct IPerlSock* piPerl, SOCKET s, const char* buffer, int len, int flags, const struct sockaddr* to, int tolen) |
1212 | { |
1213 | return(nw_sendto(s, buffer, len, flags, to, tolen)); |
1214 | } |
1215 | |
1216 | void |
1217 | PerlSockSethostent(struct IPerlSock* piPerl, int stayopen) |
1218 | { |
1219 | nw_sethostent(stayopen); |
1220 | } |
1221 | |
1222 | void |
1223 | PerlSockSetnetent(struct IPerlSock* piPerl, int stayopen) |
1224 | { |
1225 | nw_setnetent(stayopen); |
1226 | } |
1227 | |
1228 | void |
1229 | PerlSockSetprotoent(struct IPerlSock* piPerl, int stayopen) |
1230 | { |
1231 | nw_setprotoent(stayopen); |
1232 | } |
1233 | |
1234 | void |
1235 | PerlSockSetservent(struct IPerlSock* piPerl, int stayopen) |
1236 | { |
1237 | nw_setservent(stayopen); |
1238 | } |
1239 | |
1240 | int |
1241 | PerlSockSetsockopt(struct IPerlSock* piPerl, SOCKET s, int level, int optname, const char* optval, int optlen) |
1242 | { |
1243 | return nw_setsockopt(s, level, optname, optval, optlen); |
1244 | } |
1245 | |
1246 | int |
1247 | PerlSockShutdown(struct IPerlSock* piPerl, SOCKET s, int how) |
1248 | { |
1249 | return nw_shutdown(s, how); |
1250 | } |
1251 | |
1252 | SOCKET |
1253 | PerlSockSocket(struct IPerlSock* piPerl, int af, int type, int protocol) |
1254 | { |
1255 | return nw_socket(af, type, protocol); |
1256 | } |
1257 | |
1258 | int |
1259 | PerlSockSocketpair(struct IPerlSock* piPerl, int domain, int type, int protocol, int* fds) |
1260 | { |
1261 | dTHX; // (J) dTHXo |
1262 | Perl_croak(aTHX_ "socketpair not implemented!\n"); |
1263 | return 0; |
1264 | } |
1265 | |
1266 | int |
1267 | PerlSockIoctlsocket(struct IPerlSock* piPerl, SOCKET s, long cmd, u_long *argp) |
1268 | { |
1269 | dTHX; // (J) dTHXo |
1270 | Perl_croak(aTHX_ "ioctlsocket not implemented!\n"); |
1271 | return 0; |
1272 | } |
1273 | |
1274 | struct IPerlSock perlSock = |
1275 | { |
1276 | PerlSockHtonl, |
1277 | PerlSockHtons, |
1278 | PerlSockNtohl, |
1279 | PerlSockNtohs, |
1280 | PerlSockAccept, |
1281 | PerlSockBind, |
1282 | PerlSockConnect, |
1283 | PerlSockEndhostent, |
1284 | PerlSockEndnetent, |
1285 | PerlSockEndprotoent, |
1286 | PerlSockEndservent, |
1287 | PerlSockGethostname, |
1288 | PerlSockGetpeername, |
1289 | PerlSockGethostbyaddr, |
1290 | PerlSockGethostbyname, |
1291 | PerlSockGethostent, |
1292 | PerlSockGetnetbyaddr, |
1293 | PerlSockGetnetbyname, |
1294 | PerlSockGetnetent, |
1295 | PerlSockGetprotobyname, |
1296 | PerlSockGetprotobynumber, |
1297 | PerlSockGetprotoent, |
1298 | PerlSockGetservbyname, |
1299 | PerlSockGetservbyport, |
1300 | PerlSockGetservent, |
1301 | PerlSockGetsockname, |
1302 | PerlSockGetsockopt, |
1303 | PerlSockInetAddr, |
1304 | PerlSockInetNtoa, |
1305 | PerlSockListen, |
1306 | PerlSockRecv, |
1307 | PerlSockRecvfrom, |
1308 | PerlSockSelect, |
1309 | PerlSockSend, |
1310 | PerlSockSendto, |
1311 | PerlSockSethostent, |
1312 | PerlSockSetnetent, |
1313 | PerlSockSetprotoent, |
1314 | PerlSockSetservent, |
1315 | PerlSockSetsockopt, |
1316 | PerlSockShutdown, |
1317 | PerlSockSocket, |
1318 | PerlSockSocketpair, |
1319 | //Following commented by sgp bcos of comiplation error too many initializers (E279) |
1320 | // PerlSockClosesocket, |
1321 | }; |
1322 | |
1323 | |
1324 | /* IPerlProc */ |
1325 | |
1326 | #define EXECF_EXEC 1 |
1327 | #define EXECF_SPAWN 2 |
1328 | |
1329 | void |
1330 | PerlProcAbort(struct IPerlProc* piPerl) |
1331 | { |
1332 | nw_abort(); |
1333 | } |
1334 | |
1335 | char * |
1336 | PerlProcCrypt(struct IPerlProc* piPerl, const char* clear, const char* salt) |
1337 | { |
1338 | return nw_crypt(clear, salt); |
1339 | } |
1340 | |
1341 | void |
1342 | PerlProcExit(struct IPerlProc* piPerl, int status) |
1343 | { |
1344 | // exit(status); |
1345 | dTHX; |
1346 | //dJMPENV; |
1347 | JMPENV_JUMP(2); |
1348 | } |
1349 | |
1350 | void |
1351 | PerlProc_Exit(struct IPerlProc* piPerl, int status) |
1352 | { |
1353 | // _exit(status); |
1354 | dTHX; |
1355 | //dJMPENV; |
1356 | JMPENV_JUMP(2); |
1357 | } |
1358 | |
1359 | int |
1360 | PerlProcExecl(struct IPerlProc* piPerl, const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3) |
1361 | { |
1362 | // If removed, compilation error occurs. |
1363 | return 0; |
1364 | } |
1365 | |
1366 | int |
1367 | PerlProcExecv(struct IPerlProc* piPerl, const char *cmdname, const char *const *argv) |
1368 | { |
1369 | return nw_execvp((char *)cmdname, (char **)argv); |
1370 | } |
1371 | |
1372 | int |
1373 | PerlProcExecvp(struct IPerlProc* piPerl, const char *cmdname, const char *const *argv) |
1374 | { |
1375 | return nw_execvp((char *)cmdname, (char **)argv); |
1376 | } |
1377 | |
1378 | uid_t |
1379 | PerlProcGetuid(struct IPerlProc* piPerl) |
1380 | { |
1381 | // If removed, compilation error occurs. |
1382 | return 0; |
1383 | } |
1384 | |
1385 | uid_t |
1386 | PerlProcGeteuid(struct IPerlProc* piPerl) |
1387 | { |
1388 | // If removed, compilation error occurs. |
1389 | return 0; |
1390 | } |
1391 | |
1392 | gid_t |
1393 | PerlProcGetgid(struct IPerlProc* piPerl) |
1394 | { |
1395 | // If removed, compilation error occurs. |
1396 | return 0; |
1397 | } |
1398 | |
1399 | gid_t |
1400 | PerlProcGetegid(struct IPerlProc* piPerl) |
1401 | { |
1402 | // If removed, compilation error occurs. |
1403 | return 0; |
1404 | } |
1405 | |
1406 | char * |
1407 | PerlProcGetlogin(struct IPerlProc* piPerl) |
1408 | { |
1409 | // If removed, compilation error occurs. |
1410 | return NULL; |
1411 | } |
1412 | |
1413 | int |
1414 | PerlProcKill(struct IPerlProc* piPerl, int pid, int sig) |
1415 | { |
1416 | return nw_kill(pid, sig); |
1417 | } |
1418 | |
1419 | int |
1420 | PerlProcKillpg(struct IPerlProc* piPerl, int pid, int sig) |
1421 | { |
1422 | dTHX; // (J) dTHXo |
1423 | Perl_croak(aTHX_ "killpg not implemented!\n"); |
1424 | return 0; |
1425 | } |
1426 | |
1427 | int |
1428 | PerlProcPauseProc(struct IPerlProc* piPerl) |
1429 | { |
1430 | return nw_sleep((32767L << 16) + 32767); |
1431 | } |
1432 | |
1433 | PerlIO* |
1434 | PerlProcPopen(struct IPerlProc* piPerl, const char *command, const char *mode) |
1435 | { |
1436 | dTHX; // (J) dTHXo |
1437 | PERL_FLUSHALL_FOR_CHILD; |
1438 | |
1439 | return (PerlIO*)nw_Popen((char *)command, (char *)mode, (int *)errno); |
1440 | } |
1441 | |
1442 | int |
1443 | PerlProcPclose(struct IPerlProc* piPerl, PerlIO *stream) |
1444 | { |
1445 | return nw_Pclose((FILE*)stream, (int *)errno); |
1446 | } |
1447 | |
1448 | int |
1449 | PerlProcPipe(struct IPerlProc* piPerl, int *phandles) |
1450 | { |
1451 | return nw_Pipe((int *)phandles, (int *)errno); |
1452 | } |
1453 | |
1454 | int |
1455 | PerlProcSetuid(struct IPerlProc* piPerl, uid_t u) |
1456 | { |
1457 | // If removed, compilation error occurs. |
1458 | return 0; |
1459 | } |
1460 | |
1461 | int |
1462 | PerlProcSetgid(struct IPerlProc* piPerl, gid_t g) |
1463 | { |
1464 | // If removed, compilation error occurs. |
1465 | return 0; |
1466 | } |
1467 | |
1468 | int |
1469 | PerlProcSleep(struct IPerlProc* piPerl, unsigned int s) |
1470 | { |
1471 | return nw_sleep(s); |
1472 | } |
1473 | |
1474 | int |
1475 | PerlProcTimes(struct IPerlProc* piPerl, struct tms *timebuf) |
1476 | { |
1477 | return nw_times(timebuf); |
1478 | } |
1479 | |
1480 | int |
1481 | PerlProcWait(struct IPerlProc* piPerl, int *status) |
1482 | { |
1483 | return nw_wait(status); |
1484 | } |
1485 | |
1486 | int |
1487 | PerlProcWaitpid(struct IPerlProc* piPerl, int pid, int *status, int flags) |
1488 | { |
1489 | return nw_waitpid(pid, status, flags); |
1490 | } |
1491 | |
1492 | Sighandler_t |
1493 | PerlProcSignal(struct IPerlProc* piPerl, int sig, Sighandler_t subcode) |
1494 | { |
1495 | // If removed, compilation error occurs. |
1496 | return 0; |
1497 | } |
1498 | |
1499 | int |
1500 | PerlProcFork(struct IPerlProc* piPerl) |
1501 | { |
1502 | // If removed, compilation error occurs. |
1503 | return 0; |
1504 | } |
1505 | |
1506 | int |
1507 | PerlProcGetpid(struct IPerlProc* piPerl) |
1508 | { |
1509 | return nw_getpid(); |
1510 | } |
1511 | |
1512 | BOOL |
1513 | PerlProcDoCmd(struct IPerlProc* piPerl, char *cmd) |
1514 | { |
1515 | do_spawn2(cmd, EXECF_EXEC); |
1516 | return FALSE; |
1517 | } |
1518 | |
1519 | int |
1520 | PerlProcSpawn(struct IPerlProc* piPerl, char* cmds) |
1521 | { |
1522 | return do_spawn2(cmds, EXECF_SPAWN); |
1523 | } |
1524 | |
1525 | int |
1526 | PerlProcSpawnvp(struct IPerlProc* piPerl, int mode, const char *cmdname, const char *const *argv) |
1527 | { |
1528 | return nw_spawnvp(mode, (char *)cmdname, (char **)argv); |
1529 | } |
1530 | |
1531 | int |
1532 | PerlProcASpawn(struct IPerlProc* piPerl, void *vreally, void **vmark, void **vsp) |
1533 | { |
1534 | return do_aspawn(vreally, vmark, vsp); |
1535 | } |
1536 | |
1537 | struct IPerlProc perlProc = |
1538 | { |
1539 | PerlProcAbort, |
1540 | PerlProcCrypt, |
1541 | PerlProcExit, |
1542 | PerlProc_Exit, |
1543 | PerlProcExecl, |
1544 | PerlProcExecv, |
1545 | PerlProcExecvp, |
1546 | PerlProcGetuid, |
1547 | PerlProcGeteuid, |
1548 | PerlProcGetgid, |
1549 | PerlProcGetegid, |
1550 | PerlProcGetlogin, |
1551 | PerlProcKill, |
1552 | PerlProcKillpg, |
1553 | PerlProcPauseProc, |
1554 | PerlProcPopen, |
1555 | PerlProcPclose, |
1556 | PerlProcPipe, |
1557 | PerlProcSetuid, |
1558 | PerlProcSetgid, |
1559 | PerlProcSleep, |
1560 | PerlProcTimes, |
1561 | PerlProcWait, |
1562 | PerlProcWaitpid, |
1563 | PerlProcSignal, |
1564 | PerlProcFork, |
1565 | PerlProcGetpid, |
1566 | /* PerlProcDynaLoader, |
1567 | PerlProcGetOSError, |
1568 | PerlProcDoCmd, |
1569 | PerlProcSpawn, |
1570 | PerlProcSpawnvp, |
1571 | PerlProcASpawn,*/ |
1572 | }; |
1573 | |
1574 | |
1575 | /* |
1576 | * CPerlHost |
1577 | */ |
1578 | |
1579 | CPerlHost::CPerlHost(void) |
1580 | { |
1581 | m_pVMem = new VMem(); |
1582 | m_pVMemShared = new VMem(); |
1583 | m_pVMemParse = new VMem(); |
1584 | |
1585 | memcpy(&m_hostperlMem, &perlMem, sizeof(perlMem)); |
1586 | memcpy(&m_hostperlMemShared, &perlMemShared, sizeof(perlMemShared)); |
1587 | memcpy(&m_hostperlMemParse, &perlMemParse, sizeof(perlMemParse)); |
1588 | memcpy(&m_hostperlEnv, &perlEnv, sizeof(perlEnv)); |
1589 | memcpy(&m_hostperlStdIO, &perlStdIO, sizeof(perlStdIO)); |
1590 | memcpy(&m_hostperlLIO, &perlLIO, sizeof(perlLIO)); |
1591 | memcpy(&m_hostperlDir, &perlDir, sizeof(perlDir)); |
1592 | memcpy(&m_hostperlSock, &perlSock, sizeof(perlSock)); |
1593 | memcpy(&m_hostperlProc, &perlProc, sizeof(perlProc)); |
1594 | |
1595 | m_pHostperlMem = &m_hostperlMem; |
1596 | m_pHostperlMemShared = &m_hostperlMemShared; |
1597 | m_pHostperlMemParse = &m_hostperlMemParse; |
1598 | m_pHostperlEnv = &m_hostperlEnv; |
1599 | m_pHostperlStdIO = &m_hostperlStdIO; |
1600 | m_pHostperlLIO = &m_hostperlLIO; |
1601 | m_pHostperlDir = &m_hostperlDir; |
1602 | m_pHostperlSock = &m_hostperlSock; |
1603 | m_pHostperlProc = &m_hostperlProc; |
1604 | } |
1605 | |
1606 | #define SETUPEXCHANGE(xptr, iptr, table) \ |
1607 | STMT_START { \ |
1608 | if (xptr) { \ |
1609 | iptr = *xptr; \ |
1610 | *xptr = &table; \ |
1611 | } \ |
1612 | else { \ |
1613 | iptr = &table; \ |
1614 | } \ |
1615 | } STMT_END |
1616 | |
1617 | CPerlHost::CPerlHost(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared, |
1618 | struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv, |
1619 | struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO, |
1620 | struct IPerlDir** ppDir, struct IPerlSock** ppSock, |
1621 | struct IPerlProc** ppProc) |
1622 | { |
1623 | m_pVMem = new VMem(); |
1624 | m_pVMemShared = new VMem(); |
1625 | m_pVMemParse = new VMem(); |
1626 | |
1627 | memcpy(&m_hostperlMem, &perlMem, sizeof(perlMem)); |
1628 | memcpy(&m_hostperlMemShared, &perlMemShared, sizeof(perlMemShared)); |
1629 | memcpy(&m_hostperlMemParse, &perlMemParse, sizeof(perlMemParse)); |
1630 | memcpy(&m_hostperlEnv, &perlEnv, sizeof(perlEnv)); |
1631 | memcpy(&m_hostperlStdIO, &perlStdIO, sizeof(perlStdIO)); |
1632 | memcpy(&m_hostperlLIO, &perlLIO, sizeof(perlLIO)); |
1633 | memcpy(&m_hostperlDir, &perlDir, sizeof(perlDir)); |
1634 | memcpy(&m_hostperlSock, &perlSock, sizeof(perlSock)); |
1635 | memcpy(&m_hostperlProc, &perlProc, sizeof(perlProc)); |
1636 | |
1637 | SETUPEXCHANGE(ppMem, m_pHostperlMem, m_hostperlMem); |
1638 | SETUPEXCHANGE(ppMemShared, m_pHostperlMemShared, m_hostperlMemShared); |
1639 | SETUPEXCHANGE(ppMemParse, m_pHostperlMemParse, m_hostperlMemParse); |
1640 | SETUPEXCHANGE(ppEnv, m_pHostperlEnv, m_hostperlEnv); |
1641 | SETUPEXCHANGE(ppStdIO, m_pHostperlStdIO, m_hostperlStdIO); |
1642 | SETUPEXCHANGE(ppLIO, m_pHostperlLIO, m_hostperlLIO); |
1643 | SETUPEXCHANGE(ppDir, m_pHostperlDir, m_hostperlDir); |
1644 | SETUPEXCHANGE(ppSock, m_pHostperlSock, m_hostperlSock); |
1645 | SETUPEXCHANGE(ppProc, m_pHostperlProc, m_hostperlProc); |
1646 | } |
1647 | #undef SETUPEXCHANGE |
1648 | |
1649 | CPerlHost::CPerlHost(const CPerlHost& host) |
1650 | { |
1651 | memcpy(&m_hostperlMem, &perlMem, sizeof(perlMem)); |
1652 | memcpy(&m_hostperlMemShared, &perlMemShared, sizeof(perlMemShared)); |
1653 | memcpy(&m_hostperlMemParse, &perlMemParse, sizeof(perlMemParse)); |
1654 | memcpy(&m_hostperlEnv, &perlEnv, sizeof(perlEnv)); |
1655 | memcpy(&m_hostperlStdIO, &perlStdIO, sizeof(perlStdIO)); |
1656 | memcpy(&m_hostperlLIO, &perlLIO, sizeof(perlLIO)); |
1657 | memcpy(&m_hostperlDir, &perlDir, sizeof(perlDir)); |
1658 | memcpy(&m_hostperlSock, &perlSock, sizeof(perlSock)); |
1659 | memcpy(&m_hostperlProc, &perlProc, sizeof(perlProc)); |
1660 | |
1661 | m_pHostperlMem = &m_hostperlMem; |
1662 | m_pHostperlMemShared = &m_hostperlMemShared; |
1663 | m_pHostperlMemParse = &m_hostperlMemParse; |
1664 | m_pHostperlEnv = &m_hostperlEnv; |
1665 | m_pHostperlStdIO = &m_hostperlStdIO; |
1666 | m_pHostperlLIO = &m_hostperlLIO; |
1667 | m_pHostperlDir = &m_hostperlDir; |
1668 | m_pHostperlSock = &m_hostperlSock; |
1669 | m_pHostperlProc = &m_hostperlProc; |
1670 | |
1671 | } |
1672 | |
1673 | CPerlHost::~CPerlHost(void) |
1674 | { |
1675 | if ( m_pVMemParse ) delete m_pVMemParse; |
1676 | if ( m_pVMemShared ) delete m_pVMemShared; |
1677 | if ( m_pVMem ) delete m_pVMem; |
1678 | } |
1679 | |
1680 | char* |
1681 | CPerlHost::Getenv(const char *varname) |
1682 | { |
1683 | // getenv is always present. In old CLIB, it is implemented |
1684 | // to always return NULL. With java loaded on NW411, it will |
1685 | // return values set by envset. Is correctly implemented by |
1686 | // CLIB on MOAB. |
1687 | // |
1688 | return getenv(varname); |
1689 | } |
1690 | |
1691 | int |
1692 | CPerlHost::Putenv(const char *envstring) |
1693 | { |
1694 | return(putenv(envstring)); |
1695 | } |
1696 | |
1697 | |
1698 | #endif /* ___NWPerlHost_H___ */ |
1699 | |