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