Commit | Line | Data |
2986a63f |
1 | /* |
2 | * Copyright © 2001 Novell, Inc. All Rights Reserved. |
3 | * |
4 | * You may distribute under the terms of either the GNU General Public |
5 | * License or the Artistic License, as specified in the README file. |
6 | * |
7 | */ |
8 | |
9 | /* |
8dbfbba0 |
10 | * FILENAME : nwperlsys.h |
11 | * DESCRIPTION : Derives from iperlsys.h and define the |
12 | * platform specific function |
13 | * Author : SGP |
14 | * Date Created : June 12th 2001. |
15 | * Date Modified: June 26th 2001. |
2986a63f |
16 | */ |
17 | |
18 | #ifndef ___NWPerlSys_H___ |
19 | #define ___NWPerlSys_H___ |
20 | |
21 | |
22 | #include "iperlsys.h" |
23 | |
8dbfbba0 |
24 | #include "nw5iop.h" |
25 | #include <fcntl.h> |
26 | |
2986a63f |
27 | //Socket related calls |
28 | #include "nw5sck.h" |
29 | |
30 | //Store the Watcom hash list |
31 | #include "nwtinfo.h" |
32 | |
33 | //Watcom hash list |
34 | #include <wchash.h> |
35 | |
8dbfbba0 |
36 | #include "win32ish.h" |
37 | |
38 | START_EXTERN_C |
39 | extern int do_spawn2(char *cmd, int exectype); |
40 | extern int do_aspawn(void *vreally, void **vmark, void **vsp); |
41 | extern void Perl_init_os_extras(void); |
42 | BOOL fnGetHashListAddrs(void *addrs, BOOL *dontTouchHashList); |
43 | END_EXTERN_C |
44 | |
45 | /* IPerlMem - Memory management functions - Begin ========================================*/ |
2986a63f |
46 | |
8dbfbba0 |
47 | void* |
48 | PerlMemMalloc(struct IPerlMem* piPerl, size_t size) |
49 | { |
50 | void *ptr = NULL; |
51 | ptr = malloc(size); |
52 | if (ptr) { |
53 | void **listptr; |
54 | BOOL m_dontTouchHashLists; |
55 | if(fnGetHashListAddrs(&listptr,&m_dontTouchHashLists)) { |
56 | if (listptr) { |
57 | WCValHashTable<void*>* m_allocList= (WCValHashTable<void*>*)listptr; |
58 | (WCValHashTable<void*>*)m_allocList->insert(ptr); |
59 | } |
60 | } |
61 | } |
62 | return(ptr); |
63 | } |
64 | |
65 | void* |
66 | PerlMemRealloc(struct IPerlMem* piPerl, void* ptr, size_t size) |
67 | { |
68 | void *newptr = NULL; |
69 | WCValHashTable<void*>* m_allocList; |
70 | |
71 | newptr = realloc(ptr, size); |
72 | |
73 | if (ptr) |
74 | { |
75 | void **listptr; |
76 | BOOL m_dontTouchHashLists; |
77 | if(fnGetHashListAddrs(&listptr,&m_dontTouchHashLists)) { |
78 | m_allocList= (WCValHashTable<void*>*)listptr; |
79 | (WCValHashTable<void*>*)m_allocList->remove(ptr); |
80 | } |
81 | } |
82 | if (newptr) |
83 | { |
84 | if (m_allocList) |
85 | (WCValHashTable<void*>*)m_allocList->insert(newptr); |
86 | } |
87 | |
88 | return(newptr); |
89 | } |
90 | |
91 | void |
92 | PerlMemFree(struct IPerlMem* piPerl, void* ptr) |
93 | { |
94 | BOOL m_dontTouchHashLists; |
95 | WCValHashTable<void*>* m_allocList; |
96 | |
97 | void **listptr; |
98 | if(fnGetHashListAddrs(&listptr,&m_dontTouchHashLists)) { |
99 | m_allocList= (WCValHashTable<void*>*)listptr; |
100 | // Final clean up, free all the nodes from the hash list |
101 | if (m_dontTouchHashLists) |
102 | { |
103 | if(ptr) |
104 | { |
105 | free(ptr); |
106 | ptr = NULL; |
107 | } |
108 | } |
109 | else |
110 | { |
111 | if(ptr && m_allocList) |
112 | { |
113 | if ((WCValHashTable<void*>*)m_allocList->remove(ptr)) |
114 | { |
115 | free(ptr); |
116 | ptr = NULL; |
117 | } |
118 | else |
119 | { |
120 | // If it comes here, that means that the memory pointer is not contained in the hash list. |
121 | // But no need to free now, since if is deleted here, it will result in an abend!! |
122 | // If the memory is still there, it will be cleaned during final cleanup anyway. |
123 | } |
124 | } |
125 | } |
126 | } |
127 | return; |
128 | } |
129 | |
130 | void* |
131 | PerlMemCalloc(struct IPerlMem* piPerl, size_t num, size_t size) |
132 | { |
133 | void *ptr = NULL; |
134 | |
135 | ptr = calloc(num, size); |
136 | if (ptr) { |
137 | void **listptr; |
138 | BOOL m_dontTouchHashLists; |
139 | if(fnGetHashListAddrs(&listptr,&m_dontTouchHashLists)) { |
140 | if (listptr) { |
141 | WCValHashTable<void*>* m_allocList= (WCValHashTable<void*>*)listptr; |
142 | (WCValHashTable<void*>*)m_allocList->insert(ptr); |
143 | } |
144 | } |
145 | } |
146 | return(ptr); |
147 | } |
2986a63f |
148 | |
149 | struct IPerlMem perlMem = |
150 | { |
151 | PerlMemMalloc, |
152 | PerlMemRealloc, |
153 | PerlMemFree, |
154 | PerlMemCalloc, |
155 | }; |
156 | |
8dbfbba0 |
157 | /* IPerlMem - Memory management functions - End ========================================*/ |
158 | |
159 | /* IPerlDir - Directory Manipulation functions - Begin ===================================*/ |
2986a63f |
160 | |
8dbfbba0 |
161 | int |
162 | PerlDirMakedir(struct IPerlDir* piPerl, const char *dirname, int mode) |
163 | { |
164 | return mkdir(dirname); |
165 | } |
2986a63f |
166 | |
8dbfbba0 |
167 | int |
168 | PerlDirChdir(struct IPerlDir* piPerl, const char *dirname) |
169 | { |
170 | return nw_chdir(dirname); |
171 | } |
172 | |
173 | int |
174 | PerlDirRmdir(struct IPerlDir* piPerl, const char *dirname) |
175 | { |
176 | return nw_rmdir(dirname); |
177 | } |
178 | |
179 | int |
180 | PerlDirClose(struct IPerlDir* piPerl, DIR *dirp) |
181 | { |
182 | return nw_closedir(dirp); |
183 | } |
184 | |
185 | DIR* |
186 | PerlDirOpen(struct IPerlDir* piPerl, char *filename) |
187 | { |
188 | return nw_opendir(filename); |
189 | } |
190 | |
191 | struct direct * |
192 | PerlDirRead(struct IPerlDir* piPerl, DIR *dirp) |
193 | { |
194 | return nw_readdir(dirp); |
195 | } |
196 | |
197 | void |
198 | PerlDirRewind(struct IPerlDir* piPerl, DIR *dirp) |
199 | { |
200 | nw_rewinddir(dirp); |
201 | } |
202 | |
203 | void |
204 | PerlDirSeek(struct IPerlDir* piPerl, DIR *dirp, long loc) |
205 | { |
206 | nw_seekdir(dirp, loc); |
207 | } |
208 | |
209 | long |
210 | PerlDirTell(struct IPerlDir* piPerl, DIR *dirp) |
211 | { |
212 | return nw_telldir(dirp); |
213 | } |
2986a63f |
214 | |
215 | struct IPerlDir perlDir = |
216 | { |
217 | PerlDirMakedir, |
218 | PerlDirChdir, |
219 | PerlDirRmdir, |
220 | PerlDirClose, |
221 | PerlDirOpen, |
222 | PerlDirRead, |
223 | PerlDirRewind, |
224 | PerlDirSeek, |
225 | PerlDirTell, |
226 | }; |
227 | |
8dbfbba0 |
228 | /* IPerlDir - Directory Manipulation functions - End ===================================*/ |
2986a63f |
229 | |
230 | /* IPerlEnv - Environment related functions - Begin ======================================*/ |
231 | |
8dbfbba0 |
232 | char* |
233 | PerlEnvGetenv(struct IPerlEnv* piPerl, const char *varname) |
234 | { |
235 | return(getenv(varname)); |
236 | }; |
237 | |
238 | int |
239 | PerlEnvPutenv(struct IPerlEnv* piPerl, const char *envstring) |
240 | { |
241 | return(putenv(envstring)); |
242 | }; |
243 | |
244 | char* |
245 | PerlEnvGetenv_len(struct IPerlEnv* piPerl, const char* varname, unsigned long* len) |
246 | { |
247 | *len = 0; |
248 | char *e = getenv(varname); |
249 | if (e) |
250 | *len = strlen(e); |
251 | return e; |
252 | } |
2986a63f |
253 | |
8dbfbba0 |
254 | int |
255 | PerlEnvUname(struct IPerlEnv* piPerl, struct utsname *name) |
256 | { |
257 | return nw_uname(name); |
258 | } |
2986a63f |
259 | |
8dbfbba0 |
260 | void |
261 | PerlEnvClearenv(struct IPerlEnv* piPerl) |
262 | { |
263 | |
264 | } |
2986a63f |
265 | |
266 | struct IPerlEnv perlEnv = |
267 | { |
268 | PerlEnvGetenv, |
269 | PerlEnvPutenv, |
270 | PerlEnvGetenv_len, |
271 | PerlEnvUname, |
272 | PerlEnvClearenv, |
273 | /* PerlEnvGetChildenv, |
274 | PerlEnvFreeChildenv, |
275 | PerlEnvGetChilddir, |
276 | PerlEnvFreeChilddir,*/ |
277 | }; |
278 | |
8dbfbba0 |
279 | /* IPerlEnv - Environment related functions - End ======================================*/ |
2986a63f |
280 | |
281 | /* IPerlStdio - Stdio functions - Begin ================================================*/ |
282 | |
8dbfbba0 |
283 | FILE* |
284 | PerlStdIOStdin(struct IPerlStdIO* piPerl) |
285 | { |
286 | return nw_stdin(); |
287 | } |
288 | |
289 | FILE* |
290 | PerlStdIOStdout(struct IPerlStdIO* piPerl) |
291 | { |
292 | return nw_stdout(); |
293 | } |
294 | |
295 | FILE* |
296 | PerlStdIOStderr(struct IPerlStdIO* piPerl) |
297 | { |
298 | return nw_stderr(); |
299 | } |
300 | |
301 | FILE* |
302 | PerlStdIOOpen(struct IPerlStdIO* piPerl, const char *path, const char *mode) |
303 | { |
304 | return nw_fopen(path, mode); |
305 | } |
306 | |
307 | int |
308 | PerlStdIOClose(struct IPerlStdIO* piPerl, FILE* pf) |
309 | { |
310 | return nw_fclose(pf); |
311 | } |
312 | |
313 | int |
314 | PerlStdIOEof(struct IPerlStdIO* piPerl, FILE* pf) |
315 | { |
316 | return nw_feof(pf); |
317 | } |
318 | |
319 | int |
320 | PerlStdIOError(struct IPerlStdIO* piPerl, FILE* pf) |
321 | { |
322 | return nw_ferror(pf); |
323 | } |
324 | |
325 | void |
326 | PerlStdIOClearerr(struct IPerlStdIO* piPerl, FILE* pf) |
327 | { |
328 | nw_clearerr(pf); |
329 | } |
330 | |
331 | int |
332 | PerlStdIOGetc(struct IPerlStdIO* piPerl, FILE* pf) |
333 | { |
334 | return nw_getc(pf); |
335 | } |
336 | |
337 | char* |
338 | PerlStdIOGetBase(struct IPerlStdIO* piPerl, FILE* pf) |
339 | { |
340 | #ifdef FILE_base |
341 | FILE *f = pf; |
342 | return FILE_base(f); |
343 | #else |
344 | return Nullch; |
345 | #endif |
346 | } |
347 | |
348 | int |
349 | PerlStdIOGetBufsiz(struct IPerlStdIO* piPerl, FILE* pf) |
350 | { |
351 | #ifdef FILE_bufsiz |
352 | FILE *f = pf; |
353 | return FILE_bufsiz(f); |
354 | #else |
355 | return (-1); |
356 | #endif |
357 | } |
358 | |
359 | int |
360 | PerlStdIOGetCnt(struct IPerlStdIO* piPerl, FILE* pf) |
361 | { |
362 | #ifdef USE_STDIO_PTR |
363 | FILE *f = pf; |
364 | return FILE_cnt(f); |
365 | #else |
366 | return (-1); |
367 | #endif |
368 | } |
369 | |
370 | char* |
371 | PerlStdIOGetPtr(struct IPerlStdIO* piPerl, FILE* pf) |
372 | { |
373 | #ifdef USE_STDIO_PTR |
374 | FILE *f = pf; |
375 | return FILE_ptr(f); |
376 | #else |
377 | return Nullch; |
378 | #endif |
379 | } |
380 | |
381 | char* |
382 | PerlStdIOGets(struct IPerlStdIO* piPerl, FILE* pf, char* s, int n) |
383 | { |
384 | return nw_fgets(s, n, pf); |
385 | } |
386 | |
387 | int |
388 | PerlStdIOPutc(struct IPerlStdIO* piPerl, FILE* pf, int c) |
389 | { |
390 | return nw_fputc(c, pf); |
391 | } |
392 | |
393 | int |
394 | PerlStdIOPuts(struct IPerlStdIO* piPerl, FILE* pf, const char *s) |
395 | { |
396 | return nw_fputs(s, pf); |
397 | } |
398 | |
399 | int |
400 | PerlStdIOFlush(struct IPerlStdIO* piPerl, FILE* pf) |
401 | { |
402 | return nw_fflush(pf); |
403 | } |
404 | |
405 | int |
406 | PerlStdIOUngetc(struct IPerlStdIO* piPerl, int c, FILE* pf) |
407 | { |
408 | return nw_ungetc(c, pf); |
409 | } |
410 | |
411 | int |
412 | PerlStdIOFileno(struct IPerlStdIO* piPerl, FILE* pf) |
413 | { |
414 | return nw_fileno(pf); |
415 | } |
416 | |
417 | FILE* |
418 | PerlStdIOFdopen(struct IPerlStdIO* piPerl, int fd, const char *mode) |
419 | { |
420 | return nw_fdopen(fd, mode); |
421 | } |
422 | |
423 | FILE* |
424 | PerlStdIOReopen(struct IPerlStdIO* piPerl, const char*path, const char*mode, FILE* pf) |
425 | { |
426 | return nw_freopen(path, mode, pf); |
427 | } |
428 | |
429 | SSize_t |
430 | PerlStdIORead(struct IPerlStdIO* piPerl, void *buffer, Size_t size, Size_t count, FILE* pf) |
431 | { |
432 | return nw_fread(buffer, size, count, pf); |
433 | } |
434 | |
435 | SSize_t |
436 | PerlStdIOWrite(struct IPerlStdIO* piPerl, const void *buffer, Size_t size, Size_t count, FILE* pf) |
437 | { |
438 | return nw_fwrite(buffer, size, count, pf); |
439 | } |
440 | |
441 | void |
442 | PerlStdIOSetBuf(struct IPerlStdIO* piPerl, FILE* pf, char* buffer) |
443 | { |
444 | nw_setbuf(pf, buffer); |
445 | } |
446 | |
447 | int |
448 | PerlStdIOSetVBuf(struct IPerlStdIO* piPerl, FILE* pf, char* buffer, int type, Size_t size) |
449 | { |
450 | return nw_setvbuf(pf, buffer, type, size); |
451 | } |
452 | |
453 | void |
454 | PerlStdIOSetCnt(struct IPerlStdIO* piPerl, FILE* pf, int n) |
455 | { |
456 | #ifdef STDIO_CNT_LVALUE |
457 | FILE *f = pf; |
458 | FILE_cnt(f) = n; |
459 | #endif |
460 | } |
461 | |
462 | void |
463 | PerlStdIOSetPtr(struct IPerlStdIO* piPerl, FILE* pf, char * ptr) |
464 | { |
465 | #ifdef STDIO_PTR_LVALUE |
466 | FILE *f = pf; |
467 | FILE_ptr(f) = ptr; |
468 | #endif |
469 | } |
470 | |
471 | void |
472 | PerlStdIOSetlinebuf(struct IPerlStdIO* piPerl, FILE* pf) |
473 | { |
474 | nw_setvbuf(pf, NULL, _IOLBF, 0); |
475 | } |
476 | |
477 | int |
478 | PerlStdIOPrintf(struct IPerlStdIO* piPerl, FILE* pf, const char *format,...) |
479 | { |
480 | va_list(arglist); |
481 | va_start(arglist, format); |
482 | return nw_vfprintf(pf, format, arglist); |
483 | } |
484 | |
485 | int |
486 | PerlStdIOVprintf(struct IPerlStdIO* piPerl, FILE* pf, const char *format, va_list arglist) |
487 | { |
488 | return nw_vfprintf(pf, format, arglist); |
489 | } |
490 | |
491 | long |
492 | PerlStdIOTell(struct IPerlStdIO* piPerl, FILE* pf) |
493 | { |
494 | return nw_ftell(pf); |
495 | } |
496 | |
497 | int |
498 | PerlStdIOSeek(struct IPerlStdIO* piPerl, FILE* pf, off_t offset, int origin) |
499 | { |
500 | return nw_fseek(pf, offset, origin); |
501 | } |
502 | |
503 | void |
504 | PerlStdIORewind(struct IPerlStdIO* piPerl, FILE* pf) |
505 | { |
506 | nw_rewind(pf); |
507 | } |
508 | |
509 | FILE* |
510 | PerlStdIOTmpfile(struct IPerlStdIO* piPerl) |
511 | { |
512 | return nw_tmpfile(); |
513 | } |
514 | |
515 | int |
516 | PerlStdIOGetpos(struct IPerlStdIO* piPerl, FILE* pf, Fpos_t *p) |
517 | { |
518 | return nw_fgetpos(pf, p); |
519 | } |
520 | |
521 | int |
522 | PerlStdIOSetpos(struct IPerlStdIO* piPerl, FILE* pf, const Fpos_t *p) |
523 | { |
524 | return nw_fsetpos(pf, p); |
525 | } |
526 | |
527 | void |
528 | PerlStdIOInit(struct IPerlStdIO* piPerl) |
529 | { |
530 | } |
531 | |
532 | void |
533 | PerlStdIOInitOSExtras(struct IPerlStdIO* piPerl) |
534 | { |
535 | Perl_init_os_extras(); |
536 | } |
537 | |
538 | |
539 | int |
540 | PerlStdIOOpenOSfhandle(struct IPerlStdIO* piPerl, long osfhandle, int flags) |
541 | { |
542 | return nw_open_osfhandle(osfhandle, flags); |
543 | } |
544 | |
545 | int |
546 | PerlStdIOGetOSfhandle(struct IPerlStdIO* piPerl, int filenum) |
547 | { |
548 | return nw_get_osfhandle(filenum); |
549 | } |
550 | |
551 | FILE* |
552 | PerlStdIOFdupopen(struct IPerlStdIO* piPerl, FILE* pf) |
553 | { |
554 | FILE* pfdup=NULL; |
555 | fpos_t pos=0; |
556 | char mode[3]={'\0'}; |
557 | int fileno = nw_dup(nw_fileno(pf)); |
558 | |
559 | /* open the file in the same mode */ |
560 | if(((FILE*)pf)->_flag & _IOREAD) { |
561 | mode[0] = 'r'; |
562 | mode[1] = 0; |
563 | } |
564 | else if(((FILE*)pf)->_flag & _IOWRT) { |
565 | mode[0] = 'a'; |
566 | mode[1] = 0; |
567 | } |
568 | else if(((FILE*)pf)->_flag & _IORW) { |
569 | mode[0] = 'r'; |
570 | mode[1] = '+'; |
571 | mode[2] = 0; |
572 | } |
573 | |
574 | /* it appears that the binmode is attached to the |
575 | * file descriptor so binmode files will be handled |
576 | * correctly |
577 | */ |
578 | pfdup = nw_fdopen(fileno, mode); |
579 | |
580 | /* move the file pointer to the same position */ |
581 | if (!fgetpos(pf, &pos)) { |
582 | fsetpos(pfdup, &pos); |
583 | } |
584 | return pfdup; |
585 | } |
2986a63f |
586 | |
587 | struct IPerlStdIO perlStdIO = |
588 | { |
589 | PerlStdIOStdin, |
590 | PerlStdIOStdout, |
591 | PerlStdIOStderr, |
592 | PerlStdIOOpen, |
593 | PerlStdIOClose, |
594 | PerlStdIOEof, |
595 | PerlStdIOError, |
596 | PerlStdIOClearerr, |
597 | PerlStdIOGetc, |
598 | PerlStdIOGetBase, |
599 | PerlStdIOGetBufsiz, |
600 | PerlStdIOGetCnt, |
601 | PerlStdIOGetPtr, |
602 | PerlStdIOGets, |
603 | PerlStdIOPutc, |
604 | PerlStdIOPuts, |
605 | PerlStdIOFlush, |
606 | PerlStdIOUngetc, |
607 | PerlStdIOFileno, |
608 | PerlStdIOFdopen, |
609 | PerlStdIOReopen, |
610 | PerlStdIORead, |
611 | PerlStdIOWrite, |
612 | PerlStdIOSetBuf, |
613 | PerlStdIOSetVBuf, |
614 | PerlStdIOSetCnt, |
615 | PerlStdIOSetPtr, |
616 | PerlStdIOSetlinebuf, |
617 | PerlStdIOPrintf, |
618 | PerlStdIOVprintf, |
619 | PerlStdIOTell, |
620 | PerlStdIOSeek, |
621 | PerlStdIORewind, |
622 | PerlStdIOTmpfile, |
623 | PerlStdIOGetpos, |
624 | PerlStdIOSetpos, |
625 | PerlStdIOInit, |
626 | PerlStdIOInitOSExtras, |
627 | PerlStdIOFdupopen, |
628 | }; |
629 | |
630 | /* IPerlStdio - Stdio functions - End ================================================*/ |
631 | |
632 | /* IPerlLIO - Low-level IO functions - Begin =============================================*/ |
633 | |
8dbfbba0 |
634 | int |
635 | PerlLIOAccess(struct IPerlLIO* piPerl, const char *path, int mode) |
636 | { |
637 | return nw_access(path, mode); |
638 | } |
639 | |
640 | int |
641 | PerlLIOChmod(struct IPerlLIO* piPerl, const char *filename, int pmode) |
642 | { |
643 | return nw_chmod(filename, pmode); |
644 | } |
645 | |
646 | int |
647 | PerlLIOChown(struct IPerlLIO* piPerl, const char *filename, uid_t owner, gid_t group) |
648 | { |
649 | dTHXo; |
650 | Perl_croak(aTHX_ "chown not implemented!\n"); |
651 | return 0; |
652 | } |
653 | |
654 | int |
655 | PerlLIOChsize(struct IPerlLIO* piPerl, int handle, long size) |
656 | { |
657 | return (nw_chsize(handle,size)); |
658 | } |
659 | |
660 | int |
661 | PerlLIOClose(struct IPerlLIO* piPerl, int handle) |
662 | { |
663 | return nw_close(handle); |
664 | } |
665 | |
666 | int |
667 | PerlLIODup(struct IPerlLIO* piPerl, int handle) |
668 | { |
669 | return nw_dup(handle); |
670 | } |
671 | |
672 | int |
673 | PerlLIODup2(struct IPerlLIO* piPerl, int handle1, int handle2) |
674 | { |
675 | return nw_dup2(handle1, handle2); |
676 | } |
677 | |
678 | int |
679 | PerlLIOFlock(struct IPerlLIO* piPerl, int fd, int oper) |
680 | { |
681 | //On NetWare simulate flock by locking a range on the file |
682 | return nw_flock(fd, oper); |
683 | } |
684 | |
685 | int |
686 | PerlLIOFileStat(struct IPerlLIO* piPerl, int handle, struct stat *buffer) |
687 | { |
688 | return fstat(handle, buffer); |
689 | } |
690 | |
691 | int |
692 | PerlLIOIOCtl(struct IPerlLIO* piPerl, int i, unsigned int u, char *data) |
693 | { |
694 | return 0; |
695 | } |
696 | |
697 | int |
698 | PerlLIOIsatty(struct IPerlLIO* piPerl, int fd) |
699 | { |
700 | return nw_isatty(fd); |
701 | } |
702 | |
703 | int |
704 | PerlLIOLink(struct IPerlLIO* piPerl, const char*oldname, const char *newname) |
705 | { |
706 | return nw_link(oldname, newname); |
707 | } |
708 | |
709 | long |
710 | PerlLIOLseek(struct IPerlLIO* piPerl, int handle, long offset, int origin) |
711 | { |
712 | return nw_lseek(handle, offset, origin); |
713 | } |
714 | |
715 | int |
716 | PerlLIOLstat(struct IPerlLIO* piPerl, const char *path, struct stat *buffer) |
717 | { |
718 | return nw_stat(path, buffer); |
719 | } |
720 | |
721 | char* |
722 | PerlLIOMktemp(struct IPerlLIO* piPerl, char *Template) |
723 | { |
724 | return(nw_mktemp(Template)); |
725 | } |
726 | |
727 | int |
728 | PerlLIOOpen(struct IPerlLIO* piPerl, const char *filename, int oflag) |
729 | { |
730 | return nw_open(filename, oflag); |
731 | } |
732 | |
733 | int |
734 | PerlLIOOpen3(struct IPerlLIO* piPerl, const char *filename, int oflag, int pmode) |
735 | { |
736 | return nw_open(filename, oflag, pmode); |
737 | } |
738 | |
739 | int |
740 | PerlLIORead(struct IPerlLIO* piPerl, int handle, void *buffer, unsigned int count) |
741 | { |
742 | return nw_read(handle, buffer, count); |
743 | } |
744 | |
745 | int |
746 | PerlLIORename(struct IPerlLIO* piPerl, const char *OldFileName, const char *newname) |
747 | { |
748 | return nw_rename(OldFileName, newname); |
749 | } |
750 | |
751 | int |
752 | PerlLIOSetmode(struct IPerlLIO* piPerl, FILE *fp, int mode) |
753 | { |
754 | return nw_setmode(fp, mode); |
755 | } |
756 | |
757 | int |
758 | PerlLIONameStat(struct IPerlLIO* piPerl, const char *path, struct stat *buffer) |
759 | { |
760 | return nw_stat(path, buffer); |
761 | } |
762 | |
763 | char* |
764 | PerlLIOTmpnam(struct IPerlLIO* piPerl, char *string) |
765 | { |
766 | return tmpnam(string); |
767 | } |
768 | |
769 | int |
770 | PerlLIOUmask(struct IPerlLIO* piPerl, int pmode) |
771 | { |
772 | return umask(pmode); |
773 | } |
774 | |
775 | int |
776 | PerlLIOUnlink(struct IPerlLIO* piPerl, const char *filename) |
777 | { |
778 | return nw_unlink(filename); |
779 | } |
780 | |
781 | int |
782 | PerlLIOUtime(struct IPerlLIO* piPerl, char *filename, struct utimbuf *times) |
783 | { |
784 | return nw_utime(filename, times); |
785 | } |
786 | |
787 | int |
788 | PerlLIOWrite(struct IPerlLIO* piPerl, int handle, const void *buffer, unsigned int count) |
789 | { |
790 | return nw_write(handle, buffer, count); |
791 | } |
2986a63f |
792 | |
793 | struct IPerlLIO perlLIO = |
794 | { |
795 | PerlLIOAccess, |
796 | PerlLIOChmod, |
797 | PerlLIOChown, |
798 | PerlLIOChsize, |
799 | PerlLIOClose, |
800 | PerlLIODup, |
801 | PerlLIODup2, |
802 | PerlLIOFlock, |
803 | PerlLIOFileStat, |
804 | PerlLIOIOCtl, |
805 | PerlLIOIsatty, |
806 | PerlLIOLink, |
807 | PerlLIOLseek, |
808 | PerlLIOLstat, |
809 | PerlLIOMktemp, |
810 | PerlLIOOpen, |
811 | PerlLIOOpen3, |
812 | PerlLIORead, |
813 | PerlLIORename, |
814 | PerlLIOSetmode, |
815 | PerlLIONameStat, |
816 | PerlLIOTmpnam, |
817 | PerlLIOUmask, |
818 | PerlLIOUnlink, |
819 | PerlLIOUtime, |
820 | PerlLIOWrite, |
821 | }; |
822 | |
8dbfbba0 |
823 | /* IPerlLIO - Low-level IO functions - End =============================================*/ |
2986a63f |
824 | |
825 | /* IPerlProc - Process control functions - Begin =========================================*/ |
826 | |
8dbfbba0 |
827 | #define EXECF_EXEC 1 |
828 | #define EXECF_SPAWN 2 |
829 | |
830 | void |
831 | PerlProcAbort(struct IPerlProc* piPerl) |
832 | { |
833 | nw_abort(); |
834 | } |
835 | |
836 | char * |
837 | PerlProcCrypt(struct IPerlProc* piPerl, const char* clear, const char* salt) |
838 | { |
839 | return nw_crypt(clear, salt); |
840 | } |
841 | |
842 | void |
843 | PerlProcExit(struct IPerlProc* piPerl, int status) |
844 | { |
845 | // exit(status); |
846 | dTHX; |
847 | dJMPENV; |
848 | JMPENV_JUMP(2); |
849 | } |
850 | |
851 | void |
852 | PerlProc_Exit(struct IPerlProc* piPerl, int status) |
853 | { |
854 | // _exit(status); |
855 | dTHX; |
856 | dJMPENV; |
857 | JMPENV_JUMP(2); |
858 | } |
859 | |
860 | int |
861 | PerlProcExecl(struct IPerlProc* piPerl, const char *cmdname, const char *arg0, const char *arg1, const char *arg2, const char *arg3) |
862 | { |
863 | dTHXo; |
864 | Perl_croak(aTHX_ "execl not implemented!\n"); |
865 | return 0; |
866 | } |
867 | |
868 | int |
869 | PerlProcExecv(struct IPerlProc* piPerl, const char *cmdname, const char *const *argv) |
870 | { |
871 | return nw_execvp((char *)cmdname, (char **)argv); |
872 | } |
873 | |
874 | int |
875 | PerlProcExecvp(struct IPerlProc* piPerl, const char *cmdname, const char *const *argv) |
876 | { |
877 | return nw_execvp((char *)cmdname, (char **)argv); |
878 | } |
879 | |
880 | uid_t |
881 | PerlProcGetuid(struct IPerlProc* piPerl) |
882 | { |
883 | return 0; |
884 | } |
885 | |
886 | uid_t |
887 | PerlProcGeteuid(struct IPerlProc* piPerl) |
888 | { |
889 | return 0; |
890 | } |
891 | |
892 | gid_t |
893 | PerlProcGetgid(struct IPerlProc* piPerl) |
894 | { |
895 | return 0; |
896 | } |
897 | |
898 | gid_t |
899 | PerlProcGetegid(struct IPerlProc* piPerl) |
900 | { |
901 | return 0; |
902 | } |
903 | |
904 | char * |
905 | PerlProcGetlogin(struct IPerlProc* piPerl) |
906 | { |
907 | return NULL; |
908 | } |
909 | |
910 | int |
911 | PerlProcKill(struct IPerlProc* piPerl, int pid, int sig) |
912 | { |
913 | return nw_kill(pid, sig); |
914 | } |
915 | |
916 | int |
917 | PerlProcKillpg(struct IPerlProc* piPerl, int pid, int sig) |
918 | { |
919 | dTHXo; |
920 | Perl_croak(aTHX_ "killpg not implemented!\n"); |
921 | return 0; |
922 | } |
923 | |
924 | int |
925 | PerlProcPauseProc(struct IPerlProc* piPerl) |
926 | { |
927 | return nw_sleep((32767L << 16) + 32767); |
928 | } |
929 | |
930 | PerlIO* |
931 | PerlProcPopen(struct IPerlProc* piPerl, const char *command, const char *mode) |
932 | { |
933 | dTHXo; |
934 | PERL_FLUSHALL_FOR_CHILD; |
935 | |
936 | return (PerlIO*)nw_Popen((char *)command, (char *)mode, (int *)errno); |
937 | } |
938 | |
939 | int |
940 | PerlProcPclose(struct IPerlProc* piPerl, PerlIO *stream) |
941 | { |
942 | return nw_Pclose((FILE*)stream, (int *)errno); |
943 | } |
944 | |
945 | int |
946 | PerlProcPipe(struct IPerlProc* piPerl, int *phandles) |
947 | { |
948 | return nw_Pipe((int *)phandles, (int *)errno); |
949 | } |
950 | |
951 | int |
952 | PerlProcSetuid(struct IPerlProc* piPerl, uid_t u) |
953 | { |
954 | return 0; |
955 | } |
956 | |
957 | int |
958 | PerlProcSetgid(struct IPerlProc* piPerl, gid_t g) |
959 | { |
960 | return 0; |
961 | } |
962 | |
963 | int |
964 | PerlProcSleep(struct IPerlProc* piPerl, unsigned int s) |
965 | { |
966 | return nw_sleep(s); |
967 | } |
968 | |
969 | int |
970 | PerlProcTimes(struct IPerlProc* piPerl, struct tms *timebuf) |
971 | { |
972 | return nw_times(timebuf); |
973 | } |
974 | |
975 | int |
976 | PerlProcWait(struct IPerlProc* piPerl, int *status) |
977 | { |
978 | return nw_wait(status); |
979 | } |
980 | |
981 | int |
982 | PerlProcWaitpid(struct IPerlProc* piPerl, int pid, int *status, int flags) |
983 | { |
984 | return nw_waitpid(pid, status, flags); |
985 | } |
986 | |
987 | Sighandler_t |
988 | PerlProcSignal(struct IPerlProc* piPerl, int sig, Sighandler_t subcode) |
989 | { |
990 | return 0; |
991 | } |
992 | |
993 | int |
994 | PerlProcFork(struct IPerlProc* piPerl) |
995 | { |
996 | return 0; |
997 | } |
998 | |
999 | int |
1000 | PerlProcGetpid(struct IPerlProc* piPerl) |
1001 | { |
1002 | return nw_getpid(); |
1003 | } |
1004 | |
1005 | /*BOOL |
1006 | PerlProcDoCmd(struct IPerlProc* piPerl, char *cmd) |
1007 | { |
1008 | do_spawn2(cmd, EXECF_EXEC); |
1009 | return FALSE; |
1010 | }*/ |
1011 | |
1012 | int |
1013 | PerlProcSpawn(struct IPerlProc* piPerl, char* cmds) |
1014 | { |
1015 | return do_spawn2(cmds, EXECF_SPAWN); |
1016 | } |
1017 | |
1018 | int |
1019 | PerlProcSpawnvp(struct IPerlProc* piPerl, int mode, const char *cmdname, const char *const *argv) |
1020 | { |
1021 | return nw_spawnvp(mode, (char *)cmdname, (char **)argv); |
1022 | } |
1023 | |
1024 | int |
1025 | PerlProcASpawn(struct IPerlProc* piPerl, void *vreally, void **vmark, void **vsp) |
1026 | { |
1027 | return do_aspawn(vreally, vmark, vsp); |
1028 | } |
2986a63f |
1029 | |
1030 | struct IPerlProc perlProc = |
1031 | { |
1032 | PerlProcAbort, |
1033 | PerlProcCrypt, |
1034 | PerlProcExit, |
1035 | PerlProc_Exit, |
1036 | PerlProcExecl, |
1037 | PerlProcExecv, |
1038 | PerlProcExecvp, |
1039 | PerlProcGetuid, |
1040 | PerlProcGeteuid, |
1041 | PerlProcGetgid, |
1042 | PerlProcGetegid, |
1043 | PerlProcGetlogin, |
1044 | PerlProcKill, |
1045 | PerlProcKillpg, |
1046 | PerlProcPauseProc, |
1047 | PerlProcPopen, |
1048 | PerlProcPclose, |
1049 | PerlProcPipe, |
1050 | PerlProcSetuid, |
1051 | PerlProcSetgid, |
1052 | PerlProcSleep, |
1053 | PerlProcTimes, |
1054 | PerlProcWait, |
1055 | PerlProcWaitpid, |
1056 | PerlProcSignal, |
1057 | PerlProcFork, |
1058 | PerlProcGetpid, |
1059 | //PerlProcLastHost; |
1060 | //PerlProcPopenList; |
1061 | }; |
1062 | |
1063 | /* IPerlProc - Process control functions - End =========================================*/ |
1064 | |
1065 | /* IPerlSock - Socket functions - Begin ==================================================*/ |
1066 | |
8dbfbba0 |
1067 | u_long |
1068 | PerlSockHtonl(struct IPerlSock* piPerl, u_long hostlong) |
1069 | { |
1070 | return(nw_htonl(hostlong)); |
1071 | } |
1072 | |
1073 | u_short |
1074 | PerlSockHtons(struct IPerlSock* piPerl, u_short hostshort) |
1075 | { |
1076 | return(nw_htons(hostshort)); |
1077 | } |
1078 | |
1079 | u_long |
1080 | PerlSockNtohl(struct IPerlSock* piPerl, u_long netlong) |
1081 | { |
1082 | return nw_ntohl(netlong); |
1083 | } |
1084 | |
1085 | u_short |
1086 | PerlSockNtohs(struct IPerlSock* piPerl, u_short netshort) |
1087 | { |
1088 | return nw_ntohs(netshort); |
1089 | } |
1090 | |
1091 | SOCKET PerlSockAccept(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* addr, int* addrlen) |
1092 | { |
1093 | return nw_accept(s, addr, addrlen); |
1094 | } |
1095 | |
1096 | int |
1097 | PerlSockBind(struct IPerlSock* piPerl, SOCKET s, const struct sockaddr* name, int namelen) |
1098 | { |
1099 | return nw_bind(s, name, namelen); |
1100 | } |
1101 | |
1102 | int |
1103 | PerlSockConnect(struct IPerlSock* piPerl, SOCKET s, const struct sockaddr* name, int namelen) |
1104 | { |
1105 | return nw_connect(s, name, namelen); |
1106 | } |
1107 | |
1108 | void |
1109 | PerlSockEndhostent(struct IPerlSock* piPerl) |
1110 | { |
1111 | nw_endhostent(); |
1112 | } |
1113 | |
1114 | void |
1115 | PerlSockEndnetent(struct IPerlSock* piPerl) |
1116 | { |
1117 | nw_endnetent(); |
1118 | } |
1119 | |
1120 | void |
1121 | PerlSockEndprotoent(struct IPerlSock* piPerl) |
1122 | { |
1123 | nw_endprotoent(); |
1124 | } |
1125 | |
1126 | void |
1127 | PerlSockEndservent(struct IPerlSock* piPerl) |
1128 | { |
1129 | nw_endservent(); |
1130 | } |
1131 | |
1132 | struct hostent* |
1133 | PerlSockGethostbyaddr(struct IPerlSock* piPerl, const char* addr, int len, int type) |
1134 | { |
1135 | return(nw_gethostbyaddr(addr,len,type)); |
1136 | } |
1137 | |
1138 | struct hostent* |
1139 | PerlSockGethostbyname(struct IPerlSock* piPerl, const char* name) |
1140 | { |
1141 | return nw_gethostbyname(name); |
1142 | } |
1143 | |
1144 | struct hostent* |
1145 | PerlSockGethostent(struct IPerlSock* piPerl) |
1146 | { |
1147 | return(nw_gethostent()); |
1148 | } |
1149 | |
1150 | int |
1151 | PerlSockGethostname(struct IPerlSock* piPerl, char* name, int namelen) |
1152 | { |
1153 | return nw_gethostname(name,namelen); |
1154 | } |
1155 | |
1156 | struct netent * |
1157 | PerlSockGetnetbyaddr(struct IPerlSock* piPerl, long net, int type) |
1158 | { |
1159 | return nw_getnetbyaddr(net, type); |
1160 | } |
1161 | |
1162 | struct netent * |
1163 | PerlSockGetnetbyname(struct IPerlSock* piPerl, const char *name) |
1164 | { |
1165 | return nw_getnetbyname((char*)name); |
1166 | } |
1167 | |
1168 | struct netent * |
1169 | PerlSockGetnetent(struct IPerlSock* piPerl) |
1170 | { |
1171 | return nw_getnetent(); |
1172 | } |
1173 | |
1174 | int PerlSockGetpeername(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* name, int* namelen) |
1175 | { |
1176 | return nw_getpeername(s, name, namelen); |
1177 | } |
1178 | |
1179 | struct protoent* |
1180 | PerlSockGetprotobyname(struct IPerlSock* piPerl, const char* name) |
1181 | { |
1182 | return nw_getprotobyname(name); |
1183 | } |
1184 | |
1185 | struct protoent* |
1186 | PerlSockGetprotobynumber(struct IPerlSock* piPerl, int number) |
1187 | { |
1188 | return nw_getprotobynumber(number); |
1189 | } |
1190 | |
1191 | struct protoent* |
1192 | PerlSockGetprotoent(struct IPerlSock* piPerl) |
1193 | { |
1194 | return nw_getprotoent(); |
1195 | } |
1196 | |
1197 | struct servent* |
1198 | PerlSockGetservbyname(struct IPerlSock* piPerl, const char* name, const char* proto) |
1199 | { |
1200 | return nw_getservbyname((char*)name, (char*)proto); |
1201 | } |
1202 | |
1203 | struct servent* |
1204 | PerlSockGetservbyport(struct IPerlSock* piPerl, int port, const char* proto) |
1205 | { |
1206 | return nw_getservbyport(port, proto); |
1207 | } |
1208 | |
1209 | struct servent* |
1210 | PerlSockGetservent(struct IPerlSock* piPerl) |
1211 | { |
1212 | return nw_getservent(); |
1213 | } |
1214 | |
1215 | int |
1216 | PerlSockGetsockname(struct IPerlSock* piPerl, SOCKET s, struct sockaddr* name, int* namelen) |
1217 | { |
1218 | return nw_getsockname(s, name, namelen); |
1219 | } |
1220 | |
1221 | int |
1222 | PerlSockGetsockopt(struct IPerlSock* piPerl, SOCKET s, int level, int optname, char* optval, int* optlen) |
1223 | { |
1224 | return nw_getsockopt(s, level, optname, optval, optlen); |
1225 | } |
1226 | |
1227 | unsigned long |
1228 | PerlSockInetAddr(struct IPerlSock* piPerl, const char* cp) |
1229 | { |
1230 | return(nw_inet_addr(cp)); |
1231 | } |
1232 | |
1233 | char* |
1234 | PerlSockInetNtoa(struct IPerlSock* piPerl, struct in_addr in) |
1235 | { |
1236 | return NULL; |
1237 | } |
1238 | |
1239 | int |
1240 | PerlSockListen(struct IPerlSock* piPerl, SOCKET s, int backlog) |
1241 | { |
1242 | return (nw_listen(s, backlog)); |
1243 | } |
1244 | |
1245 | int |
1246 | PerlSockRecv(struct IPerlSock* piPerl, SOCKET s, char* buffer, int len, int flags) |
1247 | { |
1248 | return (nw_recv(s, buffer, len, flags)); |
1249 | } |
1250 | |
1251 | int |
1252 | PerlSockRecvfrom(struct IPerlSock* piPerl, SOCKET s, char* buffer, int len, int flags, struct sockaddr* from, int* fromlen) |
1253 | { |
1254 | return nw_recvfrom(s, buffer, len, flags, from, fromlen); |
1255 | } |
1256 | |
1257 | int |
1258 | PerlSockSelect(struct IPerlSock* piPerl, int nfds, char* readfds, char* writefds, char* exceptfds, const struct timeval* timeout) |
1259 | { |
1260 | return nw_select(nfds, (fd_set*) readfds, (fd_set*) writefds, (fd_set*) exceptfds, timeout); |
1261 | } |
1262 | |
1263 | int |
1264 | PerlSockSend(struct IPerlSock* piPerl, SOCKET s, const char* buffer, int len, int flags) |
1265 | { |
1266 | return (nw_send(s, buffer, len, flags)); |
1267 | } |
1268 | |
1269 | int |
1270 | PerlSockSendto(struct IPerlSock* piPerl, SOCKET s, const char* buffer, int len, int flags, const struct sockaddr* to, int tolen) |
1271 | { |
1272 | return(nw_sendto(s, buffer, len, flags, to, tolen)); |
1273 | } |
1274 | |
1275 | void |
1276 | PerlSockSethostent(struct IPerlSock* piPerl, int stayopen) |
1277 | { |
1278 | nw_sethostent(stayopen); |
1279 | } |
1280 | |
1281 | void |
1282 | PerlSockSetnetent(struct IPerlSock* piPerl, int stayopen) |
1283 | { |
1284 | nw_setnetent(stayopen); |
1285 | } |
1286 | |
1287 | void |
1288 | PerlSockSetprotoent(struct IPerlSock* piPerl, int stayopen) |
1289 | { |
1290 | nw_setprotoent(stayopen); |
1291 | } |
1292 | |
1293 | void |
1294 | PerlSockSetservent(struct IPerlSock* piPerl, int stayopen) |
1295 | { |
1296 | nw_setservent(stayopen); |
1297 | } |
1298 | |
1299 | int |
1300 | PerlSockSetsockopt(struct IPerlSock* piPerl, SOCKET s, int level, int optname, const char* optval, int optlen) |
1301 | { |
1302 | dTHXo; |
1303 | Perl_croak(aTHX_ "setsockopt not implemented!\n"); |
1304 | return 0; |
1305 | } |
1306 | |
1307 | int |
1308 | PerlSockShutdown(struct IPerlSock* piPerl, SOCKET s, int how) |
1309 | { |
1310 | return nw_shutdown(s, how); |
1311 | } |
1312 | |
1313 | SOCKET |
1314 | PerlSockSocket(struct IPerlSock* piPerl, int af, int type, int protocol) |
1315 | { |
1316 | return nw_socket(af, type, protocol); |
1317 | } |
1318 | |
1319 | int |
1320 | PerlSockSocketpair(struct IPerlSock* piPerl, int domain, int type, int protocol, int* fds) |
1321 | { |
1322 | dTHXo; |
1323 | Perl_croak(aTHX_ "socketpair not implemented!\n"); |
1324 | return 0; |
1325 | } |
1326 | |
1327 | int |
1328 | PerlSockIoctlsocket(struct IPerlSock* piPerl, SOCKET s, long cmd, u_long *argp) |
1329 | { |
1330 | dTHXo; |
1331 | Perl_croak(aTHX_ "ioctlsocket not implemented!\n"); |
1332 | return 0; |
1333 | } |
2986a63f |
1334 | |
1335 | struct IPerlSock perlSock = |
1336 | { |
1337 | PerlSockHtonl, |
1338 | PerlSockHtons, |
1339 | PerlSockNtohl, |
1340 | PerlSockNtohs, |
1341 | PerlSockAccept, |
1342 | PerlSockBind, |
1343 | PerlSockConnect, |
1344 | PerlSockEndhostent, |
1345 | PerlSockEndnetent, |
1346 | PerlSockEndprotoent, |
1347 | PerlSockEndservent, |
1348 | PerlSockGethostname, |
1349 | PerlSockGetpeername, |
1350 | PerlSockGethostbyaddr, |
1351 | PerlSockGethostbyname, |
1352 | PerlSockGethostent, |
1353 | PerlSockGetnetbyaddr, |
1354 | PerlSockGetnetbyname, |
1355 | PerlSockGetnetent, |
1356 | PerlSockGetprotobyname, |
1357 | PerlSockGetprotobynumber, |
1358 | PerlSockGetprotoent, |
1359 | PerlSockGetservbyname, |
1360 | PerlSockGetservbyport, |
1361 | PerlSockGetservent, |
1362 | PerlSockGetsockname, |
1363 | PerlSockGetsockopt, |
1364 | PerlSockInetAddr, |
1365 | PerlSockInetNtoa, |
1366 | PerlSockListen, |
1367 | PerlSockRecv, |
1368 | PerlSockRecvfrom, |
1369 | PerlSockSelect, |
1370 | PerlSockSend, |
1371 | PerlSockSendto, |
1372 | PerlSockSethostent, |
1373 | PerlSockSetnetent, |
1374 | PerlSockSetprotoent, |
1375 | PerlSockSetservent, |
1376 | PerlSockSetsockopt, |
1377 | PerlSockShutdown, |
1378 | PerlSockSocket, |
1379 | PerlSockSocketpair, |
1380 | }; |
1381 | |
8dbfbba0 |
1382 | /* IPerlSock - Socket functions - End ==================================================*/ |
2986a63f |
1383 | |
1384 | #endif /* ___NWPerlSys_H___ */ |