This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add patch, along with all the missing bits, and doc tweaks
[perl5.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 #ifdef PERL_OBJECT
78
79 #ifndef PerlIO
80 typedef struct _PerlIO PerlIO;
81 #endif
82
83 class IPerlStdIO
84 {
85 public:
86     virtual PerlIO *    Stdin(void) = 0;
87     virtual PerlIO *    Stdout(void) = 0;
88     virtual PerlIO *    Stderr(void) = 0;
89     virtual PerlIO *    Open(const char *, const char *, int &err) = 0;
90     virtual int         Close(PerlIO*, int &err) = 0;
91     virtual int         Eof(PerlIO*, int &err) = 0;
92     virtual int         Error(PerlIO*, int &err) = 0;
93     virtual void        Clearerr(PerlIO*, int &err) = 0;
94     virtual int         Getc(PerlIO*, int &err) = 0;
95     virtual char *      GetBase(PerlIO *, int &err) = 0;
96     virtual int         GetBufsiz(PerlIO *, int &err) = 0;
97     virtual int         GetCnt(PerlIO *, int &err) = 0;
98     virtual char *      GetPtr(PerlIO *, int &err) = 0;
99     virtual char *      Gets(PerlIO*, char*, int, int& err) = 0;
100     virtual int         Putc(PerlIO*, int, int &err) = 0;
101     virtual int         Puts(PerlIO*, const char *, int &err) = 0;
102     virtual int         Flush(PerlIO*, int &err) = 0;
103     virtual int         Ungetc(PerlIO*,int, int &err) = 0;
104     virtual int         Fileno(PerlIO*, int &err) = 0;
105     virtual PerlIO *    Fdopen(int, const char *, int &err) = 0;
106     virtual PerlIO *    Reopen(const char*, const char*, PerlIO*, int &err) = 0;
107     virtual SSize_t     Read(PerlIO*,void *,Size_t, int &err) = 0;
108     virtual SSize_t     Write(PerlIO*,const void *,Size_t, int &err) = 0;
109     virtual void        SetBuf(PerlIO *, char*, int &err) = 0;
110     virtual int         SetVBuf(PerlIO *, char*, int, Size_t, int &err) = 0;
111     virtual void        SetCnt(PerlIO *, int, int &err) = 0;
112     virtual void        SetPtrCnt(PerlIO *, char *, int, int& err) = 0;
113     virtual void        Setlinebuf(PerlIO*, int &err) = 0;
114     virtual int         Printf(PerlIO*, int &err, const char *,...) = 0;
115     virtual int         Vprintf(PerlIO*, int &err, const char *, va_list) = 0;
116     virtual long        Tell(PerlIO*, int &err) = 0;
117     virtual int         Seek(PerlIO*, off_t, int, int &err) = 0;
118     virtual void        Rewind(PerlIO*, int &err) = 0;
119     virtual PerlIO *    Tmpfile(int &err) = 0;
120     virtual int         Getpos(PerlIO*, Fpos_t *, int &err) = 0;
121     virtual int         Setpos(PerlIO*, const Fpos_t *, int &err) = 0;
122     virtual void        Init(int &err) = 0;
123     virtual void        InitOSExtras(void* p) = 0;
124 #ifdef WIN32
125     virtual int         OpenOSfhandle(long osfhandle, int flags) = 0;
126     virtual int         GetOSfhandle(int filenum) = 0;
127 #endif
128 };
129
130 #define PerlIO_canset_cnt(f)    1
131 #define PerlIO_has_base(f)      1
132 #define PerlIO_has_cntptr(f)    1
133 #define PerlIO_fast_gets(f)     1
134
135 #define PerlIO_stdin()          piStdIO->Stdin()
136 #define PerlIO_stdout()         piStdIO->Stdout()
137 #define PerlIO_stderr()         piStdIO->Stderr()
138 #define PerlIO_open(x,y)        piStdIO->Open((x),(y), ErrorNo())
139 #define PerlIO_close(f)         piStdIO->Close((f), ErrorNo())
140 #define PerlIO_eof(f)           piStdIO->Eof((f), ErrorNo())
141 #define PerlIO_error(f)         piStdIO->Error((f), ErrorNo())
142 #define PerlIO_clearerr(f)      piStdIO->Clearerr((f), ErrorNo())
143 #define PerlIO_getc(f)          piStdIO->Getc((f), ErrorNo())
144 #define PerlIO_get_base(f)      piStdIO->GetBase((f), ErrorNo())
145 #define PerlIO_get_bufsiz(f)    piStdIO->GetBufsiz((f), ErrorNo())
146 #define PerlIO_get_cnt(f)       piStdIO->GetCnt((f), ErrorNo())
147 #define PerlIO_get_ptr(f)       piStdIO->GetPtr((f), ErrorNo())
148 #define PerlIO_putc(f,c)        piStdIO->Putc((f),(c), ErrorNo())
149 #define PerlIO_puts(f,s)        piStdIO->Puts((f),(s), ErrorNo())
150 #define PerlIO_flush(f)         piStdIO->Flush((f), ErrorNo())
151 #define PerlIO_gets(s, n, fp)   piStdIO->Gets((fp), s, n, ErrorNo())
152 #define PerlIO_ungetc(f,c)      piStdIO->Ungetc((f),(c), ErrorNo())
153 #define PerlIO_fileno(f)        piStdIO->Fileno((f), ErrorNo())
154 #define PerlIO_fdopen(f, s)     piStdIO->Fdopen((f),(s), ErrorNo())
155 #define PerlIO_reopen(p, m, f)  piStdIO->Reopen((p), (m), (f), ErrorNo())
156 #define PerlIO_read(f,buf,count)                                        \
157         (SSize_t)piStdIO->Read((f), (buf), (count), ErrorNo())
158 #define PerlIO_write(f,buf,count)                                       \
159         piStdIO->Write((f), (buf), (count), ErrorNo())
160 #define PerlIO_setbuf(f,b)      piStdIO->SetBuf((f), (b), ErrorNo())
161 #define PerlIO_setvbuf(f,b,t,s) piStdIO->SetVBuf((f), (b), (t), (s), ErrorNo())
162 #define PerlIO_set_cnt(f,c)     piStdIO->SetCnt((f), (c), ErrorNo())
163 #define PerlIO_set_ptrcnt(f,p,c)                                        \
164         piStdIO->SetPtrCnt((f), (p), (c), ErrorNo())
165 #define PerlIO_setlinebuf(f)    piStdIO->Setlinebuf((f), ErrorNo())
166 #define PerlIO_printf           fprintf
167 #define PerlIO_stdoutf          piStdIO->Printf
168 #define PerlIO_vprintf(f,fmt,a) piStdIO->Vprintf((f), ErrorNo(), (fmt),a)          
169 #define PerlIO_tell(f)          piStdIO->Tell((f), ErrorNo())
170 #define PerlIO_seek(f,o,w)      piStdIO->Seek((f),(o),(w), ErrorNo())
171 #define PerlIO_getpos(f,p)      piStdIO->Getpos((f),(p), ErrorNo())
172 #define PerlIO_setpos(f,p)      piStdIO->Setpos((f),(p), ErrorNo())
173 #define PerlIO_rewind(f)        piStdIO->Rewind((f), ErrorNo())
174 #define PerlIO_tmpfile()        piStdIO->Tmpfile(ErrorNo())
175 #define PerlIO_init()           piStdIO->Init(ErrorNo())
176 #undef  init_os_extras
177 #define init_os_extras()        piStdIO->InitOSExtras(this)
178
179 #else   /* PERL_OBJECT */
180
181 #include "perlsdio.h"
182
183 #endif  /* PERL_OBJECT */
184
185 #ifndef PERLIO_IS_STDIO
186 #ifdef USE_SFIO
187 #include "perlsfio.h"
188 #endif /* USE_SFIO */
189 #endif /* PERLIO_IS_STDIO */
190
191 #ifndef EOF
192 #define EOF (-1)
193 #endif
194
195 /* This is to catch case with no stdio */
196 #ifndef BUFSIZ
197 #define BUFSIZ 1024
198 #endif
199
200 #ifndef SEEK_SET
201 #define SEEK_SET 0
202 #endif
203
204 #ifndef SEEK_CUR
205 #define SEEK_CUR 1
206 #endif
207
208 #ifndef SEEK_END
209 #define SEEK_END 2
210 #endif
211
212 #ifndef PerlIO
213 struct _PerlIO;
214 #define PerlIO struct _PerlIO
215 #endif /* No PerlIO */
216
217 #ifndef Fpos_t
218 #define Fpos_t long
219 #endif
220
221 #ifndef NEXT30_NO_ATTRIBUTE
222 #ifndef HASATTRIBUTE       /* disable GNU-cc attribute checking? */
223 #ifdef  __attribute__      /* Avoid possible redefinition errors */
224 #undef  __attribute__
225 #endif
226 #define __attribute__(attr)
227 #endif
228 #endif
229
230 #ifndef PerlIO_stdoutf
231 extern int      PerlIO_stdoutf          _((const char *,...))
232                                         __attribute__((format (printf, 1, 2)));
233 #endif
234 #ifndef PerlIO_puts
235 extern int      PerlIO_puts             _((PerlIO *,const char *));
236 #endif
237 #ifndef PerlIO_open
238 extern PerlIO * PerlIO_open             _((const char *,const char *));
239 #endif
240 #ifndef PerlIO_close
241 extern int      PerlIO_close            _((PerlIO *));
242 #endif
243 #ifndef PerlIO_eof
244 extern int      PerlIO_eof              _((PerlIO *));
245 #endif
246 #ifndef PerlIO_error
247 extern int      PerlIO_error            _((PerlIO *));
248 #endif
249 #ifndef PerlIO_clearerr
250 extern void     PerlIO_clearerr         _((PerlIO *));
251 #endif
252 #ifndef PerlIO_getc
253 extern int      PerlIO_getc             _((PerlIO *));
254 #endif
255 #ifndef PerlIO_putc
256 extern int      PerlIO_putc             _((PerlIO *,int));
257 #endif
258 #ifndef PerlIO_flush
259 extern int      PerlIO_flush            _((PerlIO *));
260 #endif
261 #ifndef PerlIO_ungetc
262 extern int      PerlIO_ungetc           _((PerlIO *,int));
263 #endif
264 #ifndef PerlIO_fileno
265 extern int      PerlIO_fileno           _((PerlIO *));
266 #endif
267 #ifndef PerlIO_fdopen
268 extern PerlIO * PerlIO_fdopen           _((int, const char *));
269 #endif
270 #ifndef PerlIO_importFILE
271 extern PerlIO * PerlIO_importFILE       _((FILE *,int));
272 #endif
273 #ifndef PerlIO_exportFILE
274 extern FILE *   PerlIO_exportFILE       _((PerlIO *,int));
275 #endif
276 #ifndef PerlIO_findFILE
277 extern FILE *   PerlIO_findFILE         _((PerlIO *));
278 #endif
279 #ifndef PerlIO_releaseFILE
280 extern void     PerlIO_releaseFILE      _((PerlIO *,FILE *));
281 #endif
282 #ifndef PerlIO_read
283 extern SSize_t  PerlIO_read             _((PerlIO *,void *,Size_t));
284 #endif
285 #ifndef PerlIO_write
286 extern SSize_t  PerlIO_write            _((PerlIO *,const void *,Size_t));
287 #endif
288 #ifndef PerlIO_setlinebuf
289 extern void     PerlIO_setlinebuf       _((PerlIO *));
290 #endif
291 #ifndef PerlIO_printf
292 extern int      PerlIO_printf           _((PerlIO *, const char *,...))
293                                         __attribute__((format (printf, 2, 3)));
294 #endif
295 #ifndef PerlIO_sprintf
296 extern int      PerlIO_sprintf          _((char *, int, const char *,...))
297                                         __attribute__((format (printf, 3, 4)));
298 #endif
299 #ifndef PerlIO_vprintf
300 extern int      PerlIO_vprintf          _((PerlIO *, const char *, va_list));
301 #endif
302 #ifndef PerlIO_tell
303 extern long     PerlIO_tell             _((PerlIO *));
304 #endif
305 #ifndef PerlIO_seek
306 extern int      PerlIO_seek             _((PerlIO *,off_t,int));
307 #endif
308 #ifndef PerlIO_rewind
309 extern void     PerlIO_rewind           _((PerlIO *));
310 #endif
311 #ifndef PerlIO_has_base
312 extern int      PerlIO_has_base         _((PerlIO *));
313 #endif
314 #ifndef PerlIO_has_cntptr
315 extern int      PerlIO_has_cntptr       _((PerlIO *));
316 #endif
317 #ifndef PerlIO_fast_gets
318 extern int      PerlIO_fast_gets        _((PerlIO *));
319 #endif
320 #ifndef PerlIO_canset_cnt
321 extern int      PerlIO_canset_cnt       _((PerlIO *));
322 #endif
323 #ifndef PerlIO_get_ptr
324 extern STDCHAR * PerlIO_get_ptr         _((PerlIO *));
325 #endif
326 #ifndef PerlIO_get_cnt
327 extern int      PerlIO_get_cnt          _((PerlIO *));
328 #endif
329 #ifndef PerlIO_set_cnt
330 extern void     PerlIO_set_cnt          _((PerlIO *,int));
331 #endif
332 #ifndef PerlIO_set_ptrcnt
333 extern void     PerlIO_set_ptrcnt       _((PerlIO *,STDCHAR *,int));
334 #endif
335 #ifndef PerlIO_get_base
336 extern STDCHAR * PerlIO_get_base        _((PerlIO *));
337 #endif
338 #ifndef PerlIO_get_bufsiz
339 extern int      PerlIO_get_bufsiz       _((PerlIO *));
340 #endif
341 #ifndef PerlIO_tmpfile
342 extern PerlIO * PerlIO_tmpfile          _((void));
343 #endif
344 #ifndef PerlIO_stdin
345 extern PerlIO * PerlIO_stdin    _((void));
346 #endif
347 #ifndef PerlIO_stdout
348 extern PerlIO * PerlIO_stdout   _((void));
349 #endif
350 #ifndef PerlIO_stderr
351 extern PerlIO * PerlIO_stderr   _((void));
352 #endif
353 #ifndef PerlIO_getpos
354 extern int      PerlIO_getpos           _((PerlIO *,Fpos_t *));
355 #endif
356 #ifndef PerlIO_setpos
357 extern int      PerlIO_setpos           _((PerlIO *,const Fpos_t *));
358 #endif
359
360
361 /*
362  *   Interface for directory functions
363  */
364
365 #ifdef PERL_OBJECT
366
367 class IPerlDir
368 {
369 public:
370     virtual int         Makedir(const char *dirname, int mode, int &err) = 0;
371     virtual int         Chdir(const char *dirname, int &err) = 0;
372     virtual int         Rmdir(const char *dirname, int &err) = 0;
373     virtual int         Close(DIR *dirp, int &err) = 0;
374     virtual DIR *       Open(char *filename, int &err) = 0;
375     virtual struct direct *Read(DIR *dirp, int &err) = 0;
376     virtual void        Rewind(DIR *dirp, int &err) = 0;
377     virtual void        Seek(DIR *dirp, long loc, int &err) = 0;
378     virtual long        Tell(DIR *dirp, int &err) = 0;
379 };
380
381 #define PerlDir_mkdir(name, mode)                               \
382         piDir->Makedir((name), (mode), ErrorNo())
383 #define PerlDir_chdir(name)                                     \
384         piDir->Chdir((name), ErrorNo())
385 #define PerlDir_rmdir(name)                                     \
386         piDir->Rmdir((name), ErrorNo())
387 #define PerlDir_close(dir)                                      \
388         piDir->Close((dir), ErrorNo())
389 #define PerlDir_open(name)                                      \
390         piDir->Open((name), ErrorNo())
391 #define PerlDir_read(dir)                                       \
392         piDir->Read((dir), ErrorNo())
393 #define PerlDir_rewind(dir)                                     \
394         piDir->Rewind((dir), ErrorNo())
395 #define PerlDir_seek(dir, loc)                                  \
396         piDir->Seek((dir), (loc), ErrorNo())
397 #define PerlDir_tell(dir)                                       \
398         piDir->Tell((dir), ErrorNo())
399
400 #else   /* PERL_OBJECT */
401
402 #define PerlDir_mkdir(name, mode)       Mkdir((name), (mode))
403 #ifdef VMS
404 #  define PerlDir_chdir(n)              chdir(((n) && *(n)) ? (n) : "SYS$LOGIN")
405 #else 
406 #  define PerlDir_chdir(name)           chdir((name))
407 #endif
408 #define PerlDir_rmdir(name)             rmdir((name))
409 #define PerlDir_close(dir)              closedir((dir))
410 #define PerlDir_open(name)              opendir((name))
411 #define PerlDir_read(dir)               readdir((dir))
412 #define PerlDir_rewind(dir)             rewinddir((dir))
413 #define PerlDir_seek(dir, loc)          seekdir((dir), (loc))
414 #define PerlDir_tell(dir)               telldir((dir))
415
416 #endif  /* PERL_OBJECT */
417
418 /*
419     Interface for perl environment functions
420 */
421
422 #ifdef PERL_OBJECT
423
424 class IPerlEnv
425 {
426 public:
427     virtual char *      Getenv(const char *varname, int &err) = 0;
428     virtual int         Putenv(const char *envstring, int &err) = 0;
429     virtual char *      LibPath(char *patchlevel) =0;
430     virtual char *      SiteLibPath(char *patchlevel) =0;
431 };
432
433 #define PerlEnv_putenv(str)             piENV->Putenv((str), ErrorNo())
434 #define PerlEnv_getenv(str)             piENV->Getenv((str), ErrorNo())
435 #ifdef WIN32
436 #define PerlEnv_lib_path(str)           piENV->LibPath((str))
437 #define PerlEnv_sitelib_path(str)       piENV->SiteLibPath((str))
438 #endif
439
440 #else   /* PERL_OBJECT */
441
442 #define PerlEnv_putenv(str)             putenv((str))
443 #define PerlEnv_getenv(str)             getenv((str))
444
445 #endif  /* PERL_OBJECT */
446
447 /*
448     Interface for perl low-level IO functions
449 */
450
451 #ifdef PERL_OBJECT
452
453 class IPerlLIO
454 {
455 public:
456     virtual int         Access(const char *path, int mode, int &err) = 0;
457     virtual int         Chmod(const char *filename, int pmode, int &err) = 0;
458     virtual int         Chown(const char *filename, uid_t owner,
459                               gid_t group, int &err) = 0;
460     virtual int         Chsize(int handle, long size, int &err) = 0;
461     virtual int         Close(int handle, int &err) = 0;
462     virtual int         Dup(int handle, int &err) = 0;
463     virtual int         Dup2(int handle1, int handle2, int &err) = 0;
464     virtual int         Flock(int fd, int oper, int &err) = 0;
465     virtual int         FileStat(int handle, struct stat *buffer, int &err) = 0;
466     virtual int         IOCtl(int i, unsigned int u, char *data, int &err) = 0;
467     virtual int         Isatty(int handle, int &err) = 0;
468     virtual long        Lseek(int handle, long offset, int origin, int &err) = 0;
469     virtual int         Lstat(const char *path, struct stat *buffer, int &err) = 0;
470     virtual char *      Mktemp(char *Template, int &err) = 0;
471     virtual int         Open(const char *filename, int oflag, int &err) = 0;    
472     virtual int         Open(const char *filename, int oflag,
473                              int pmode, int &err) = 0;  
474     virtual int         Read(int handle, void *buffer,
475                              unsigned int count, int &err) = 0;
476     virtual int         Rename(const char *oldname,
477                                const char *newname, int &err) = 0;
478     virtual int         Setmode(int handle, int mode, int &err) = 0;
479     virtual int         NameStat(const char *path,
480                                  struct stat *buffer, int &err) = 0;
481     virtual char *      Tmpnam(char *string, int &err) = 0;
482     virtual int         Umask(int pmode, int &err) = 0;
483     virtual int         Unlink(const char *filename, int &err) = 0;
484     virtual int         Utime(char *filename, struct utimbuf *times, int &err) = 0;
485     virtual int         Write(int handle, const void *buffer,
486                               unsigned int count, int &err) = 0;
487 };
488
489 #define PerlLIO_access(file, mode)                                      \
490         piLIO->Access((file), (mode), ErrorNo())
491 #define PerlLIO_chmod(file, mode)                                       \
492         piLIO->Chmod((file), (mode), ErrorNo())
493 #define PerlLIO_chown(file, owner, group)                               \
494         piLIO->Chown((file), (owner), (group), ErrorNo())
495 #define PerlLIO_chsize(fd, size)                                        \
496         piLIO->Chsize((fd), (size), ErrorNo())
497 #define PerlLIO_close(fd)                                               \
498         piLIO->Close((fd), ErrorNo())
499 #define PerlLIO_dup(fd)                                                 \
500         piLIO->Dup((fd), ErrorNo())
501 #define PerlLIO_dup2(fd1, fd2)                                          \
502         piLIO->Dup2((fd1), (fd2), ErrorNo())
503 #define PerlLIO_flock(fd, op)                                           \
504         piLIO->Flock((fd), (op), ErrorNo())
505 #define PerlLIO_fstat(fd, buf)                                          \
506         piLIO->FileStat((fd), (buf), ErrorNo())
507 #define PerlLIO_ioctl(fd, u, buf)                                       \
508         piLIO->IOCtl((fd), (u), (buf), ErrorNo())
509 #define PerlLIO_isatty(fd)                                              \
510         piLIO->Isatty((fd), ErrorNo())
511 #define PerlLIO_lseek(fd, offset, mode)                                 \
512         piLIO->Lseek((fd), (offset), (mode), ErrorNo())
513 #define PerlLIO_lstat(name, buf)                                        \
514         piLIO->Lstat((name), (buf), ErrorNo())
515 #define PerlLIO_mktemp(file)                                            \
516         piLIO->Mktemp((file), ErrorNo())
517 #define PerlLIO_open(file, flag)                                        \
518         piLIO->Open((file), (flag), ErrorNo())
519 #define PerlLIO_open3(file, flag, perm)                                 \
520         piLIO->Open((file), (flag), (perm), ErrorNo())
521 #define PerlLIO_read(fd, buf, count)                                    \
522         piLIO->Read((fd), (buf), (count), ErrorNo())
523 #define PerlLIO_rename(oldname, newname)                                \
524         piLIO->Rename((oldname), (newname), ErrorNo())
525 #define PerlLIO_setmode(fd, mode)                                       \
526         piLIO->Setmode((fd), (mode), ErrorNo())
527 #define PerlLIO_stat(name, buf)                                         \
528         piLIO->NameStat((name), (buf), ErrorNo())
529 #define PerlLIO_tmpnam(str)                                             \
530         piLIO->Tmpnam((str), ErrorNo())
531 #define PerlLIO_umask(mode)                                             \
532         piLIO->Umask((mode), ErrorNo())
533 #define PerlLIO_unlink(file)                                            \
534         piLIO->Unlink((file), ErrorNo())
535 #define PerlLIO_utime(file, time)                                       \
536         piLIO->Utime((file), (time), ErrorNo())
537 #define PerlLIO_write(fd, buf, count)                                   \
538         piLIO->Write((fd), (buf), (count), ErrorNo())
539
540 #else   /* PERL_OBJECT */
541
542 #define PerlLIO_access(file, mode)      access((file), (mode))
543 #define PerlLIO_chmod(file, mode)       chmod((file), (mode))
544 #define PerlLIO_chown(file, owner, grp) chown((file), (owner), (grp))
545 #define PerlLIO_chsize(fd, size)        chsize((fd), (size))
546 #define PerlLIO_close(fd)               close((fd))
547 #define PerlLIO_dup(fd)                 dup((fd))
548 #define PerlLIO_dup2(fd1, fd2)          dup2((fd1), (fd2))
549 #define PerlLIO_flock(fd, op)           FLOCK((fd), (op))
550 #define PerlLIO_fstat(fd, buf)          Fstat((fd), (buf))
551 #define PerlLIO_ioctl(fd, u, buf)       ioctl((fd), (u), (buf))
552 #define PerlLIO_isatty(fd)              isatty((fd))
553 #define PerlLIO_lseek(fd, offset, mode) lseek((fd), (offset), (mode))
554 #define PerlLIO_lstat(name, buf)        lstat((name), (buf))
555 #define PerlLIO_mktemp(file)            mktemp((file))
556 #define PerlLIO_mkstemp(file)           mkstemp((file))
557 #define PerlLIO_open(file, flag)        open((file), (flag))
558 #define PerlLIO_open3(file, flag, perm) open((file), (flag), (perm))
559 #define PerlLIO_read(fd, buf, count)    read((fd), (buf), (count))
560 #define PerlLIO_rename(old, new)        rename((old), (new))
561 #define PerlLIO_setmode(fd, mode)       setmode((fd), (mode))
562 #define PerlLIO_stat(name, buf)         Stat((name), (buf))
563 #define PerlLIO_tmpnam(str)             tmpnam((str))
564 #define PerlLIO_umask(mode)             umask((mode))
565 #define PerlLIO_unlink(file)            unlink((file))
566 #define PerlLIO_utime(file, time)       utime((file), (time))
567 #define PerlLIO_write(fd, buf, count)   write((fd), (buf), (count))
568
569 #endif  /* PERL_OBJECT */
570
571 /*
572     Interface for perl memory allocation
573 */
574
575 #ifdef PERL_OBJECT
576
577 class IPerlMem
578 {
579 public:
580     virtual void *      Malloc(size_t) = 0;
581     virtual void *      Realloc(void*, size_t) = 0;
582     virtual void        Free(void*) = 0;
583 };
584
585 #define PerlMem_malloc(size)            piMem->Malloc((size))
586 #define PerlMem_realloc(buf, size)      piMem->Realloc((buf), (size))
587 #define PerlMem_free(buf)               piMem->Free((buf))
588
589 #else   /* PERL_OBJECT */
590
591 #define PerlMem_malloc(size)            malloc((size))
592 #define PerlMem_realloc(buf, size)      realloc((buf), (size))
593 #define PerlMem_free(buf)               free((buf))
594
595 #endif  /* PERL_OBJECT */
596
597 /*
598     Interface for perl process functions
599 */
600
601
602 #ifdef PERL_OBJECT
603
604 #ifndef Sighandler_t
605 typedef Signal_t (*Sighandler_t) _((int));
606 #endif
607 #ifndef jmp_buf
608 #include <setjmp.h>
609 #endif
610
611 class IPerlProc
612 {
613 public:
614     virtual void        Abort(void) = 0;
615     virtual void        Exit(int status) = 0;
616     virtual void        _Exit(int status) = 0;
617     virtual int         Execl(const char *cmdname, const char *arg0,
618                               const char *arg1, const char *arg2,
619                               const char *arg3) = 0;
620     virtual int         Execv(const char *cmdname, const char *const *argv) = 0;
621     virtual int         Execvp(const char *cmdname, const char *const *argv) = 0;
622     virtual uid_t       Getuid(void) = 0;
623     virtual uid_t       Geteuid(void) = 0;
624     virtual gid_t       Getgid(void) = 0;
625     virtual gid_t       Getegid(void) = 0;
626     virtual char *      Getlogin(void) = 0;
627     virtual int         Kill(int pid, int sig) = 0;
628     virtual int         Killpg(int pid, int sig) = 0;
629     virtual int         PauseProc(void) = 0;
630     virtual PerlIO *    Popen(const char *command, const char *mode) = 0;
631     virtual int         Pclose(PerlIO *stream) = 0;
632     virtual int         Pipe(int *phandles) = 0;
633     virtual int         Setuid(uid_t uid) = 0;
634     virtual int         Setgid(gid_t gid) = 0;
635     virtual int         Sleep(unsigned int) = 0;
636     virtual int         Times(struct tms *timebuf) = 0;
637     virtual int         Wait(int *status) = 0;
638     virtual int         Waitpid(int pid, int *status, int flags) = 0;
639     virtual Sighandler_t        Signal(int sig, Sighandler_t subcode) = 0;
640 #ifdef WIN32
641     virtual void        GetSysMsg(char*& msg, DWORD& dwLen, DWORD dwErr) = 0;
642     virtual void        FreeBuf(char* msg) = 0;
643     virtual BOOL        DoCmd(char *cmd) = 0;
644     virtual int         Spawn(char*cmds) = 0;
645     virtual int         Spawnvp(int mode, const char *cmdname,
646                                 const char *const *argv) = 0;
647     virtual int         ASpawn(void *vreally, void **vmark, void **vsp) = 0;
648 #endif
649 };
650
651 #define PerlProc_abort()        piProc->Abort()
652 #define PerlProc_exit(s)        piProc->Exit((s))
653 #define PerlProc__exit(s)       piProc->_Exit((s))
654 #define PerlProc_execl(c, w, x, y, z)                                   \
655         piProc->Execl((c), (w), (x), (y), (z))
656
657 #define PerlProc_execv(c, a)    piProc->Execv((c), (a))
658 #define PerlProc_execvp(c, a)   piProc->Execvp((c), (a))
659 #define PerlProc_getuid()       piProc->Getuid()
660 #define PerlProc_geteuid()      piProc->Geteuid()
661 #define PerlProc_getgid()       piProc->Getgid()
662 #define PerlProc_getegid()      piProc->Getegid()
663 #define PerlProc_getlogin()     piProc->Getlogin()
664 #define PerlProc_kill(i, a)     piProc->Kill((i), (a))
665 #define PerlProc_killpg(i, a)   piProc->Killpg((i), (a))
666 #define PerlProc_pause()        piProc->PauseProc()
667 #define PerlProc_popen(c, m)    piProc->Popen((c), (m))
668 #define PerlProc_pclose(f)      piProc->Pclose((f))
669 #define PerlProc_pipe(fd)       piProc->Pipe((fd))
670 #define PerlProc_setuid(u)      piProc->Setuid((u))
671 #define PerlProc_setgid(g)      piProc->Setgid((g))
672 #define PerlProc_sleep(t)       piProc->Sleep((t))
673 #define PerlProc_times(t)       piProc->Times((t))
674 #define PerlProc_wait(t)        piProc->Wait((t))
675 #define PerlProc_waitpid(p,s,f) piProc->Waitpid((p), (s), (f))
676 #define PerlProc_setjmp(b, n)   Sigsetjmp((b), (n))
677 #define PerlProc_longjmp(b, n)  Siglongjmp((b), (n))
678 #define PerlProc_signal(n, h)   piProc->Signal((n), (h))
679
680 #ifdef WIN32
681 #define PerlProc_GetSysMsg(s,l,e)                                       \
682         piProc->GetSysMsg((s), (l), (e))
683
684 #define PerlProc_FreeBuf(s)     piProc->FreeBuf((s))
685 #define PerlProc_Cmd(s)         piProc->DoCmd((s))
686 #define do_spawn(s)             piProc->Spawn((s))
687 #define do_spawnvp(m, c, a)     piProc->Spawnvp((m), (c), (a))
688 #define PerlProc_aspawn(m,c,a)  piProc->ASpawn((m), (c), (a))
689 #endif
690
691 #else   /* PERL_OBJECT */
692
693 #define PerlProc_abort()        abort()
694 #define PerlProc_exit(s)        exit((s))
695 #define PerlProc__exit(s)       _exit((s))
696 #define PerlProc_execl(c,w,x,y,z)                                       \
697         execl((c), (w), (x), (y), (z))
698 #define PerlProc_execv(c, a)    execv((c), (a))
699 #define PerlProc_execvp(c, a)   execvp((c), (a))
700 #define PerlProc_getuid()       getuid()
701 #define PerlProc_geteuid()      geteuid()
702 #define PerlProc_getgid()       getgid()
703 #define PerlProc_getegid()      getegid()
704 #define PerlProc_getlogin()     getlogin()
705 #define PerlProc_kill(i, a)     kill((i), (a))
706 #define PerlProc_killpg(i, a)   killpg((i), (a))
707 #define PerlProc_pause()        Pause()
708 #define PerlProc_popen(c, m)    my_popen((c), (m))
709 #define PerlProc_pclose(f)      my_pclose((f))
710 #define PerlProc_pipe(fd)       pipe((fd))
711 #define PerlProc_setuid(u)      setuid((u))
712 #define PerlProc_setgid(g)      setgid((g))
713 #define PerlProc_sleep(t)       sleep((t))
714 #define PerlProc_times(t)       times((t))
715 #define PerlProc_wait(t)        wait((t))
716 #define PerlProc_waitpid(p,s,f) waitpid((p), (s), (f))
717 #define PerlProc_setjmp(b, n)   Sigsetjmp((b), (n))
718 #define PerlProc_longjmp(b, n)  Siglongjmp((b), (n))
719 #define PerlProc_signal(n, h)   signal((n), (h))
720
721
722 #endif  /* PERL_OBJECT */
723
724 /*
725     Interface for perl socket functions
726 */
727
728 #ifdef PERL_OBJECT
729
730 class IPerlSock
731 {
732 public:
733     virtual u_long      Htonl(u_long hostlong) = 0;
734     virtual u_short     Htons(u_short hostshort) = 0;
735     virtual u_long      Ntohl(u_long netlong) = 0;
736     virtual u_short     Ntohs(u_short netshort) = 0;
737     virtual SOCKET      Accept(SOCKET s, struct sockaddr* addr,
738                                int* addrlen, int &err) = 0;
739     virtual int         Bind(SOCKET s, const struct sockaddr* name,
740                              int namelen, int &err) = 0;
741     virtual int         Connect(SOCKET s, const struct sockaddr* name,
742                                 int namelen, int &err) = 0;
743     virtual void        Endhostent(int &err) = 0;
744     virtual void        Endnetent(int &err) = 0;
745     virtual void        Endprotoent(int &err) = 0;
746     virtual void        Endservent(int &err) = 0;
747     virtual int         Gethostname(char* name, int namelen, int &err) = 0;
748     virtual int         Getpeername(SOCKET s, struct sockaddr* name,
749                                     int* namelen, int &err) = 0;
750     virtual struct hostent *    Gethostbyaddr(const char* addr, int len,
751                                               int type, int &err) = 0;
752     virtual struct hostent *    Gethostbyname(const char* name, int &err) = 0;
753     virtual struct hostent *    Gethostent(int &err) = 0;
754     virtual struct netent *     Getnetbyaddr(long net, int type, int &err) = 0;
755     virtual struct netent *     Getnetbyname(const char *, int &err) = 0;
756     virtual struct netent *     Getnetent(int &err) = 0;
757     virtual struct protoent *   Getprotobyname(const char* name, int &err) = 0;
758     virtual struct protoent *   Getprotobynumber(int number, int &err) = 0;
759     virtual struct protoent *   Getprotoent(int &err) = 0;
760     virtual struct servent *    Getservbyname(const char* name,
761                                               const char* proto, int &err) = 0;
762     virtual struct servent *    Getservbyport(int port, const char* proto,
763                                               int &err) = 0;
764     virtual struct servent *    Getservent(int &err) = 0;
765     virtual int         Getsockname(SOCKET s, struct sockaddr* name,
766                                     int* namelen, int &err) = 0;
767     virtual int         Getsockopt(SOCKET s, int level, int optname,
768                                    char* optval, int* optlen, int &err) = 0;
769     virtual unsigned long       InetAddr(const char* cp, int &err) = 0;
770     virtual char *      InetNtoa(struct in_addr in, int &err) = 0;
771     virtual int         Listen(SOCKET s, int backlog, int &err) = 0;
772     virtual int         Recv(SOCKET s, char* buf, int len,
773                              int flags, int &err) = 0;
774     virtual int         Recvfrom(SOCKET s, char* buf, int len, int flags,
775                                  struct sockaddr* from, int* fromlen, int &err) = 0;
776     virtual int         Select(int nfds, char* readfds, char* writefds,
777                                char* exceptfds, const struct timeval* timeout,
778                                int &err) = 0;
779     virtual int         Send(SOCKET s, const char* buf, int len,
780                              int flags, int &err) = 0; 
781     virtual int         Sendto(SOCKET s, const char* buf, int len, int flags,
782                                const struct sockaddr* to, int tolen, int &err) = 0;
783     virtual void        Sethostent(int stayopen, int &err) = 0;
784     virtual void        Setnetent(int stayopen, int &err) = 0;
785     virtual void        Setprotoent(int stayopen, int &err) = 0;
786     virtual void        Setservent(int stayopen, int &err) = 0;
787     virtual int         Setsockopt(SOCKET s, int level, int optname,
788                                    const char* optval, int optlen, int &err) = 0;
789     virtual int         Shutdown(SOCKET s, int how, int &err) = 0;
790     virtual SOCKET      Socket(int af, int type, int protocol, int &err) = 0;
791     virtual int         Socketpair(int domain, int type, int protocol,
792                                    int* fds, int &err) = 0;
793 #ifdef WIN32
794     virtual int         Closesocket(SOCKET s, int& err) = 0;
795     virtual int         Ioctlsocket(SOCKET s, long cmd, u_long *argp,
796                                     int& err) = 0;
797 #endif
798 };
799
800 #define PerlSock_htonl(x)               piSock->Htonl(x)
801 #define PerlSock_htons(x)               piSock->Htons(x)
802 #define PerlSock_ntohl(x)               piSock->Ntohl(x)
803 #define PerlSock_ntohs(x)               piSock->Ntohs(x)
804 #define PerlSock_accept(s, a, l)        piSock->Accept(s, a, l, ErrorNo())
805 #define PerlSock_bind(s, n, l)          piSock->Bind(s, n, l, ErrorNo())
806 #define PerlSock_connect(s, n, l)       piSock->Connect(s, n, l, ErrorNo())
807 #define PerlSock_endhostent()           piSock->Endhostent(ErrorNo())
808 #define PerlSock_endnetent()            piSock->Endnetent(ErrorNo())
809 #define PerlSock_endprotoent()          piSock->Endprotoent(ErrorNo())
810 #define PerlSock_endservent()           piSock->Endservent(ErrorNo())
811 #define PerlSock_gethostbyaddr(a, l, t) piSock->Gethostbyaddr(a, l, t, ErrorNo())
812 #define PerlSock_gethostbyname(n)       piSock->Gethostbyname(n, ErrorNo())
813 #define PerlSock_gethostent()           piSock->Gethostent(ErrorNo())
814 #define PerlSock_gethostname(n, l)      piSock->Gethostname(n, l, ErrorNo())
815 #define PerlSock_getnetbyaddr(n, t)     piSock->Getnetbyaddr(n, t, ErrorNo())
816 #define PerlSock_getnetbyname(c)        piSock->Getnetbyname(c, ErrorNo())
817 #define PerlSock_getnetent()            piSock->Getnetent(ErrorNo())
818 #define PerlSock_getpeername(s, n, l)   piSock->Getpeername(s, n, l, ErrorNo())
819 #define PerlSock_getprotobyname(n)      piSock->Getprotobyname(n, ErrorNo())
820 #define PerlSock_getprotobynumber(n)    piSock->Getprotobynumber(n, ErrorNo())
821 #define PerlSock_getprotoent()          piSock->Getprotoent(ErrorNo())
822 #define PerlSock_getservbyname(n, p)    piSock->Getservbyname(n, p, ErrorNo())
823 #define PerlSock_getservbyport(port, p) piSock->Getservbyport(port, p, ErrorNo())
824 #define PerlSock_getservent()           piSock->Getservent(ErrorNo())
825 #define PerlSock_getsockname(s, n, l)   piSock->Getsockname(s, n, l, ErrorNo())
826 #define PerlSock_getsockopt(s,l,n,v,i)  piSock->Getsockopt(s, l, n, v, i, ErrorNo())
827 #define PerlSock_inet_addr(c)           piSock->InetAddr(c, ErrorNo())
828 #define PerlSock_inet_ntoa(i)           piSock->InetNtoa(i, ErrorNo())
829 #define PerlSock_listen(s, b)           piSock->Listen(s, b, ErrorNo())
830 #define PerlSock_recv(s, b, l, f)       piSock->Recv(s, b, l, f, ErrorNo())
831 #define PerlSock_recvfrom(s,b,l,f,from,fromlen)                         \
832         piSock->Recvfrom(s, b, l, f, from, fromlen, ErrorNo())
833 #define PerlSock_select(n, r, w, e, t)                                  \
834         piSock->Select(n, (char*)r, (char*)w, (char*)e, t, ErrorNo())
835 #define PerlSock_send(s, b, l, f)       piSock->Send(s, b, l, f, ErrorNo())
836 #define PerlSock_sendto(s, b, l, f, t, tlen)                            \
837         piSock->Sendto(s, b, l, f, t, tlen, ErrorNo())
838 #define PerlSock_sethostent(f)          piSock->Sethostent(f, ErrorNo())
839 #define PerlSock_setnetent(f)           piSock->Setnetent(f, ErrorNo())
840 #define PerlSock_setprotoent(f)         piSock->Setprotoent(f, ErrorNo())
841 #define PerlSock_setservent(f)          piSock->Setservent(f, ErrorNo())
842 #define PerlSock_setsockopt(s, l, n, v, len)                            \
843         piSock->Setsockopt(s, l, n, v, len, ErrorNo())
844 #define PerlSock_shutdown(s, h)         piSock->Shutdown(s, h, ErrorNo())
845 #define PerlSock_socket(a, t, p)        piSock->Socket(a, t, p, ErrorNo())
846 #define PerlSock_socketpair(a, t, p, f) piSock->Socketpair(a, t, p, f, ErrorNo())
847
848 #else   /* PERL_OBJECT */
849
850 #define PerlSock_htonl(x)               htonl(x)
851 #define PerlSock_htons(x)               htons(x)
852 #define PerlSock_ntohl(x)               ntohl(x)
853 #define PerlSock_ntohs(x)               ntohs(x)
854 #define PerlSock_accept(s, a, l)        accept(s, a, l)
855 #define PerlSock_bind(s, n, l)          bind(s, n, l)
856 #define PerlSock_connect(s, n, l)       connect(s, n, l)
857
858 #define PerlSock_gethostbyaddr(a, l, t) gethostbyaddr(a, l, t)
859 #define PerlSock_gethostbyname(n)       gethostbyname(n)
860 #define PerlSock_gethostent             gethostent
861 #define PerlSock_endhostent             endhostent
862 #define PerlSock_gethostname(n, l)      gethostname(n, l)
863
864 #define PerlSock_getnetbyaddr(n, t)     getnetbyaddr(n, t)
865 #define PerlSock_getnetbyname(n)        getnetbyname(n)
866 #define PerlSock_getnetent              getnetent
867 #define PerlSock_endnetent              endnetent
868 #define PerlSock_getpeername(s, n, l)   getpeername(s, n, l)
869
870 #define PerlSock_getprotobyname(n)      getprotobyname(n)
871 #define PerlSock_getprotobynumber(n)    getprotobynumber(n)
872 #define PerlSock_getprotoent            getprotoent
873 #define PerlSock_endprotoent            endprotoent
874
875 #define PerlSock_getservbyname(n, p)    getservbyname(n, p)
876 #define PerlSock_getservbyport(port, p) getservbyport(port, p)
877 #define PerlSock_getservent             getservent
878 #define PerlSock_endservent             endservent
879
880 #define PerlSock_getsockname(s, n, l)   getsockname(s, n, l)
881 #define PerlSock_getsockopt(s,l,n,v,i)  getsockopt(s, l, n, v, i)
882 #define PerlSock_inet_addr(c)           inet_addr(c)
883 #define PerlSock_inet_ntoa(i)           inet_ntoa(i)
884 #define PerlSock_listen(s, b)           listen(s, b)
885 #define PerlSock_recvfrom(s, b, l, f, from, fromlen)                    \
886         recvfrom(s, b, l, f, from, fromlen)
887 #define PerlSock_select(n, r, w, e, t)  select(n, r, w, e, t)
888 #define PerlSock_send(s, b, l, f)       send(s, b, l, f)
889 #define PerlSock_sendto(s, b, l, f, t, tlen)                            \
890         sendto(s, b, l, f, t, tlen)
891 #define PerlSock_sethostent(f)          sethostent(f)
892 #define PerlSock_setnetent(f)           setnetent(f)
893 #define PerlSock_setprotoent(f)         setprotoent(f)
894 #define PerlSock_setservent(f)          setservent(f)
895 #define PerlSock_setsockopt(s, l, n, v, len)                            \
896         setsockopt(s, l, n, v, len)
897 #define PerlSock_shutdown(s, h)         shutdown(s, h)
898 #define PerlSock_socket(a, t, p)        socket(a, t, p)
899 #define PerlSock_socketpair(a, t, p, f) socketpair(a, t, p, f)
900
901
902 #endif  /* PERL_OBJECT */
903
904 #endif  /* __Inc__IPerl___ */
905