patch up egcs-1.1.2-mingw32 build (builds a working miniperl, but not
[p5sagit/p5-mst-13.2.git] / iperlsys.h
1 /*
2  * iperlsys.h - Perl's interface to the system
3  *
4  * This file defines the system level functionality that perl needs.
5  *
6  * When using C, this definition is in the form of a set of macros
7  * that can be #defined to the system-level function (or a wrapper
8  * provided elsewhere).
9  *
10  * When using C++ with -DPERL_OBJECT, this definition is in the
11  * form of a set of virtual base classes which must be subclassed to
12  * provide a real implementation.  The Perl Object will use instances
13  * of this implementation to use the system-level functionality.
14  *
15  * GSAR 21-JUN-98
16  */
17
18 #ifndef __Inc__IPerl___
19 #define __Inc__IPerl___
20
21 /*
22  *      PerlXXX_YYY explained - DickH and DougL @ ActiveState.com
23  *
24  * XXX := functional group
25  * YYY := stdlib/OS function name
26  *
27  * Continuing with the theme of PerlIO, all OS functionality was
28  * encapsulated into one of several interfaces.
29  *
30  * PerlIO - stdio
31  * PerlLIO - low level I/O
32  * PerlMem - malloc, realloc, free
33  * PerlDir - directory related
34  * PerlEnv - process environment handling
35  * PerlProc - process control
36  * PerlSock - socket functions
37  *
38  *
39  * The features of this are:
40  * 1. All OS dependant code is in the Perl Host and not the Perl Core.
41  *    (At least this is the holy grail goal of this work)
42  * 2. The Perl Host (see perl.h for description) can provide a new and
43  *    improved interface to OS functionality if required.
44  * 3. Developers can easily hook into the OS calls for instrumentation
45  *    or diagnostic purposes.
46  *
47  * What was changed to do this:
48  * 1. All calls to OS functions were replaced with PerlXXX_YYY
49  *
50  */
51
52
53 /*
54     Interface for perl stdio functions
55 */
56
57
58 /* Clean up (or at least document) the various possible #defines.
59    This section attempts to match the 5.003_03 Configure variables
60    onto the 5.003_02 header file values.
61    I can't figure out where USE_STDIO was supposed to be set.
62    --AD
63 */
64 #ifndef USE_PERLIO
65 # define PERLIO_IS_STDIO
66 #endif
67
68 /* Below is the 5.003_02 stuff. */
69 #ifdef USE_STDIO
70 #  ifndef PERLIO_IS_STDIO
71 #      define PERLIO_IS_STDIO
72 #  endif
73 #else
74 extern void PerlIO_init (void);
75 #endif
76
77 #ifndef Sighandler_t
78 typedef Signal_t (*Sighandler_t) (int);
79 #endif
80
81 #if defined(PERL_IMPLICIT_SYS)
82
83 #ifndef PerlIO
84 typedef struct _PerlIO PerlIO;
85 #endif
86
87 /* IPerlStdIO           */
88 struct IPerlStdIO;
89 typedef PerlIO*         (*LPStdin)(struct IPerlStdIO*);
90 typedef PerlIO*         (*LPStdout)(struct IPerlStdIO*);
91 typedef PerlIO*         (*LPStderr)(struct IPerlStdIO*);
92 typedef PerlIO*         (*LPOpen)(struct IPerlStdIO*, const char*,
93                             const char*);
94 typedef int             (*LPClose)(struct IPerlStdIO*, PerlIO*);
95 typedef int             (*LPEof)(struct IPerlStdIO*, PerlIO*);
96 typedef int             (*LPError)(struct IPerlStdIO*, PerlIO*);
97 typedef void            (*LPClearerr)(struct IPerlStdIO*, PerlIO*);
98 typedef int             (*LPGetc)(struct IPerlStdIO*, PerlIO*);
99 typedef char*           (*LPGetBase)(struct IPerlStdIO*, PerlIO*);
100 typedef int             (*LPGetBufsiz)(struct IPerlStdIO*, PerlIO*);
101 typedef int             (*LPGetCnt)(struct IPerlStdIO*, PerlIO*);
102 typedef char*           (*LPGetPtr)(struct IPerlStdIO*, PerlIO*);
103 typedef char*           (*LPGets)(struct IPerlStdIO*, PerlIO*, char*, int);
104 typedef int             (*LPPutc)(struct IPerlStdIO*, PerlIO*, int);
105 typedef int             (*LPPuts)(struct IPerlStdIO*, PerlIO*, const char*);
106 typedef int             (*LPFlush)(struct IPerlStdIO*, PerlIO*);
107 typedef int             (*LPUngetc)(struct IPerlStdIO*, PerlIO*,int);
108 typedef int             (*LPFileno)(struct IPerlStdIO*, PerlIO*);
109 typedef PerlIO*         (*LPFdopen)(struct IPerlStdIO*, int, const char*);
110 typedef PerlIO*         (*LPReopen)(struct IPerlStdIO*, const char*,
111                             const char*, PerlIO*);
112 typedef SSize_t         (*LPRead)(struct IPerlStdIO*, PerlIO*, void*, Size_t);
113 typedef SSize_t         (*LPWrite)(struct IPerlStdIO*, PerlIO*, const void*,
114                             Size_t);
115 typedef void            (*LPSetBuf)(struct IPerlStdIO*, PerlIO*, char*);
116 typedef int             (*LPSetVBuf)(struct IPerlStdIO*, PerlIO*, char*, int,
117                             Size_t);
118 typedef void            (*LPSetCnt)(struct IPerlStdIO*, PerlIO*, int);
119 typedef void            (*LPSetPtrCnt)(struct IPerlStdIO*, PerlIO*, char*,
120                             int);
121 typedef void            (*LPSetlinebuf)(struct IPerlStdIO*, PerlIO*);
122 typedef int             (*LPPrintf)(struct IPerlStdIO*, PerlIO*, const char*, 
123                             ...);
124 typedef int             (*LPVprintf)(struct IPerlStdIO*, PerlIO*, const char*,
125                             va_list);
126 typedef long            (*LPTell)(struct IPerlStdIO*, PerlIO*);
127 typedef int             (*LPSeek)(struct IPerlStdIO*, PerlIO*, Off_t, int);
128 typedef void            (*LPRewind)(struct IPerlStdIO*, PerlIO*);
129 typedef PerlIO*         (*LPTmpfile)(struct IPerlStdIO*);
130 typedef int             (*LPGetpos)(struct IPerlStdIO*, PerlIO*, Fpos_t*);
131 typedef int             (*LPSetpos)(struct IPerlStdIO*, PerlIO*,
132                             const Fpos_t*);
133 typedef void            (*LPInit)(struct IPerlStdIO*);
134 typedef void            (*LPInitOSExtras)(struct IPerlStdIO*);
135
136 struct IPerlStdIO
137 {
138     LPStdin             pStdin;
139     LPStdout            pStdout;
140     LPStderr            pStderr;
141     LPOpen              pOpen;
142     LPClose             pClose;
143     LPEof               pEof;
144     LPError             pError;
145     LPClearerr          pClearerr;
146     LPGetc              pGetc;
147     LPGetBase           pGetBase;
148     LPGetBufsiz         pGetBufsiz;
149     LPGetCnt            pGetCnt;
150     LPGetPtr            pGetPtr;
151     LPGets              pGets;
152     LPPutc              pPutc;
153     LPPuts              pPuts;
154     LPFlush             pFlush;
155     LPUngetc            pUngetc;
156     LPFileno            pFileno;
157     LPFdopen            pFdopen;
158     LPReopen            pReopen;
159     LPRead              pRead;
160     LPWrite             pWrite;
161     LPSetBuf            pSetBuf;
162     LPSetVBuf           pSetVBuf;
163     LPSetCnt            pSetCnt;
164     LPSetPtrCnt         pSetPtrCnt;
165     LPSetlinebuf        pSetlinebuf;
166     LPPrintf            pPrintf;
167     LPVprintf           pVprintf;
168     LPTell              pTell;
169     LPSeek              pSeek;
170     LPRewind            pRewind;
171     LPTmpfile           pTmpfile;
172     LPGetpos            pGetpos;
173     LPSetpos            pSetpos;
174     LPInit              pInit;
175     LPInitOSExtras      pInitOSExtras;
176 };
177
178 struct IPerlStdIOInfo
179 {
180     unsigned long       nCount;     /* number of entries expected */
181     struct IPerlStdIO   perlStdIOList;
182 };
183
184 #ifdef USE_STDIO_PTR
185 #  define PerlIO_has_cntptr(f)          1       
186 #  ifdef STDIO_CNT_LVALUE
187 #    define PerlIO_canset_cnt(f)        1      
188 #    ifdef STDIO_PTR_LVALUE
189 #      define PerlIO_fast_gets(f)       1        
190 #    endif
191 #  else
192 #    define PerlIO_canset_cnt(f)        0      
193 #  endif
194 #else  /* USE_STDIO_PTR */
195 #  define PerlIO_has_cntptr(f)          0
196 #  define PerlIO_canset_cnt(f)          0
197 #endif /* USE_STDIO_PTR */
198
199 #ifndef PerlIO_fast_gets
200 #define PerlIO_fast_gets(f)             0        
201 #endif
202
203 #ifdef FILE_base
204 #define PerlIO_has_base(f)              1
205 #else
206 #define PerlIO_has_base(f)              0
207 #endif
208
209 #define PerlIO_stdin()                                                  \
210         (*PL_StdIO->pStdin)(PL_StdIO)
211 #define PerlIO_stdout()                                                 \
212         (*PL_StdIO->pStdout)(PL_StdIO)
213 #define PerlIO_stderr()                                                 \
214         (*PL_StdIO->pStderr)(PL_StdIO)
215 #define PerlIO_open(x,y)                                                \
216         (*PL_StdIO->pOpen)(PL_StdIO, (x),(y))
217 #define PerlIO_close(f)                                                 \
218         (*PL_StdIO->pClose)(PL_StdIO, (f))
219 #define PerlIO_eof(f)                                                   \
220         (*PL_StdIO->pEof)(PL_StdIO, (f))
221 #define PerlIO_error(f)                                                 \
222         (*PL_StdIO->pError)(PL_StdIO, (f))
223 #define PerlIO_clearerr(f)                                              \
224         (*PL_StdIO->pClearerr)(PL_StdIO, (f))
225 #define PerlIO_getc(f)                                                  \
226         (*PL_StdIO->pGetc)(PL_StdIO, (f))
227 #define PerlIO_get_base(f)                                              \
228         (*PL_StdIO->pGetBase)(PL_StdIO, (f))
229 #define PerlIO_get_bufsiz(f)                                            \
230         (*PL_StdIO->pGetBufsiz)(PL_StdIO, (f))
231 #define PerlIO_get_cnt(f)                                               \
232         (*PL_StdIO->pGetCnt)(PL_StdIO, (f))
233 #define PerlIO_get_ptr(f)                                               \
234         (*PL_StdIO->pGetPtr)(PL_StdIO, (f))
235 #define PerlIO_putc(f,c)                                                \
236         (*PL_StdIO->pPutc)(PL_StdIO, (f),(c))
237 #define PerlIO_puts(f,s)                                                \
238         (*PL_StdIO->pPuts)(PL_StdIO, (f),(s))
239 #define PerlIO_flush(f)                                                 \
240         (*PL_StdIO->pFlush)(PL_StdIO, (f))
241 #define PerlIO_gets(s, n, fp)                                           \
242         (*PL_StdIO->pGets)(PL_StdIO, (fp), s, n)
243 #define PerlIO_ungetc(f,c)                                              \
244         (*PL_StdIO->pUngetc)(PL_StdIO, (f),(c))
245 #define PerlIO_fileno(f)                                                \
246         (*PL_StdIO->pFileno)(PL_StdIO, (f))
247 #define PerlIO_fdopen(f, s)                                             \
248         (*PL_StdIO->pFdopen)(PL_StdIO, (f),(s))
249 #define PerlIO_reopen(p, m, f)                                          \
250         (*PL_StdIO->pReopen)(PL_StdIO, (p), (m), (f))
251 #define PerlIO_read(f,buf,count)                                        \
252         (SSize_t)(*PL_StdIO->pRead)(PL_StdIO, (f), (buf), (count))
253 #define PerlIO_write(f,buf,count)                                       \
254         (*PL_StdIO->pWrite)(PL_StdIO, (f), (buf), (count))
255 #define PerlIO_setbuf(f,b)                                              \
256         (*PL_StdIO->pSetBuf)(PL_StdIO, (f), (b))
257 #define PerlIO_setvbuf(f,b,t,s)                                         \
258         (*PL_StdIO->pSetVBuf)(PL_StdIO, (f),(b),(t),(s))
259 #define PerlIO_set_cnt(f,c)                                             \
260         (*PL_StdIO->pSetCnt)(PL_StdIO, (f), (c))
261 #define PerlIO_set_ptrcnt(f,p,c)                                        \
262         (*PL_StdIO->pSetPtrCnt)(PL_StdIO, (f), (p), (c))
263 #define PerlIO_setlinebuf(f)                                            \
264         (*PL_StdIO->pSetlinebuf)(PL_StdIO, (f))
265 #define PerlIO_printf           Perl_fprintf_nocontext
266 #define PerlIO_stdoutf          *PL_StdIO->pPrintf
267 #define PerlIO_vprintf(f,fmt,a)                                         \
268         (*PL_StdIO->pVprintf)(PL_StdIO, (f),(fmt),a)          
269 #define PerlIO_tell(f)                                                  \
270         (*PL_StdIO->pTell)(PL_StdIO, (f))
271 #define PerlIO_seek(f,o,w)                                              \
272         (*PL_StdIO->pSeek)(PL_StdIO, (f),(o),(w))
273 #define PerlIO_getpos(f,p)                                              \
274         (*PL_StdIO->pGetpos)(PL_StdIO, (f),(p))
275 #define PerlIO_setpos(f,p)                                              \
276         (*PL_StdIO->pSetpos)(PL_StdIO, (f),(p))
277 #define PerlIO_rewind(f)                                                \
278         (*PL_StdIO->pRewind)(PL_StdIO, (f))
279 #define PerlIO_tmpfile()                                                \
280         (*PL_StdIO->pTmpfile)(PL_StdIO)
281 #define PerlIO_init()                                                   \
282         (*PL_StdIO->pInit)(PL_StdIO)
283 #undef  init_os_extras
284 #define init_os_extras()                                                \
285         (*PL_StdIO->pInitOSExtras)(PL_StdIO)
286
287 #else   /* PERL_IMPLICIT_SYS */
288
289 #include "perlsdio.h"
290 #include "perl.h"
291
292 #endif  /* PERL_IMPLICIT_SYS */
293
294 #ifndef PERLIO_IS_STDIO
295 #ifdef USE_SFIO
296 #include "perlsfio.h"
297 #endif /* USE_SFIO */
298 #endif /* PERLIO_IS_STDIO */
299
300 #ifndef EOF
301 #define EOF (-1)
302 #endif
303
304 /* This is to catch case with no stdio */
305 #ifndef BUFSIZ
306 #define BUFSIZ 1024
307 #endif
308
309 #ifndef SEEK_SET
310 #define SEEK_SET 0
311 #endif
312
313 #ifndef SEEK_CUR
314 #define SEEK_CUR 1
315 #endif
316
317 #ifndef SEEK_END
318 #define SEEK_END 2
319 #endif
320
321 #ifndef PerlIO
322 struct _PerlIO;
323 #define PerlIO struct _PerlIO
324 #endif /* No PerlIO */
325
326 #ifndef Fpos_t
327 #define Fpos_t long
328 #endif
329
330 #ifndef NEXT30_NO_ATTRIBUTE
331 #ifndef HASATTRIBUTE       /* disable GNU-cc attribute checking? */
332 #ifdef  __attribute__      /* Avoid possible redefinition errors */
333 #undef  __attribute__
334 #endif
335 #define __attribute__(attr)
336 #endif
337 #endif
338
339 #ifndef PerlIO_stdoutf
340 extern int      PerlIO_stdoutf          (const char *,...)
341                                         __attribute__((format (printf, 1, 2)));
342 #endif
343 #ifndef PerlIO_puts
344 extern int      PerlIO_puts             (PerlIO *,const char *);
345 #endif
346 #ifndef PerlIO_open
347 extern PerlIO * PerlIO_open             (const char *,const char *);
348 #endif
349 #ifndef PerlIO_close
350 extern int      PerlIO_close            (PerlIO *);
351 #endif
352 #ifndef PerlIO_eof
353 extern int      PerlIO_eof              (PerlIO *);
354 #endif
355 #ifndef PerlIO_error
356 extern int      PerlIO_error            (PerlIO *);
357 #endif
358 #ifndef PerlIO_clearerr
359 extern void     PerlIO_clearerr         (PerlIO *);
360 #endif
361 #ifndef PerlIO_getc
362 extern int      PerlIO_getc             (PerlIO *);
363 #endif
364 #ifndef PerlIO_putc
365 extern int      PerlIO_putc             (PerlIO *,int);
366 #endif
367 #ifndef PerlIO_flush
368 extern int      PerlIO_flush            (PerlIO *);
369 #endif
370 #ifndef PerlIO_ungetc
371 extern int      PerlIO_ungetc           (PerlIO *,int);
372 #endif
373 #ifndef PerlIO_fileno
374 extern int      PerlIO_fileno           (PerlIO *);
375 #endif
376 #ifndef PerlIO_fdopen
377 extern PerlIO * PerlIO_fdopen           (int, const char *);
378 #endif
379 #ifndef PerlIO_importFILE
380 extern PerlIO * PerlIO_importFILE       (FILE *,int);
381 #endif
382 #ifndef PerlIO_exportFILE
383 extern FILE *   PerlIO_exportFILE       (PerlIO *,int);
384 #endif
385 #ifndef PerlIO_findFILE
386 extern FILE *   PerlIO_findFILE         (PerlIO *);
387 #endif
388 #ifndef PerlIO_releaseFILE
389 extern void     PerlIO_releaseFILE      (PerlIO *,FILE *);
390 #endif
391 #ifndef PerlIO_read
392 extern SSize_t  PerlIO_read             (PerlIO *,void *,Size_t);
393 #endif
394 #ifndef PerlIO_write
395 extern SSize_t  PerlIO_write            (PerlIO *,const void *,Size_t);
396 #endif
397 #ifndef PerlIO_setlinebuf
398 extern void     PerlIO_setlinebuf       (PerlIO *);
399 #endif
400 #ifndef PerlIO_printf
401 extern int      PerlIO_printf           (PerlIO *, const char *,...)
402                                         __attribute__((format (printf, 2, 3)));
403 #endif
404 #ifndef PerlIO_sprintf
405 extern int      PerlIO_sprintf          (char *, int, const char *,...)
406                                         __attribute__((format (printf, 3, 4)));
407 #endif
408 #ifndef PerlIO_vprintf
409 extern int      PerlIO_vprintf          (PerlIO *, const char *, va_list);
410 #endif
411 #ifndef PerlIO_tell
412 extern Off_t    PerlIO_tell             (PerlIO *);
413 #endif
414 #ifndef PerlIO_seek
415 extern int      PerlIO_seek             (PerlIO *, Off_t, int);
416 #endif
417 #ifndef PerlIO_rewind
418 extern void     PerlIO_rewind           (PerlIO *);
419 #endif
420 #ifndef PerlIO_has_base
421 extern int      PerlIO_has_base         (PerlIO *);
422 #endif
423 #ifndef PerlIO_has_cntptr
424 extern int      PerlIO_has_cntptr       (PerlIO *);
425 #endif
426 #ifndef PerlIO_fast_gets
427 extern int      PerlIO_fast_gets        (PerlIO *);
428 #endif
429 #ifndef PerlIO_canset_cnt
430 extern int      PerlIO_canset_cnt       (PerlIO *);
431 #endif
432 #ifndef PerlIO_get_ptr
433 extern STDCHAR * PerlIO_get_ptr         (PerlIO *);
434 #endif
435 #ifndef PerlIO_get_cnt
436 extern int      PerlIO_get_cnt          (PerlIO *);
437 #endif
438 #ifndef PerlIO_set_cnt
439 extern void     PerlIO_set_cnt          (PerlIO *,int);
440 #endif
441 #ifndef PerlIO_set_ptrcnt
442 extern void     PerlIO_set_ptrcnt       (PerlIO *,STDCHAR *,int);
443 #endif
444 #ifndef PerlIO_get_base
445 extern STDCHAR * PerlIO_get_base        (PerlIO *);
446 #endif
447 #ifndef PerlIO_get_bufsiz
448 extern int      PerlIO_get_bufsiz       (PerlIO *);
449 #endif
450 #ifndef PerlIO_tmpfile
451 extern PerlIO * PerlIO_tmpfile          (void);
452 #endif
453 #ifndef PerlIO_stdin
454 extern PerlIO * PerlIO_stdin    (void);
455 #endif
456 #ifndef PerlIO_stdout
457 extern PerlIO * PerlIO_stdout   (void);
458 #endif
459 #ifndef PerlIO_stderr
460 extern PerlIO * PerlIO_stderr   (void);
461 #endif
462 #ifndef PerlIO_getpos
463 extern int      PerlIO_getpos           (PerlIO *,Fpos_t *);
464 #endif
465 #ifndef PerlIO_setpos
466 extern int      PerlIO_setpos           (PerlIO *,const Fpos_t *);
467 #endif
468
469
470 /*
471  *   Interface for directory functions
472  */
473
474 #if defined(PERL_IMPLICIT_SYS)
475
476 /* IPerlDir             */
477 struct IPerlDir;
478 typedef int             (*LPMakedir)(struct IPerlDir*, const char*, int);
479 typedef int             (*LPChdir)(struct IPerlDir*, const char*);
480 typedef int             (*LPRmdir)(struct IPerlDir*, const char*);
481 typedef int             (*LPDirClose)(struct IPerlDir*, DIR*);
482 typedef DIR*            (*LPDirOpen)(struct IPerlDir*, char*);
483 typedef struct direct*  (*LPDirRead)(struct IPerlDir*, DIR*);
484 typedef void            (*LPDirRewind)(struct IPerlDir*, DIR*);
485 typedef void            (*LPDirSeek)(struct IPerlDir*, DIR*, long);
486 typedef long            (*LPDirTell)(struct IPerlDir*, DIR*);
487
488 struct IPerlDir
489 {
490     LPMakedir           pMakedir;
491     LPChdir             pChdir;
492     LPRmdir             pRmdir;
493     LPDirClose          pClose;
494     LPDirOpen           pOpen;
495     LPDirRead           pRead;
496     LPDirRewind         pRewind;
497     LPDirSeek           pSeek;
498     LPDirTell           pTell;
499 };
500
501 struct IPerlDirInfo
502 {
503     unsigned long       nCount;     /* number of entries expected */
504     struct IPerlDir     perlDirList;
505 };
506
507 #define PerlDir_mkdir(name, mode)                               \
508         (*PL_Dir->pMakedir)(PL_Dir, (name), (mode))
509 #define PerlDir_chdir(name)                                     \
510         (*PL_Dir->pChdir)(PL_Dir, (name))
511 #define PerlDir_rmdir(name)                                     \
512         (*PL_Dir->pRmdir)(PL_Dir, (name))
513 #define PerlDir_close(dir)                                      \
514         (*PL_Dir->pClose)(PL_Dir, (dir))
515 #define PerlDir_open(name)                                      \
516         (*PL_Dir->pOpen)(PL_Dir, (name))
517 #define PerlDir_read(dir)                                       \
518         (*PL_Dir->pRead)(PL_Dir, (dir))
519 #define PerlDir_rewind(dir)                                     \
520         (*PL_Dir->pRewind)(PL_Dir, (dir))
521 #define PerlDir_seek(dir, loc)                                  \
522         (*PL_Dir->pSeek)(PL_Dir, (dir), (loc))
523 #define PerlDir_tell(dir)                                       \
524         (*PL_Dir->pTell)(PL_Dir, (dir))
525
526 #else   /* PERL_IMPLICIT_SYS */
527
528 #define PerlDir_mkdir(name, mode)       Mkdir((name), (mode))
529 #ifdef VMS
530 #  define PerlDir_chdir(n)              chdir(((n) && *(n)) ? (n) : "SYS$LOGIN")
531 #else 
532 #  define PerlDir_chdir(name)           chdir((name))
533 #endif
534 #define PerlDir_rmdir(name)             rmdir((name))
535 #define PerlDir_close(dir)              closedir((dir))
536 #define PerlDir_open(name)              opendir((name))
537 #define PerlDir_read(dir)               readdir((dir))
538 #define PerlDir_rewind(dir)             rewinddir((dir))
539 #define PerlDir_seek(dir, loc)          seekdir((dir), (loc))
540 #define PerlDir_tell(dir)               telldir((dir))
541
542 #endif  /* PERL_IMPLICIT_SYS */
543
544 /*
545     Interface for perl environment functions
546 */
547
548 #if defined(PERL_IMPLICIT_SYS)
549
550 /* IPerlEnv             */
551 struct IPerlEnv;
552 typedef char*           (*LPEnvGetenv)(struct IPerlEnv*, const char*);
553 typedef int             (*LPEnvPutenv)(struct IPerlEnv*, const char*);
554 typedef char*           (*LPEnvGetenv_len)(struct IPerlEnv*,
555                                     const char *varname, unsigned long *len);
556 typedef int             (*LPEnvUname)(struct IPerlEnv*, struct utsname *name);
557 typedef void            (*LPEnvClearenv)(struct IPerlEnv*);
558 typedef void*           (*LPEnvGetChildenv)(struct IPerlEnv*);
559 typedef void            (*LPEnvFreeChildenv)(struct IPerlEnv*, void* env);
560 typedef char*           (*LPEnvGetChilddir)(struct IPerlEnv*);
561 typedef void            (*LPEnvFreeChilddir)(struct IPerlEnv*, char* dir);
562 #ifdef HAS_ENVGETENV
563 typedef char*           (*LPENVGetenv)(struct IPerlEnv*, const char *varname);
564 typedef char*           (*LPENVGetenv_len)(struct IPerlEnv*,
565                                     const char *varname, unsigned long *len);
566 #endif
567 #ifdef WIN32
568 typedef unsigned long   (*LPEnvOsID)(struct IPerlEnv*);
569 typedef char*           (*LPEnvLibPath)(struct IPerlEnv*, char*);
570 typedef char*           (*LPEnvSiteLibPath)(struct IPerlEnv*, char*);
571 #endif
572
573 struct IPerlEnv
574 {
575     LPEnvGetenv         pGetenv;
576     LPEnvPutenv         pPutenv;
577     LPEnvGetenv_len     pGetenv_len;
578     LPEnvUname          pEnvUname;
579     LPEnvClearenv       pClearenv;
580     LPEnvGetChildenv    pGetChildenv;
581     LPEnvFreeChildenv   pFreeChildenv;
582     LPEnvGetChilddir    pGetChilddir;
583     LPEnvFreeChilddir   pFreeChilddir;
584 #ifdef HAS_ENVGETENV
585     LPENVGetenv         pENVGetenv;
586     LPENVGetenv_len     pENVGetenv_len;
587 #endif
588 #ifdef WIN32
589     LPEnvOsID           pEnvOsID;
590     LPEnvLibPath        pLibPath;
591     LPEnvSiteLibPath    pSiteLibPath;
592 #endif
593 };
594
595 struct IPerlEnvInfo
596 {
597     unsigned long       nCount;     /* number of entries expected */
598     struct IPerlEnv     perlEnvList;
599 };
600
601 #define PerlEnv_putenv(str)                                     \
602         (*PL_Env->pPutenv)(PL_Env,(str))
603 #define PerlEnv_getenv(str)                                     \
604         (*PL_Env->pGetenv)(PL_Env,(str))
605 #define PerlEnv_getenv_len(str,l)                               \
606         (*PL_Env->pGetenv_len)(PL_Env,(str), (l))
607 #define PerlEnv_clearenv()                                      \
608         (*PL_Env->pClearenv)(PL_Env)
609 #define PerlEnv_get_childenv()                                  \
610         (*PL_Env->pGetChildenv)(PL_Env)
611 #define PerlEnv_free_childenv(e)                                \
612         (*PL_Env->pFreeChildenv)(PL_Env, (e))
613 #define PerlEnv_get_childdir()                                  \
614         (*PL_Env->pGetChilddir)(PL_Env)
615 #define PerlEnv_free_childdir(d)                                \
616         (*PL_Env->pFreeChilddir)(PL_Env, (d))
617 #ifdef HAS_ENVGETENV
618 #  define PerlEnv_ENVgetenv(str)                                \
619         (*PL_Env->pENVGetenv)(PL_Env,(str))
620 #  define PerlEnv_ENVgetenv_len(str,l)                          \
621         (*PL_Env->pENVGetenv_len)(PL_Env,(str), (l))
622 #else
623 #  define PerlEnv_ENVgetenv(str)                                \
624         PerlEnv_getenv((str))
625 #  define PerlEnv_ENVgetenv_len(str,l)                          \
626         PerlEnv_getenv_len((str),(l))
627 #endif
628 #define PerlEnv_uname(name)                                     \
629         (*PL_Env->pEnvUname)(PL_Env,(name))
630 #ifdef WIN32
631 #define PerlEnv_os_id()                                         \
632         (*PL_Env->pEnvOsID)(PL_Env)
633 #define PerlEnv_lib_path(str)                                   \
634         (*PL_Env->pLibPath)(PL_Env,(str))
635 #define PerlEnv_sitelib_path(str)                               \
636         (*PL_Env->pSiteLibPath)(PL_Env,(str))
637 #endif
638
639 #else   /* PERL_IMPLICIT_SYS */
640
641 #define PerlEnv_putenv(str)             putenv((str))
642 #define PerlEnv_getenv(str)             getenv((str))
643 #define PerlEnv_getenv_len(str,l)       getenv_len((str), (l))
644 #define PerlEnv_clear()                 clearenv()
645 #define PerlEnv_get_childenv()          get_childenv()
646 #define PerlEnv_free_childenv(e)        free_childenv((e))
647 #define PerlEnv_get_childdir()          get_childdir()
648 #define PerlEnv_free_childdir(d)        free_childdir((d))
649 #ifdef HAS_ENVGETENV
650 #  define PerlEnv_ENVgetenv(str)        ENVgetenv((str))
651 #  define PerlEnv_ENVgetenv_len(str,l)  ENVgetenv_len((str), (l))
652 #else
653 #  define PerlEnv_ENVgetenv(str)        PerlEnv_getenv((str))
654 #  define PerlEnv_ENVgetenv_len(str,l)  PerlEnv_getenv_len((str), (l))
655 #endif
656 #define PerlEnv_uname(name)             uname((name))
657
658 #ifdef WIN32
659 #define PerlEnv_os_id()                 win32_os_id()
660 #endif
661
662 #endif  /* PERL_IMPLICIT_SYS */
663
664 /*
665     Interface for perl low-level IO functions
666 */
667
668 #if defined(PERL_IMPLICIT_SYS)
669
670 /* IPerlLIO             */
671 struct IPerlLIO;
672 typedef int             (*LPLIOAccess)(struct IPerlLIO*, const char*, int);
673 typedef int             (*LPLIOChmod)(struct IPerlLIO*, const char*, int);
674 typedef int             (*LPLIOChown)(struct IPerlLIO*, const char*, uid_t,
675                             gid_t);
676 typedef int             (*LPLIOChsize)(struct IPerlLIO*, int, long);
677 typedef int             (*LPLIOClose)(struct IPerlLIO*, int);
678 typedef int             (*LPLIODup)(struct IPerlLIO*, int);
679 typedef int             (*LPLIODup2)(struct IPerlLIO*, int, int);
680 typedef int             (*LPLIOFlock)(struct IPerlLIO*, int, int);
681 typedef int             (*LPLIOFileStat)(struct IPerlLIO*, int, struct stat*);
682 typedef int             (*LPLIOIOCtl)(struct IPerlLIO*, int, unsigned int,
683                             char*);
684 typedef int             (*LPLIOIsatty)(struct IPerlLIO*, int);
685 typedef long            (*LPLIOLseek)(struct IPerlLIO*, int, long, int);
686 typedef int             (*LPLIOLstat)(struct IPerlLIO*, const char*,
687                             struct stat*);
688 typedef char*           (*LPLIOMktemp)(struct IPerlLIO*, char*);
689 typedef int             (*LPLIOOpen)(struct IPerlLIO*, const char*, int);       
690 typedef int             (*LPLIOOpen3)(struct IPerlLIO*, const char*, int, int); 
691 typedef int             (*LPLIORead)(struct IPerlLIO*, int, void*, unsigned int);
692 typedef int             (*LPLIORename)(struct IPerlLIO*, const char*,
693                             const char*);
694 typedef int             (*LPLIOSetmode)(struct IPerlLIO*, int, int);
695 typedef int             (*LPLIONameStat)(struct IPerlLIO*, const char*,
696                             struct stat*);
697 typedef char*           (*LPLIOTmpnam)(struct IPerlLIO*, char*);
698 typedef int             (*LPLIOUmask)(struct IPerlLIO*, int);
699 typedef int             (*LPLIOUnlink)(struct IPerlLIO*, const char*);
700 typedef int             (*LPLIOUtime)(struct IPerlLIO*, char*, struct utimbuf*);
701 typedef int             (*LPLIOWrite)(struct IPerlLIO*, int, const void*,
702                             unsigned int);
703
704 struct IPerlLIO
705 {
706     LPLIOAccess         pAccess;
707     LPLIOChmod          pChmod;
708     LPLIOChown          pChown;
709     LPLIOChsize         pChsize;
710     LPLIOClose          pClose;
711     LPLIODup            pDup;
712     LPLIODup2           pDup2;
713     LPLIOFlock          pFlock;
714     LPLIOFileStat       pFileStat;
715     LPLIOIOCtl          pIOCtl;
716     LPLIOIsatty         pIsatty;
717     LPLIOLseek          pLseek;
718     LPLIOLstat          pLstat;
719     LPLIOMktemp         pMktemp;
720     LPLIOOpen           pOpen;
721     LPLIOOpen3          pOpen3;
722     LPLIORead           pRead;
723     LPLIORename         pRename;
724     LPLIOSetmode        pSetmode;
725     LPLIONameStat       pNameStat;
726     LPLIOTmpnam         pTmpnam;
727     LPLIOUmask          pUmask;
728     LPLIOUnlink         pUnlink;
729     LPLIOUtime          pUtime;
730     LPLIOWrite          pWrite;
731 };
732
733 struct IPerlLIOInfo
734 {
735     unsigned long       nCount;     /* number of entries expected */
736     struct IPerlLIO     perlLIOList;
737 };
738
739 #define PerlLIO_access(file, mode)                                      \
740         (*PL_LIO->pAccess)(PL_LIO, (file), (mode))
741 #define PerlLIO_chmod(file, mode)                                       \
742         (*PL_LIO->pChmod)(PL_LIO, (file), (mode))
743 #define PerlLIO_chown(file, owner, group)                               \
744         (*PL_LIO->pChown)(PL_LIO, (file), (owner), (group))
745 #define PerlLIO_chsize(fd, size)                                        \
746         (*PL_LIO->pChsize)(PL_LIO, (fd), (size))
747 #define PerlLIO_close(fd)                                               \
748         (*PL_LIO->pClose)(PL_LIO, (fd))
749 #define PerlLIO_dup(fd)                                                 \
750         (*PL_LIO->pDup)(PL_LIO, (fd))
751 #define PerlLIO_dup2(fd1, fd2)                                          \
752         (*PL_LIO->pDup2)(PL_LIO, (fd1), (fd2))
753 #define PerlLIO_flock(fd, op)                                           \
754         (*PL_LIO->pFlock)(PL_LIO, (fd), (op))
755 #define PerlLIO_fstat(fd, buf)                                          \
756         (*PL_LIO->pFileStat)(PL_LIO, (fd), (buf))
757 #define PerlLIO_ioctl(fd, u, buf)                                       \
758         (*PL_LIO->pIOCtl)(PL_LIO, (fd), (u), (buf))
759 #define PerlLIO_isatty(fd)                                              \
760         (*PL_LIO->pIsatty)(PL_LIO, (fd))
761 #define PerlLIO_lseek(fd, offset, mode)                                 \
762         (*PL_LIO->pLseek)(PL_LIO, (fd), (offset), (mode))
763 #define PerlLIO_lstat(name, buf)                                        \
764         (*PL_LIO->pLstat)(PL_LIO, (name), (buf))
765 #define PerlLIO_mktemp(file)                                            \
766         (*PL_LIO->pMktemp)(PL_LIO, (file))
767 #define PerlLIO_open(file, flag)                                        \
768         (*PL_LIO->pOpen)(PL_LIO, (file), (flag))
769 #define PerlLIO_open3(file, flag, perm)                                 \
770         (*PL_LIO->pOpen3)(PL_LIO, (file), (flag), (perm))
771 #define PerlLIO_read(fd, buf, count)                                    \
772         (*PL_LIO->pRead)(PL_LIO, (fd), (buf), (count))
773 #define PerlLIO_rename(oname, newname)                                  \
774         (*PL_LIO->pRename)(PL_LIO, (oname), (newname))
775 #define PerlLIO_setmode(fd, mode)                                       \
776         (*PL_LIO->pSetmode)(PL_LIO, (fd), (mode))
777 #define PerlLIO_stat(name, buf)                                         \
778         (*PL_LIO->pNameStat)(PL_LIO, (name), (buf))
779 #define PerlLIO_tmpnam(str)                                             \
780         (*PL_LIO->pTmpnam)(PL_LIO, (str))
781 #define PerlLIO_umask(mode)                                             \
782         (*PL_LIO->pUmask)(PL_LIO, (mode))
783 #define PerlLIO_unlink(file)                                            \
784         (*PL_LIO->pUnlink)(PL_LIO, (file))
785 #define PerlLIO_utime(file, time)                                       \
786         (*PL_LIO->pUtime)(PL_LIO, (file), (time))
787 #define PerlLIO_write(fd, buf, count)                                   \
788         (*PL_LIO->pWrite)(PL_LIO, (fd), (buf), (count))
789
790 #else   /* PERL_IMPLICIT_SYS */
791
792 #define PerlLIO_access(file, mode)      access((file), (mode))
793 #define PerlLIO_chmod(file, mode)       chmod((file), (mode))
794 #define PerlLIO_chown(file, owner, grp) chown((file), (owner), (grp))
795 #define PerlLIO_chsize(fd, size)        chsize((fd), (size))
796 #define PerlLIO_close(fd)               close((fd))
797 #define PerlLIO_dup(fd)                 dup((fd))
798 #define PerlLIO_dup2(fd1, fd2)          dup2((fd1), (fd2))
799 #define PerlLIO_flock(fd, op)           FLOCK((fd), (op))
800 #define PerlLIO_fstat(fd, buf)          Fstat((fd), (buf))
801 #define PerlLIO_ioctl(fd, u, buf)       ioctl((fd), (u), (buf))
802 #define PerlLIO_isatty(fd)              isatty((fd))
803 #define PerlLIO_lseek(fd, offset, mode) lseek((fd), (offset), (mode))
804 #define PerlLIO_stat(name, buf)         Stat((name), (buf))
805 #ifdef HAS_LSTAT
806 #  define PerlLIO_lstat(name, buf)      lstat((name), (buf))
807 #else
808 #  define PerlLIO_lstat(name, buf)      PerlLIO_stat((name), (buf))
809 #endif
810 #define PerlLIO_mktemp(file)            mktemp((file))
811 #define PerlLIO_mkstemp(file)           mkstemp((file))
812 #define PerlLIO_open(file, flag)        open((file), (flag))
813 #define PerlLIO_open3(file, flag, perm) open((file), (flag), (perm))
814 #define PerlLIO_read(fd, buf, count)    read((fd), (buf), (count))
815 #define PerlLIO_rename(old, new)        rename((old), (new))
816 #define PerlLIO_setmode(fd, mode)       setmode((fd), (mode))
817 #define PerlLIO_tmpnam(str)             tmpnam((str))
818 #define PerlLIO_umask(mode)             umask((mode))
819 #define PerlLIO_unlink(file)            unlink((file))
820 #define PerlLIO_utime(file, time)       utime((file), (time))
821 #define PerlLIO_write(fd, buf, count)   write((fd), (buf), (count))
822
823 #endif  /* PERL_IMPLICIT_SYS */
824
825 /*
826     Interface for perl memory allocation
827 */
828
829 #if defined(PERL_IMPLICIT_SYS)
830
831 /* IPerlMem             */
832 struct IPerlMem;
833 typedef void*           (*LPMemMalloc)(struct IPerlMem*, size_t);
834 typedef void*           (*LPMemRealloc)(struct IPerlMem*, void*, size_t);
835 typedef void            (*LPMemFree)(struct IPerlMem*, void*);
836
837 struct IPerlMem
838 {
839     LPMemMalloc         pMalloc;
840     LPMemRealloc        pRealloc;
841     LPMemFree           pFree;
842 };
843
844 struct IPerlMemInfo
845 {
846     unsigned long       nCount;     /* number of entries expected */
847     struct IPerlMem     perlMemList;
848 };
849
850 #define PerlMem_malloc(size)                                \
851         (*PL_Mem->pMalloc)(PL_Mem, (size))
852 #define PerlMem_realloc(buf, size)                          \
853         (*PL_Mem->pRealloc)(PL_Mem, (buf), (size))
854 #define PerlMem_free(buf)                                   \
855         (*PL_Mem->pFree)(PL_Mem, (buf))
856
857 #else   /* PERL_IMPLICIT_SYS */
858
859 #define PerlMem_malloc(size)            malloc((size))
860 #define PerlMem_realloc(buf, size)      realloc((buf), (size))
861 #define PerlMem_free(buf)               free((buf))
862
863 #endif  /* PERL_IMPLICIT_SYS */
864
865 /*
866     Interface for perl process functions
867 */
868
869
870 #if defined(PERL_IMPLICIT_SYS)
871
872 #ifndef jmp_buf
873 #include <setjmp.h>
874 #endif
875
876 /* IPerlProc            */
877 struct IPerlProc;
878 typedef void            (*LPProcAbort)(struct IPerlProc*);
879 typedef char*           (*LPProcCrypt)(struct IPerlProc*, const char*,
880                             const char*);
881 typedef void            (*LPProcExit)(struct IPerlProc*, int);
882 typedef void            (*LPProc_Exit)(struct IPerlProc*, int);
883 typedef int             (*LPProcExecl)(struct IPerlProc*, const char*,
884                             const char*, const char*, const char*,
885                             const char*);
886 typedef int             (*LPProcExecv)(struct IPerlProc*, const char*,
887                             const char*const*);
888 typedef int             (*LPProcExecvp)(struct IPerlProc*, const char*,
889                             const char*const*);
890 typedef uid_t           (*LPProcGetuid)(struct IPerlProc*);
891 typedef uid_t           (*LPProcGeteuid)(struct IPerlProc*);
892 typedef gid_t           (*LPProcGetgid)(struct IPerlProc*);
893 typedef gid_t           (*LPProcGetegid)(struct IPerlProc*);
894 typedef char*           (*LPProcGetlogin)(struct IPerlProc*);
895 typedef int             (*LPProcKill)(struct IPerlProc*, int, int);
896 typedef int             (*LPProcKillpg)(struct IPerlProc*, int, int);
897 typedef int             (*LPProcPauseProc)(struct IPerlProc*);
898 typedef PerlIO*         (*LPProcPopen)(struct IPerlProc*, const char*,
899                             const char*);
900 typedef int             (*LPProcPclose)(struct IPerlProc*, PerlIO*);
901 typedef int             (*LPProcPipe)(struct IPerlProc*, int*);
902 typedef int             (*LPProcSetuid)(struct IPerlProc*, uid_t);
903 typedef int             (*LPProcSetgid)(struct IPerlProc*, gid_t);
904 typedef int             (*LPProcSleep)(struct IPerlProc*, unsigned int);
905 typedef int             (*LPProcTimes)(struct IPerlProc*, struct tms*);
906 typedef int             (*LPProcWait)(struct IPerlProc*, int*);
907 typedef int             (*LPProcWaitpid)(struct IPerlProc*, int, int*, int);
908 typedef Sighandler_t    (*LPProcSignal)(struct IPerlProc*, int, Sighandler_t);
909 typedef void*           (*LPProcDynaLoader)(struct IPerlProc*, const char*);
910 #ifdef WIN32
911 typedef void            (*LPProcGetOSError)(struct IPerlProc*,
912                             SV* sv, DWORD dwErr);
913 typedef void            (*LPProcFreeBuf)(struct IPerlProc*, char*);
914 typedef BOOL            (*LPProcDoCmd)(struct IPerlProc*, char*);
915 typedef int             (*LPProcSpawn)(struct IPerlProc*, char*);
916 typedef int             (*LPProcSpawnvp)(struct IPerlProc*, int, const char*,
917                             const char*const*);
918 typedef int             (*LPProcASpawn)(struct IPerlProc*, void*, void**, void**);
919 #endif
920
921 struct IPerlProc
922 {
923     LPProcAbort         pAbort;
924     LPProcCrypt         pCrypt;
925     LPProcExit          pExit;
926     LPProc_Exit         p_Exit;
927     LPProcExecl         pExecl;
928     LPProcExecv         pExecv;
929     LPProcExecvp        pExecvp;
930     LPProcGetuid        pGetuid;
931     LPProcGeteuid       pGeteuid;
932     LPProcGetgid        pGetgid;
933     LPProcGetegid       pGetegid;
934     LPProcGetlogin      pGetlogin;
935     LPProcKill          pKill;
936     LPProcKillpg        pKillpg;
937     LPProcPauseProc     pPauseProc;
938     LPProcPopen         pPopen;
939     LPProcPclose        pPclose;
940     LPProcPipe          pPipe;
941     LPProcSetuid        pSetuid;
942     LPProcSetgid        pSetgid;
943     LPProcSleep         pSleep;
944     LPProcTimes         pTimes;
945     LPProcWait          pWait;
946     LPProcWaitpid       pWaitpid;
947     LPProcSignal        pSignal;
948 #ifdef WIN32
949     LPProcDynaLoader    pDynaLoader;
950     LPProcGetOSError    pGetOSError;
951     LPProcDoCmd         pDoCmd;
952     LPProcSpawn         pSpawn;
953     LPProcSpawnvp       pSpawnvp;
954     LPProcASpawn        pASpawn;
955 #endif
956 };
957
958 struct IPerlProcInfo
959 {
960     unsigned long       nCount;     /* number of entries expected */
961     struct IPerlProc    perlProcList;
962 };
963
964 #define PerlProc_abort()                                                \
965         (*PL_Proc->pAbort)(PL_Proc)
966 #define PerlProc_crypt(c,s)                                             \
967         (*PL_Proc->pCrypt)(PL_Proc, (c), (s))
968 #define PerlProc_exit(s)                                                \
969         (*PL_Proc->pExit)(PL_Proc, (s))
970 #define PerlProc__exit(s)                                               \
971         (*PL_Proc->p_Exit)(PL_Proc, (s))
972 #define PerlProc_execl(c, w, x, y, z)                                   \
973         (*PL_Proc->pExecl)(PL_Proc, (c), (w), (x), (y), (z))
974 #define PerlProc_execv(c, a)                                            \
975         (*PL_Proc->pExecv)(PL_Proc, (c), (a))
976 #define PerlProc_execvp(c, a)                                           \
977         (*PL_Proc->pExecvp)(PL_Proc, (c), (a))
978 #define PerlProc_getuid()                                               \
979         (*PL_Proc->pGetuid)(PL_Proc)
980 #define PerlProc_geteuid()                                              \
981         (*PL_Proc->pGeteuid)(PL_Proc)
982 #define PerlProc_getgid()                                               \
983         (*PL_Proc->pGetgid)(PL_Proc)
984 #define PerlProc_getegid()                                              \
985         (*PL_Proc->pGetegid)(PL_Proc)
986 #define PerlProc_getlogin()                                             \
987         (*PL_Proc->pGetlogin)(PL_Proc)
988 #define PerlProc_kill(i, a)                                             \
989         (*PL_Proc->pKill)(PL_Proc, (i), (a))
990 #define PerlProc_killpg(i, a)                                           \
991         (*PL_Proc->pKillpg)(PL_Proc, (i), (a))
992 #define PerlProc_pause()                                                \
993         (*PL_Proc->pPauseProc)(PL_Proc)
994 #define PerlProc_popen(c, m)                                            \
995         (*PL_Proc->pPopen)(PL_Proc, (c), (m))
996 #define PerlProc_pclose(f)                                              \
997         (*PL_Proc->pPclose)(PL_Proc, (f))
998 #define PerlProc_pipe(fd)                                               \
999         (*PL_Proc->pPipe)(PL_Proc, (fd))
1000 #define PerlProc_setuid(u)                                              \
1001         (*PL_Proc->pSetuid)(PL_Proc, (u))
1002 #define PerlProc_setgid(g)                                              \
1003         (*PL_Proc->pSetgid)(PL_Proc, (g))
1004 #define PerlProc_sleep(t)                                               \
1005         (*PL_Proc->pSleep)(PL_Proc, (t))
1006 #define PerlProc_times(t)                                               \
1007         (*PL_Proc->pTimes)(PL_Proc, (t))
1008 #define PerlProc_wait(t)                                                \
1009         (*PL_Proc->pWait)(PL_Proc, (t))
1010 #define PerlProc_waitpid(p,s,f)                                         \
1011         (*PL_Proc->pWaitpid)(PL_Proc, (p), (s), (f))
1012 #define PerlProc_signal(n, h)                                           \
1013         (*PL_Proc->pSignal)(PL_Proc, (n), (h))
1014 #define PerlProc_setjmp(b, n) Sigsetjmp((b), (n))
1015 #define PerlProc_longjmp(b, n) Siglongjmp((b), (n))
1016
1017 #ifdef WIN32
1018 #define PerlProc_DynaLoad(f)                                            \
1019         (*PL_Proc->pDynaLoader)(PL_Proc, (f))
1020 #define PerlProc_GetOSError(s,e)                                        \
1021         (*PL_Proc->pGetOSError)(PL_Proc, (s), (e))
1022 #define PerlProc_Cmd(s)                                                 \
1023         (*PL_Proc->pDoCmd)(PL_Proc, (s))
1024 #define do_spawn(s)                                                     \
1025         (*PL_Proc->pSpawn)(PL_Proc, (s))
1026 #define do_spawnvp(m, c, a)                                             \
1027         (*PL_Proc->pSpawnvp)(PL_Proc, (m), (c), (a))
1028 #define PerlProc_aspawn(m,c,a)                                          \
1029         (*PL_Proc->pASpawn)(PL_Proc, (m), (c), (a))
1030 #endif
1031
1032 #else   /* PERL_IMPLICIT_SYS */
1033
1034 #define PerlProc_abort()        abort()
1035 #define PerlProc_crypt(c,s)     crypt((c), (s))
1036 #define PerlProc_exit(s)        exit((s))
1037 #define PerlProc__exit(s)       _exit((s))
1038 #define PerlProc_execl(c,w,x,y,z)                                       \
1039         execl((c), (w), (x), (y), (z))
1040 #define PerlProc_execv(c, a)    execv((c), (a))
1041 #define PerlProc_execvp(c, a)   execvp((c), (a))
1042 #define PerlProc_getuid()       getuid()
1043 #define PerlProc_geteuid()      geteuid()
1044 #define PerlProc_getgid()       getgid()
1045 #define PerlProc_getegid()      getegid()
1046 #define PerlProc_getlogin()     getlogin()
1047 #define PerlProc_kill(i, a)     kill((i), (a))
1048 #define PerlProc_killpg(i, a)   killpg((i), (a))
1049 #define PerlProc_pause()        Pause()
1050 #define PerlProc_popen(c, m)    my_popen((c), (m))
1051 #define PerlProc_pclose(f)      my_pclose((f))
1052 #define PerlProc_pipe(fd)       pipe((fd))
1053 #define PerlProc_setuid(u)      setuid((u))
1054 #define PerlProc_setgid(g)      setgid((g))
1055 #define PerlProc_sleep(t)       sleep((t))
1056 #define PerlProc_times(t)       times((t))
1057 #define PerlProc_wait(t)        wait((t))
1058 #define PerlProc_waitpid(p,s,f) waitpid((p), (s), (f))
1059 #define PerlProc_setjmp(b, n)   Sigsetjmp((b), (n))
1060 #define PerlProc_longjmp(b, n)  Siglongjmp((b), (n))
1061 #define PerlProc_signal(n, h)   signal((n), (h))
1062
1063 #ifdef WIN32
1064 #define PerlProc_DynaLoad(f)                                            \
1065         win32_dynaload((f))
1066 #define PerlProc_GetOSError(s,e)                                        \
1067         win32_str_os_error((s), (e))
1068 #endif
1069 #endif  /* PERL_IMPLICIT_SYS */
1070
1071 /*
1072     Interface for perl socket functions
1073 */
1074
1075 #if defined(PERL_IMPLICIT_SYS)
1076
1077 /* PerlSock             */
1078 struct IPerlSock;
1079 typedef u_long          (*LPHtonl)(struct IPerlSock*, u_long);
1080 typedef u_short         (*LPHtons)(struct IPerlSock*, u_short);
1081 typedef u_long          (*LPNtohl)(struct IPerlSock*, u_long);
1082 typedef u_short         (*LPNtohs)(struct IPerlSock*, u_short);
1083 typedef SOCKET          (*LPAccept)(struct IPerlSock*, SOCKET,
1084                             struct sockaddr*, int*);
1085 typedef int             (*LPBind)(struct IPerlSock*, SOCKET,
1086                             const struct sockaddr*, int);
1087 typedef int             (*LPConnect)(struct IPerlSock*, SOCKET,
1088                             const struct sockaddr*, int);
1089 typedef void            (*LPEndhostent)(struct IPerlSock*);
1090 typedef void            (*LPEndnetent)(struct IPerlSock*);
1091 typedef void            (*LPEndprotoent)(struct IPerlSock*);
1092 typedef void            (*LPEndservent)(struct IPerlSock*);
1093 typedef int             (*LPGethostname)(struct IPerlSock*, char*, int);
1094 typedef int             (*LPGetpeername)(struct IPerlSock*, SOCKET,
1095                             struct sockaddr*, int*);
1096 typedef struct hostent* (*LPGethostbyaddr)(struct IPerlSock*, const char*,
1097                             int, int);
1098 typedef struct hostent* (*LPGethostbyname)(struct IPerlSock*, const char*);
1099 typedef struct hostent* (*LPGethostent)(struct IPerlSock*);
1100 typedef struct netent*  (*LPGetnetbyaddr)(struct IPerlSock*, long, int);
1101 typedef struct netent*  (*LPGetnetbyname)(struct IPerlSock*, const char*);
1102 typedef struct netent*  (*LPGetnetent)(struct IPerlSock*);
1103 typedef struct protoent*(*LPGetprotobyname)(struct IPerlSock*, const char*);
1104 typedef struct protoent*(*LPGetprotobynumber)(struct IPerlSock*, int);
1105 typedef struct protoent*(*LPGetprotoent)(struct IPerlSock*);
1106 typedef struct servent* (*LPGetservbyname)(struct IPerlSock*, const char*,
1107                             const char*);
1108 typedef struct servent* (*LPGetservbyport)(struct IPerlSock*, int,
1109                             const char*);
1110 typedef struct servent* (*LPGetservent)(struct IPerlSock*);
1111 typedef int             (*LPGetsockname)(struct IPerlSock*, SOCKET,
1112                             struct sockaddr*, int*);
1113 typedef int             (*LPGetsockopt)(struct IPerlSock*, SOCKET, int, int,
1114                             char*, int*);
1115 typedef unsigned long   (*LPInetAddr)(struct IPerlSock*, const char*);
1116 typedef char*           (*LPInetNtoa)(struct IPerlSock*, struct in_addr);
1117 typedef int             (*LPListen)(struct IPerlSock*, SOCKET, int);
1118 typedef int             (*LPRecv)(struct IPerlSock*, SOCKET, char*, int, int);
1119 typedef int             (*LPRecvfrom)(struct IPerlSock*, SOCKET, char*, int,
1120                             int, struct sockaddr*, int*);
1121 typedef int             (*LPSelect)(struct IPerlSock*, int, char*, char*,
1122                             char*, const struct timeval*);
1123 typedef int             (*LPSend)(struct IPerlSock*, SOCKET, const char*, int,
1124                             int); 
1125 typedef int             (*LPSendto)(struct IPerlSock*, SOCKET, const char*,
1126                             int, int, const struct sockaddr*, int);
1127 typedef void            (*LPSethostent)(struct IPerlSock*, int);
1128 typedef void            (*LPSetnetent)(struct IPerlSock*, int);
1129 typedef void            (*LPSetprotoent)(struct IPerlSock*, int);
1130 typedef void            (*LPSetservent)(struct IPerlSock*, int);
1131 typedef int             (*LPSetsockopt)(struct IPerlSock*, SOCKET, int, int,
1132                             const char*, int);
1133 typedef int             (*LPShutdown)(struct IPerlSock*, SOCKET, int);
1134 typedef SOCKET          (*LPSocket)(struct IPerlSock*, int, int, int);
1135 typedef int             (*LPSocketpair)(struct IPerlSock*, int, int, int,
1136                             int*);
1137 #ifdef WIN32
1138 typedef int             (*LPClosesocket)(struct IPerlSock*, SOCKET s);
1139 #endif
1140
1141 struct IPerlSock
1142 {
1143     LPHtonl             pHtonl;
1144     LPHtons             pHtons;
1145     LPNtohl             pNtohl;
1146     LPNtohs             pNtohs;
1147     LPAccept            pAccept;
1148     LPBind              pBind;
1149     LPConnect           pConnect;
1150     LPEndhostent        pEndhostent;
1151     LPEndnetent         pEndnetent;
1152     LPEndprotoent       pEndprotoent;
1153     LPEndservent        pEndservent;
1154     LPGethostname       pGethostname;
1155     LPGetpeername       pGetpeername;
1156     LPGethostbyaddr     pGethostbyaddr;
1157     LPGethostbyname     pGethostbyname;
1158     LPGethostent        pGethostent;
1159     LPGetnetbyaddr      pGetnetbyaddr;
1160     LPGetnetbyname      pGetnetbyname;
1161     LPGetnetent         pGetnetent;
1162     LPGetprotobyname    pGetprotobyname;
1163     LPGetprotobynumber  pGetprotobynumber;
1164     LPGetprotoent       pGetprotoent;
1165     LPGetservbyname     pGetservbyname;
1166     LPGetservbyport     pGetservbyport;
1167     LPGetservent        pGetservent;
1168     LPGetsockname       pGetsockname;
1169     LPGetsockopt        pGetsockopt;
1170     LPInetAddr          pInetAddr;
1171     LPInetNtoa          pInetNtoa;
1172     LPListen            pListen;
1173     LPRecv              pRecv;
1174     LPRecvfrom          pRecvfrom;
1175     LPSelect            pSelect;
1176     LPSend              pSend;
1177     LPSendto            pSendto;
1178     LPSethostent        pSethostent;
1179     LPSetnetent         pSetnetent;
1180     LPSetprotoent       pSetprotoent;
1181     LPSetservent        pSetservent;
1182     LPSetsockopt        pSetsockopt;
1183     LPShutdown          pShutdown;
1184     LPSocket            pSocket;
1185     LPSocketpair        pSocketpair;
1186 #ifdef WIN32
1187     LPClosesocket       pClosesocket;
1188 #endif
1189 };
1190
1191 struct IPerlSockInfo
1192 {
1193     unsigned long       nCount;     /* number of entries expected */
1194     struct IPerlSock    perlSockList;
1195 };
1196
1197 #define PerlSock_htonl(x)                                               \
1198         (*PL_Sock->pHtonl)(PL_Sock, x)
1199 #define PerlSock_htons(x)                                               \
1200         (*PL_Sock->pHtons)(PL_Sock, x)
1201 #define PerlSock_ntohl(x)                                               \
1202         (*PL_Sock->pNtohl)(PL_Sock, x)
1203 #define PerlSock_ntohs(x)                                               \
1204         (*PL_Sock->pNtohs)(PL_Sock, x)
1205 #define PerlSock_accept(s, a, l)                                        \
1206         (*PL_Sock->pAccept)(PL_Sock, s, a, l)
1207 #define PerlSock_bind(s, n, l)                                          \
1208         (*PL_Sock->pBind)(PL_Sock, s, n, l)
1209 #define PerlSock_connect(s, n, l)                                       \
1210         (*PL_Sock->pConnect)(PL_Sock, s, n, l)
1211 #define PerlSock_endhostent()                                           \
1212         (*PL_Sock->pEndhostent)(PL_Sock)
1213 #define PerlSock_endnetent()                                            \
1214         (*PL_Sock->pEndnetent)(PL_Sock)
1215 #define PerlSock_endprotoent()                                          \
1216         (*PL_Sock->pEndprotoent)(PL_Sock)
1217 #define PerlSock_endservent()                                           \
1218         (*PL_Sock->pEndservent)(PL_Sock)
1219 #define PerlSock_gethostbyaddr(a, l, t)                                 \
1220         (*PL_Sock->pGethostbyaddr)(PL_Sock, a, l, t)
1221 #define PerlSock_gethostbyname(n)                                       \
1222         (*PL_Sock->pGethostbyname)(PL_Sock, n)
1223 #define PerlSock_gethostent()                                           \
1224         (*PL_Sock->pGethostent)(PL_Sock)
1225 #define PerlSock_gethostname(n, l)                                      \
1226         (*PL_Sock->pGethostname)(PL_Sock, n, l)
1227 #define PerlSock_getnetbyaddr(n, t)                                     \
1228         (*PL_Sock->pGetnetbyaddr)(PL_Sock, n, t)
1229 #define PerlSock_getnetbyname(c)                                        \
1230         (*PL_Sock->pGetnetbyname)(PL_Sock, c)
1231 #define PerlSock_getnetent()                                            \
1232         (*PL_Sock->pGetnetent)(PL_Sock)
1233 #define PerlSock_getpeername(s, n, l)                                   \
1234         (*PL_Sock->pGetpeername)(PL_Sock, s, n, l)
1235 #define PerlSock_getprotobyname(n)                                      \
1236         (*PL_Sock->pGetprotobyname)(PL_Sock, n)
1237 #define PerlSock_getprotobynumber(n)                                    \
1238         (*PL_Sock->pGetprotobynumber)(PL_Sock, n)
1239 #define PerlSock_getprotoent()                                          \
1240         (*PL_Sock->pGetprotoent)(PL_Sock)
1241 #define PerlSock_getservbyname(n, p)                                    \
1242         (*PL_Sock->pGetservbyname)(PL_Sock, n, p)
1243 #define PerlSock_getservbyport(port, p)                                 \
1244         (*PL_Sock->pGetservbyport)(PL_Sock, port, p)
1245 #define PerlSock_getservent()                                           \
1246         (*PL_Sock->pGetservent)(PL_Sock)
1247 #define PerlSock_getsockname(s, n, l)                                   \
1248         (*PL_Sock->pGetsockname)(PL_Sock, s, n, l)
1249 #define PerlSock_getsockopt(s,l,n,v,i)                                  \
1250         (*PL_Sock->pGetsockopt)(PL_Sock, s, l, n, v, i)
1251 #define PerlSock_inet_addr(c)                                           \
1252         (*PL_Sock->pInetAddr)(PL_Sock, c)
1253 #define PerlSock_inet_ntoa(i)                                           \
1254         (*PL_Sock->pInetNtoa)(PL_Sock, i)
1255 #define PerlSock_listen(s, b)                                           \
1256         (*PL_Sock->pListen)(PL_Sock, s, b)
1257 #define PerlSock_recv(s, b, l, f)                                       \
1258         (*PL_Sock->pRecv)(PL_Sock, s, b, l, f)
1259 #define PerlSock_recvfrom(s,b,l,f,from,fromlen)                         \
1260         (*PL_Sock->pRecvfrom)(PL_Sock, s, b, l, f, from, fromlen)
1261 #define PerlSock_select(n, r, w, e, t)                                  \
1262         (*PL_Sock->pSelect)(PL_Sock, n, (char*)r, (char*)w, (char*)e, t)
1263 #define PerlSock_send(s, b, l, f)                                       \
1264         (*PL_Sock->pSend)(PL_Sock, s, b, l, f)
1265 #define PerlSock_sendto(s, b, l, f, t, tlen)                            \
1266         (*PL_Sock->pSendto)(PL_Sock, s, b, l, f, t, tlen)
1267 #define PerlSock_sethostent(f)                                          \
1268         (*PL_Sock->pSethostent)(PL_Sock, f)
1269 #define PerlSock_setnetent(f)                                           \
1270         (*PL_Sock->pSetnetent)(PL_Sock, f)
1271 #define PerlSock_setprotoent(f)                                         \
1272         (*PL_Sock->pSetprotoent)(PL_Sock, f)
1273 #define PerlSock_setservent(f)                                          \
1274         (*PL_Sock->pSetservent)(PL_Sock, f)
1275 #define PerlSock_setsockopt(s, l, n, v, len)                            \
1276         (*PL_Sock->pSetsockopt)(PL_Sock, s, l, n, v, len)
1277 #define PerlSock_shutdown(s, h)                                         \
1278         (*PL_Sock->pShutdown)(PL_Sock, s, h)
1279 #define PerlSock_socket(a, t, p)                                        \
1280         (*PL_Sock->pSocket)(PL_Sock, a, t, p)
1281 #define PerlSock_socketpair(a, t, p, f)                                 \
1282         (*PL_Sock->pSocketpair)(PL_Sock, a, t, p, f)
1283
1284 #ifdef WIN32
1285 #define PerlSock_closesocket(s)                                         \
1286         (*PL_Sock->pClosesocket)(PL_Sock, s)
1287 #endif
1288
1289 #else   /* PERL_IMPLICIT_SYS */
1290
1291 #define PerlSock_htonl(x)               htonl(x)
1292 #define PerlSock_htons(x)               htons(x)
1293 #define PerlSock_ntohl(x)               ntohl(x)
1294 #define PerlSock_ntohs(x)               ntohs(x)
1295 #define PerlSock_accept(s, a, l)        accept(s, a, l)
1296 #define PerlSock_bind(s, n, l)          bind(s, n, l)
1297 #define PerlSock_connect(s, n, l)       connect(s, n, l)
1298
1299 #define PerlSock_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
1300 #define PerlSock_gethostbyname(n)       gethostbyname(n)
1301 #define PerlSock_gethostent             gethostent
1302 #define PerlSock_endhostent             endhostent
1303 #define PerlSock_gethostname(n, l)      gethostname(n, l)
1304
1305 #define PerlSock_getnetbyaddr(n, t)     getnetbyaddr(n, t)
1306 #define PerlSock_getnetbyname(n)        getnetbyname(n)
1307 #define PerlSock_getnetent              getnetent
1308 #define PerlSock_endnetent              endnetent
1309 #define PerlSock_getpeername(s, n, l)   getpeername(s, n, l)
1310
1311 #define PerlSock_getprotobyname(n)      getprotobyname(n)
1312 #define PerlSock_getprotobynumber(n)    getprotobynumber(n)
1313 #define PerlSock_getprotoent            getprotoent
1314 #define PerlSock_endprotoent            endprotoent
1315
1316 #define PerlSock_getservbyname(n, p)    getservbyname(n, p)
1317 #define PerlSock_getservbyport(port, p) getservbyport(port, p)
1318 #define PerlSock_getservent             getservent
1319 #define PerlSock_endservent             endservent
1320
1321 #define PerlSock_getsockname(s, n, l)   getsockname(s, n, l)
1322 #define PerlSock_getsockopt(s,l,n,v,i)  getsockopt(s, l, n, v, i)
1323 #define PerlSock_inet_addr(c)           inet_addr(c)
1324 #define PerlSock_inet_ntoa(i)           inet_ntoa(i)
1325 #define PerlSock_listen(s, b)           listen(s, b)
1326 #define PerlSock_recv(s, b, l, f)       recv(s, b, l, f)
1327 #define PerlSock_recvfrom(s, b, l, f, from, fromlen)                    \
1328         recvfrom(s, b, l, f, from, fromlen)
1329 #define PerlSock_select(n, r, w, e, t)  select(n, r, w, e, t)
1330 #define PerlSock_send(s, b, l, f)       send(s, b, l, f)
1331 #define PerlSock_sendto(s, b, l, f, t, tlen)                            \
1332         sendto(s, b, l, f, t, tlen)
1333 #define PerlSock_sethostent(f)          sethostent(f)
1334 #define PerlSock_setnetent(f)           setnetent(f)
1335 #define PerlSock_setprotoent(f)         setprotoent(f)
1336 #define PerlSock_setservent(f)          setservent(f)
1337 #define PerlSock_setsockopt(s, l, n, v, len)                            \
1338         setsockopt(s, l, n, v, len)
1339 #define PerlSock_shutdown(s, h)         shutdown(s, h)
1340 #define PerlSock_socket(a, t, p)        socket(a, t, p)
1341 #define PerlSock_socketpair(a, t, p, f) socketpair(a, t, p, f)
1342
1343 #ifdef WIN32
1344 #define PerlSock_closesocket(s)         closesocket(s)
1345 #endif
1346
1347 #endif  /* PERL_IMPLICIT_SYS */
1348
1349 /* Mention
1350
1351    HAS_READV
1352    HAS_RECVMSG
1353    HAS_SENDMSG
1354    HAS_WRITEV
1355    HAS_STRUCT_MSGHDR
1356    HAS_STRUCT_CMSGHDR
1357
1358    here so that Configure picks them up.  Perl core does not
1359    use them but somebody might want to extend Socket:: or IO::
1360    someday.
1361
1362    Jarkko Hietaniemi November 1998
1363
1364    */
1365
1366 #endif  /* __Inc__IPerl___ */
1367