* iperlsys.h - Perl's interface to the system
* This file defines the system level functionality that perl needs.
* When using C, this definition is in the form of a set of macros
* that can be #defined to the system-level function (or a wrapper
* PerlXXX_YYY explained - DickH and DougL @ ActiveState.com
* XXX := functional group
* YYY := stdlib/OS function name
* Continuing with the theme of PerlIO, all OS functionality was
* encapsulated into one of several interfaces.
* PerlLIO - low level I/O
* PerlMem - malloc, realloc, free
* PerlDir - directory related
* PerlEnv - process environment handling
* PerlProc - process control
* PerlSock - socket functions
* The features of this are:
* 1. All OS dependant code is in the Perl Host and not the Perl Core.
* (At least this is the holy grail goal of this work)
* 2. The Perl Host (see perl.h for description) can provide a new and
* improved interface to OS functionality if required.
* 3. Developers can easily hook into the OS calls for instrumentation
* or diagnostic purposes.
* What was changed to do this:
* 1. All calls to OS functions were replaced with PerlXXX_YYY
Interface for perl stdio functions, or whatever we are Configure-d
# if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
typedef Signal_t (*Sighandler_t) (int, siginfo_t*, void*);
typedef Signal_t (*Sighandler_t) (int);
#if defined(PERL_IMPLICIT_SYS)
typedef FILE* (*LPStdin)(struct IPerlStdIO*);
typedef FILE* (*LPStdout)(struct IPerlStdIO*);
typedef FILE* (*LPStderr)(struct IPerlStdIO*);
typedef FILE* (*LPOpen)(struct IPerlStdIO*, const char*,
typedef int (*LPClose)(struct IPerlStdIO*, FILE*);
typedef int (*LPEof)(struct IPerlStdIO*, FILE*);
typedef int (*LPError)(struct IPerlStdIO*, FILE*);
typedef void (*LPClearerr)(struct IPerlStdIO*, FILE*);
typedef int (*LPGetc)(struct IPerlStdIO*, FILE*);
typedef STDCHAR* (*LPGetBase)(struct IPerlStdIO*, FILE*);
typedef int (*LPGetBufsiz)(struct IPerlStdIO*, FILE*);
typedef int (*LPGetCnt)(struct IPerlStdIO*, FILE*);
typedef STDCHAR* (*LPGetPtr)(struct IPerlStdIO*, FILE*);
typedef char* (*LPGets)(struct IPerlStdIO*, char*, int, FILE*);
typedef int (*LPPutc)(struct IPerlStdIO*, int, FILE*);
typedef int (*LPPuts)(struct IPerlStdIO*, const char *, FILE*);
typedef int (*LPFlush)(struct IPerlStdIO*, FILE*);
typedef int (*LPUngetc)(struct IPerlStdIO*, int,FILE*);
typedef int (*LPFileno)(struct IPerlStdIO*, FILE*);
typedef FILE* (*LPFdopen)(struct IPerlStdIO*, int, const char*);
typedef FILE* (*LPReopen)(struct IPerlStdIO*, const char*,
typedef SSize_t (*LPRead)(struct IPerlStdIO*, void*, Size_t, Size_t, FILE *);
typedef SSize_t (*LPWrite)(struct IPerlStdIO*, const void*, Size_t, Size_t, FILE *);
typedef void (*LPSetBuf)(struct IPerlStdIO*, FILE*, char*);
typedef int (*LPSetVBuf)(struct IPerlStdIO*, FILE*, char*, int,
typedef void (*LPSetCnt)(struct IPerlStdIO*, FILE*, int);
typedef void (*LPSetPtr)(struct IPerlStdIO*, FILE*, STDCHAR*);
typedef void (*LPSetPtr)(struct IPerlStdIO*, FILE*, STDCHAR*, int);
typedef void (*LPSetlinebuf)(struct IPerlStdIO*, FILE*);
typedef int (*LPPrintf)(struct IPerlStdIO*, FILE*, const char*,
typedef int (*LPVprintf)(struct IPerlStdIO*, FILE*, const char*,
typedef Off_t (*LPTell)(struct IPerlStdIO*, FILE*);
typedef int (*LPSeek)(struct IPerlStdIO*, FILE*, Off_t, int);
typedef void (*LPRewind)(struct IPerlStdIO*, FILE*);
typedef FILE* (*LPTmpfile)(struct IPerlStdIO*);
typedef int (*LPGetpos)(struct IPerlStdIO*, FILE*, Fpos_t*);
typedef int (*LPSetpos)(struct IPerlStdIO*, FILE*,
typedef void (*LPInit)(struct IPerlStdIO*);
typedef void (*LPInitOSExtras)(struct IPerlStdIO*);
typedef FILE* (*LPFdupopen)(struct IPerlStdIO*, FILE*);
LPSetlinebuf pSetlinebuf;
LPInitOSExtras pInitOSExtras;
unsigned long nCount; /* number of entries expected */
struct IPerlStdIO perlStdIOList;
/* These do not belong here ... NI-S, 14 Nov 2000 */
# define PerlSIO_has_cntptr(f) 1
# define PerlSIO_canset_cnt(f) 1
# ifdef STDIO_PTR_LVAL_NOCHANGE_CNT
# define PerlSIO_fast_gets(f) 1
# else /* STDIO_CNT_LVALUE */
# define PerlSIO_canset_cnt(f) 0
# else /* STDIO_PTR_LVALUE */
# ifdef STDIO_PTR_LVAL_SETS_CNT
# define PerlSIO_fast_gets(f) 1
#else /* USE_STDIO_PTR */
# define PerlSIO_has_cntptr(f) 0
# define PerlSIO_canset_cnt(f) 0
#endif /* USE_STDIO_PTR */
#ifndef PerlSIO_fast_gets
#define PerlSIO_fast_gets(f) 0
#define PerlSIO_has_base(f) 1
#define PerlSIO_has_base(f) 0
/* Now take FILE * via function table */
(*PL_StdIO->pStdin)(PL_StdIO)
(*PL_StdIO->pStdout)(PL_StdIO)
(*PL_StdIO->pStderr)(PL_StdIO)
#define PerlSIO_fopen(x,y) \
(*PL_StdIO->pOpen)(PL_StdIO, (x),(y))
#define PerlSIO_fclose(f) \
(*PL_StdIO->pClose)(PL_StdIO, (f))
#define PerlSIO_feof(f) \
(*PL_StdIO->pEof)(PL_StdIO, (f))
#define PerlSIO_ferror(f) \
(*PL_StdIO->pError)(PL_StdIO, (f))
#define PerlSIO_clearerr(f) \
(*PL_StdIO->pClearerr)(PL_StdIO, (f))
#define PerlSIO_fgetc(f) \
(*PL_StdIO->pGetc)(PL_StdIO, (f))
#define PerlSIO_get_base(f) \
(*PL_StdIO->pGetBase)(PL_StdIO, (f))
#define PerlSIO_get_bufsiz(f) \
(*PL_StdIO->pGetBufsiz)(PL_StdIO, (f))
#define PerlSIO_get_cnt(f) \
(*PL_StdIO->pGetCnt)(PL_StdIO, (f))
#define PerlSIO_get_ptr(f) \
(*PL_StdIO->pGetPtr)(PL_StdIO, (f))
#define PerlSIO_fputc(c,f) \
(*PL_StdIO->pPutc)(PL_StdIO, (c),(f))
#define PerlSIO_fputs(s,f) \
(*PL_StdIO->pPuts)(PL_StdIO, (s),(f))
#define PerlSIO_fflush(f) \
(*PL_StdIO->pFlush)(PL_StdIO, (f))
#define PerlSIO_fgets(s, n, f) \
(*PL_StdIO->pGets)(PL_StdIO, s, n, (f))
#define PerlSIO_ungetc(c,f) \
(*PL_StdIO->pUngetc)(PL_StdIO, (c),(f))
#define PerlSIO_fileno(f) \
(*PL_StdIO->pFileno)(PL_StdIO, (f))
#define PerlSIO_fdopen(f, s) \
(*PL_StdIO->pFdopen)(PL_StdIO, (f),(s))
#define PerlSIO_freopen(p, m, f) \
(*PL_StdIO->pReopen)(PL_StdIO, (p), (m), (f))
#define PerlSIO_fread(buf,sz,count,f) \
(*PL_StdIO->pRead)(PL_StdIO, (buf), (sz), (count), (f))
#define PerlSIO_fwrite(buf,sz,count,f) \
(*PL_StdIO->pWrite)(PL_StdIO, (buf), (sz), (count), (f))
#define PerlSIO_setbuf(f,b) \
(*PL_StdIO->pSetBuf)(PL_StdIO, (f), (b))
#define PerlSIO_setvbuf(f,b,t,s) \
(*PL_StdIO->pSetVBuf)(PL_StdIO, (f),(b),(t),(s))
#define PerlSIO_set_cnt(f,c) \
(*PL_StdIO->pSetCnt)(PL_StdIO, (f), (c))
#define PerlSIO_set_ptr(f,p) \
(*PL_StdIO->pSetPtr)(PL_StdIO, (f), (p))
#define PerlSIO_setlinebuf(f) \
(*PL_StdIO->pSetlinebuf)(PL_StdIO, (f))
#define PerlSIO_printf Perl_fprintf_nocontext
#define PerlSIO_stdoutf Perl_printf_nocontext
#define PerlSIO_vprintf(f,fmt,a) \
(*PL_StdIO->pVprintf)(PL_StdIO, (f),(fmt),a)
#define PerlSIO_ftell(f) \
(*PL_StdIO->pTell)(PL_StdIO, (f))
#define PerlSIO_fseek(f,o,w) \
(*PL_StdIO->pSeek)(PL_StdIO, (f),(o),(w))
#define PerlSIO_fgetpos(f,p) \
(*PL_StdIO->pGetpos)(PL_StdIO, (f),(p))
#define PerlSIO_fsetpos(f,p) \
(*PL_StdIO->pSetpos)(PL_StdIO, (f),(p))
#define PerlSIO_rewind(f) \
(*PL_StdIO->pRewind)(PL_StdIO, (f))
#define PerlSIO_tmpfile() \
(*PL_StdIO->pTmpfile)(PL_StdIO)
(*PL_StdIO->pInit)(PL_StdIO)
#define init_os_extras() \
(*PL_StdIO->pInitOSExtras)(PL_StdIO)
#define PerlSIO_fdupopen(f) \
(*PL_StdIO->pFdupopen)(PL_StdIO, (f))
#else /* PERL_IMPLICIT_SYS */
#define PerlSIO_stdin stdin
#define PerlSIO_stdout stdout
#define PerlSIO_stderr stderr
#define PerlSIO_fopen(x,y) fopen(x,y)
/* Work around VOS bug posix-979, wrongly setting errno when at end of file. */
#define PerlSIO_fclose(f) (((errno==1025)?errno=0:0),fclose(f))
#define PerlSIO_feof(f) (((errno==1025)?errno=0:0),feof(f))
#define PerlSIO_ferror(f) (((errno==1025)?errno=0:0),ferror(f))
#define PerlSIO_fclose(f) fclose(f)
#define PerlSIO_feof(f) feof(f)
#define PerlSIO_ferror(f) ferror(f)
#define PerlSIO_clearerr(f) clearerr(f)
#define PerlSIO_fgetc(f) fgetc(f)
#define PerlSIO_get_base(f) FILE_base(f)
#define PerlSIO_get_bufsiz(f) FILE_bufsiz(f)
#define PerlSIO_get_base(f) NULL
#define PerlSIO_get_bufsiz(f) 0
#define PerlSIO_get_cnt(f) FILE_cnt(f)
#define PerlSIO_get_ptr(f) FILE_ptr(f)
#define PerlSIO_get_cnt(f) 0
#define PerlSIO_get_ptr(f) NULL
#define PerlSIO_fputc(c,f) fputc(c,f)
#define PerlSIO_fputs(s,f) fputs(s,f)
#define PerlSIO_fflush(f) Fflush(f)
#define PerlSIO_fgets(s, n, f) fgets(s,n,f)
/* Unusual definition of ungetc() here to accommodate fast_sv_gets()'
* belief that it can mix getc/ungetc with reads from stdio buffer */
int decc$ungetc(int __c, FILE *__stream);
# define PerlSIO_ungetc(c,f) ((c) == EOF ? EOF : \
((*(f) && !((*(f))->_flag & _IONBF) && \
((*(f))->_ptr > (*(f))->_base)) ? \
((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f)))
# define PerlSIO_ungetc(c,f) ungetc(c,f)
#define PerlSIO_fileno(f) fileno(f)
#define PerlSIO_fdopen(f, s) fdopen(f,s)
#define PerlSIO_freopen(p, m, f) freopen(p,m,f)
#define PerlSIO_fread(buf,sz,count,f) fread(buf,sz,count,f)
#define PerlSIO_fwrite(buf,sz,count,f) fwrite(buf,sz,count,f)
#define PerlSIO_setbuf(f,b) setbuf(f,b)
#define PerlSIO_setvbuf(f,b,t,s) setvbuf(f,b,t,s)
#if defined(USE_STDIO_PTR) && defined(STDIO_CNT_LVALUE)
#define PerlSIO_set_cnt(f,c) FILE_cnt(f) = (c)
#define PerlSIO_set_cnt(f,c) PerlIOProc_abort()
#if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE)
#define PerlSIO_set_ptr(f,p) (FILE_ptr(f) = (p))
#define PerlSIO_set_ptr(f,p) PerlIOProc_abort()
#define PerlSIO_setlinebuf(f) setlinebuf(f)
#define PerlSIO_printf fprintf
#define PerlSIO_stdoutf printf
#define PerlSIO_vprintf(f,fmt,a) vfprintf(f,fmt,a)
#define PerlSIO_ftell(f) ftell(f)
#define PerlSIO_fseek(f,o,w) fseek(f,o,w)
#define PerlSIO_fgetpos(f,p) fgetpos(f,p)
#define PerlSIO_fsetpos(f,p) fsetpos(f,p)
#define PerlSIO_rewind(f) rewind(f)
#define PerlSIO_tmpfile() tmpfile()
#define PerlSIO_fdupopen(f) (f)
#endif /* PERL_IMPLICIT_SYS */
* Interface for directory functions
#if defined(PERL_IMPLICIT_SYS)
typedef int (*LPMakedir)(struct IPerlDir*, const char*, int);
typedef int (*LPChdir)(struct IPerlDir*, const char*);
typedef int (*LPRmdir)(struct IPerlDir*, const char*);
typedef int (*LPDirClose)(struct IPerlDir*, DIR*);
typedef DIR* (*LPDirOpen)(struct IPerlDir*, const char*);
typedef struct direct* (*LPDirRead)(struct IPerlDir*, DIR*);
typedef void (*LPDirRewind)(struct IPerlDir*, DIR*);
typedef void (*LPDirSeek)(struct IPerlDir*, DIR*, long);
typedef long (*LPDirTell)(struct IPerlDir*, DIR*);
typedef char* (*LPDirMapPathA)(struct IPerlDir*, const char*);
typedef WCHAR* (*LPDirMapPathW)(struct IPerlDir*, const WCHAR*);
unsigned long nCount; /* number of entries expected */
struct IPerlDir perlDirList;
#define PerlDir_mkdir(name, mode) \
(*PL_Dir->pMakedir)(PL_Dir, (name), (mode))
#define PerlDir_chdir(name) \
(*PL_Dir->pChdir)(PL_Dir, (name))
#define PerlDir_rmdir(name) \
(*PL_Dir->pRmdir)(PL_Dir, (name))
#define PerlDir_close(dir) \
(*PL_Dir->pClose)(PL_Dir, (dir))
#define PerlDir_open(name) \
(*PL_Dir->pOpen)(PL_Dir, (name))
#define PerlDir_read(dir) \
(*PL_Dir->pRead)(PL_Dir, (dir))
#define PerlDir_rewind(dir) \
(*PL_Dir->pRewind)(PL_Dir, (dir))
#define PerlDir_seek(dir, loc) \
(*PL_Dir->pSeek)(PL_Dir, (dir), (loc))
#define PerlDir_tell(dir) \
(*PL_Dir->pTell)(PL_Dir, (dir))
#define PerlDir_mapA(dir) \
(*PL_Dir->pMapPathA)(PL_Dir, (dir))
#define PerlDir_mapW(dir) \
(*PL_Dir->pMapPathW)(PL_Dir, (dir))
#else /* PERL_IMPLICIT_SYS */
#define PerlDir_mkdir(name, mode) Mkdir((name), (mode))
# define PerlDir_chdir(n) Chdir((n))
# define PerlDir_chdir(name) chdir((name))
#define PerlDir_rmdir(name) rmdir((name))
#define PerlDir_close(dir) closedir((dir))
#define PerlDir_open(name) opendir((name))
#define PerlDir_read(dir) readdir((dir))
#define PerlDir_rewind(dir) rewinddir((dir))
#define PerlDir_seek(dir, loc) seekdir((dir), (loc))
#define PerlDir_tell(dir) telldir((dir))
#define PerlDir_mapA(dir) dir
#define PerlDir_mapW(dir) dir
#endif /* PERL_IMPLICIT_SYS */
Interface for perl environment functions
#if defined(PERL_IMPLICIT_SYS)
typedef char* (*LPEnvGetenv)(struct IPerlEnv*, const char*);
typedef int (*LPEnvPutenv)(struct IPerlEnv*, const char*);
typedef char* (*LPEnvGetenv_len)(struct IPerlEnv*,
const char *varname, unsigned long *len);
typedef int (*LPEnvUname)(struct IPerlEnv*, struct utsname *name);
typedef void (*LPEnvClearenv)(struct IPerlEnv*);
typedef void* (*LPEnvGetChildenv)(struct IPerlEnv*);
typedef void (*LPEnvFreeChildenv)(struct IPerlEnv*, void* env);
typedef char* (*LPEnvGetChilddir)(struct IPerlEnv*);
typedef void (*LPEnvFreeChilddir)(struct IPerlEnv*, char* dir);
typedef char* (*LPENVGetenv)(struct IPerlEnv*, const char *varname);
typedef char* (*LPENVGetenv_len)(struct IPerlEnv*,
const char *varname, unsigned long *len);
typedef unsigned long (*LPEnvOsID)(struct IPerlEnv*);
typedef char* (*LPEnvLibPath)(struct IPerlEnv*, WIN32_NO_REGISTRY_M_(const char*)
typedef char* (*LPEnvSiteLibPath)(struct IPerlEnv*, const char*,
typedef char* (*LPEnvVendorLibPath)(struct IPerlEnv*, const char*,
typedef void (*LPEnvGetChildIO)(struct IPerlEnv*, child_IO_table*);
LPEnvGetenv_len pGetenv_len;
LPEnvGetChildenv pGetChildenv;
LPEnvFreeChildenv pFreeChildenv;
LPEnvGetChilddir pGetChilddir;
LPEnvFreeChilddir pFreeChilddir;