| 1 | /* perlio.h
|
|---|
| 2 | *
|
|---|
| 3 | * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003,
|
|---|
| 4 | * by Larry Wall and others
|
|---|
| 5 | *
|
|---|
| 6 | * You may distribute under the terms of either the GNU General Public
|
|---|
| 7 | * License or the Artistic License, as specified in the README file.
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | #ifndef _PERLIO_H
|
|---|
| 12 | #define _PERLIO_H
|
|---|
| 13 | /*
|
|---|
| 14 | Interface for perl to IO functions.
|
|---|
| 15 | There is a hierarchy of Configure determined #define controls:
|
|---|
| 16 | USE_STDIO - forces PerlIO_xxx() to be #define-d onto stdio functions.
|
|---|
| 17 | This is used for x2p subdirectory and for conservative
|
|---|
| 18 | builds - "just like perl5.00X used to be".
|
|---|
| 19 | This dominates over the others.
|
|---|
| 20 |
|
|---|
| 21 | USE_PERLIO - The primary Configure variable that enables PerlIO.
|
|---|
| 22 | If USE_PERLIO is _NOT_ set
|
|---|
| 23 | then USE_STDIO above will be set to be conservative.
|
|---|
| 24 | If USE_PERLIO is set
|
|---|
| 25 | then there are two modes determined by USE_SFIO:
|
|---|
| 26 |
|
|---|
| 27 | USE_SFIO - If set causes PerlIO_xxx() to be #define-d onto sfio functions.
|
|---|
| 28 | A backward compatability mode for some specialist applications.
|
|---|
| 29 |
|
|---|
| 30 | If USE_SFIO is not set then PerlIO_xxx() are real functions
|
|---|
| 31 | defined in perlio.c which implement extra functionality
|
|---|
| 32 | required for utf8 support.
|
|---|
| 33 |
|
|---|
| 34 | One further note - the table-of-functions scheme controlled
|
|---|
| 35 | by PERL_IMPLICIT_SYS turns on USE_PERLIO so that iperlsys.h can
|
|---|
| 36 | #define PerlIO_xxx() to go via the function table, without having
|
|---|
| 37 | to #undef them from (say) stdio forms.
|
|---|
| 38 |
|
|---|
| 39 | */
|
|---|
| 40 |
|
|---|
| 41 | #if defined(PERL_IMPLICIT_SYS)
|
|---|
| 42 | #ifndef USE_PERLIO
|
|---|
| 43 | #ifndef NETWARE
|
|---|
| 44 | /* # define USE_PERLIO */
|
|---|
| 45 | #endif
|
|---|
| 46 | #endif
|
|---|
| 47 | #endif
|
|---|
| 48 |
|
|---|
| 49 | #ifndef USE_PERLIO
|
|---|
| 50 | # define USE_STDIO
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | #ifdef USE_STDIO
|
|---|
| 54 | # ifndef PERLIO_IS_STDIO
|
|---|
| 55 | # define PERLIO_IS_STDIO
|
|---|
| 56 | # endif
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | /* -------------------- End of Configure controls ---------------------------- */
|
|---|
| 60 |
|
|---|
| 61 | /*
|
|---|
| 62 | * Although we may not want stdio to be used including <stdio.h> here
|
|---|
| 63 | * avoids issues where stdio.h has strange side effects
|
|---|
| 64 | */
|
|---|
| 65 | #include <stdio.h>
|
|---|
| 66 |
|
|---|
| 67 | #ifdef __BEOS__
|
|---|
| 68 | int fseeko(FILE *stream, off_t offset, int whence);
|
|---|
| 69 | off_t ftello(FILE *stream);
|
|---|
| 70 | #endif
|
|---|
| 71 |
|
|---|
| 72 | #if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64)
|
|---|
| 73 | #define ftell ftello
|
|---|
| 74 | #endif
|
|---|
| 75 |
|
|---|
| 76 | #if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64)
|
|---|
| 77 | #define fseek fseeko
|
|---|
| 78 | #endif
|
|---|
| 79 |
|
|---|
| 80 | /* BS2000 includes are sometimes a bit non standard :-( */
|
|---|
| 81 | #if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT)
|
|---|
| 82 | #undef O_BINARY
|
|---|
| 83 | #endif
|
|---|
| 84 |
|
|---|
| 85 | #ifdef PERLIO_IS_STDIO
|
|---|
| 86 | /* #define PerlIO_xxxx() as equivalent stdio function */
|
|---|
| 87 | #include "perlsdio.h"
|
|---|
| 88 | #else /* PERLIO_IS_STDIO */
|
|---|
| 89 | #ifdef USE_SFIO
|
|---|
| 90 | /* #define PerlIO_xxxx() as equivalent sfio function */
|
|---|
| 91 | #include "perlsfio.h"
|
|---|
| 92 | #endif /* USE_SFIO */
|
|---|
| 93 | #endif /* PERLIO_IS_STDIO */
|
|---|
| 94 |
|
|---|
| 95 | #ifndef PerlIO
|
|---|
| 96 | /* ----------- PerlIO implementation ---------- */
|
|---|
| 97 | /* PerlIO not #define-d to something else - define the implementation */
|
|---|
| 98 |
|
|---|
| 99 | typedef struct _PerlIO PerlIOl;
|
|---|
| 100 | typedef struct _PerlIO_funcs PerlIO_funcs;
|
|---|
| 101 | typedef PerlIOl *PerlIO;
|
|---|
| 102 | #define PerlIO PerlIO
|
|---|
| 103 | #define PERLIO_LAYERS 1
|
|---|
| 104 |
|
|---|
| 105 | /* Making the big PerlIO_funcs vtables const is good (enables placing
|
|---|
| 106 | * them in the const section which is good for speed, security, and
|
|---|
| 107 | * embeddability) but this cannot be done by default because of
|
|---|
| 108 | * backward compatibility. */
|
|---|
| 109 | #ifdef PERLIO_FUNCS_CONST
|
|---|
| 110 | #define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs
|
|---|
| 111 | #define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs)
|
|---|
| 112 | #else
|
|---|
| 113 | #define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs
|
|---|
| 114 | #define PERLIO_FUNCS_CAST(funcs) (funcs)
|
|---|
| 115 | #endif
|
|---|
| 116 |
|
|---|
| 117 | PERL_EXPORT_C void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab);
|
|---|
| 118 | PERL_EXPORT_C PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name,
|
|---|
| 119 | STRLEN len,
|
|---|
| 120 | int load);
|
|---|
| 121 | PERL_EXPORT_C PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab),
|
|---|
| 122 | const char *mode, SV *arg);
|
|---|
| 123 | PERL_EXPORT_C void PerlIO_pop(pTHX_ PerlIO *f);
|
|---|
| 124 | PERL_EXPORT_C AV* PerlIO_get_layers(pTHX_ PerlIO *f);
|
|---|
| 125 | PERL_EXPORT_C void PerlIO_clone(pTHX_ PerlInterpreter *proto,
|
|---|
| 126 | CLONE_PARAMS *param);
|
|---|
| 127 |
|
|---|
| 128 | #endif /* PerlIO */
|
|---|
| 129 |
|
|---|
| 130 | /* ----------- End of implementation choices ---------- */
|
|---|
| 131 |
|
|---|
| 132 | #ifndef PERLIO_IS_STDIO
|
|---|
| 133 | /* Not using stdio _directly_ as PerlIO */
|
|---|
| 134 |
|
|---|
| 135 | /* We now need to determine what happens if source trys to use stdio.
|
|---|
| 136 | * There are three cases based on PERLIO_NOT_STDIO which XS code
|
|---|
| 137 | * can set how it wants.
|
|---|
| 138 | */
|
|---|
| 139 |
|
|---|
| 140 | #ifdef PERL_CORE
|
|---|
| 141 | /* Make a choice for perl core code
|
|---|
| 142 | - currently this is set to try and catch lingering raw stdio calls.
|
|---|
| 143 | This is a known issue with some non UNIX ports which still use
|
|---|
| 144 | "native" stdio features.
|
|---|
| 145 | */
|
|---|
| 146 | #ifndef PERLIO_NOT_STDIO
|
|---|
| 147 | #define PERLIO_NOT_STDIO 1
|
|---|
| 148 | #endif
|
|---|
| 149 | #else
|
|---|
| 150 | #ifndef PERLIO_NOT_STDIO
|
|---|
| 151 | #define PERLIO_NOT_STDIO 0
|
|---|
| 152 | #endif
|
|---|
| 153 | #endif
|
|---|
| 154 |
|
|---|
| 155 | #ifdef PERLIO_NOT_STDIO
|
|---|
| 156 | #if PERLIO_NOT_STDIO
|
|---|
|
|---|