X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/888911fcc68a18021b42aeaddb5cb8725ce411af..4fdcb09baafee5a8d18f22e92f6336a504d38b63:/perlio.h diff --git a/perlio.h b/perlio.h index 9af62f5..1a3d480 100644 --- a/perlio.h +++ b/perlio.h @@ -1,32 +1,139 @@ -#ifndef H_PERLIO -#define H_PERLIO 1 - -/* Clean up (or at least document) the various possible #defines. - This section attempts to match the 5.003_03 Configure variables - onto the 5.003_02 header file values. - I can't figure out where USE_STDIO was supposed to be set. - --AD +/* perlio.h + * + * Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, + * 2004, 2005, 2006, 2007, by Larry Wall and others + * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the README file. + * + */ + +#ifndef _PERLIO_H +#define _PERLIO_H +/* + Interface for perl to IO functions. + There is a hierarchy of Configure determined #define controls: + USE_STDIO - No longer available via Configure. Formerly forced + PerlIO_xxx() to be #define-d onto stdio functions. + Now generates compile-time error. + + USE_PERLIO - The primary Configure variable that enables PerlIO. + PerlIO_xxx() are real functions + defined in perlio.c which implement extra functionality + required for utf8 support. + */ + #ifndef USE_PERLIO -# define PERLIO_IS_STDIO +# define USE_STDIO #endif -/* Below is the 5.003_02 stuff. */ #ifdef USE_STDIO -# ifndef PERLIO_IS_STDIO -# define PERLIO_IS_STDIO +# error "stdio is no longer supported as the default base layer -- use perlio." +#endif + +/* -------------------- End of Configure controls ---------------------------- */ + +/* + * Although we may not want stdio to be used including here + * avoids issues where stdio.h has strange side effects + */ +#include + +#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64) +#define ftell ftello +#endif + +#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64) +#define fseek fseeko +#endif + +/* BS2000 includes are sometimes a bit non standard :-( */ +#if defined(POSIX_BC) && defined(O_BINARY) && !defined(O_TEXT) +#undef O_BINARY +#endif + +#ifndef PerlIO +/* ----------- PerlIO implementation ---------- */ +/* PerlIO not #define-d to something else - define the implementation */ + +typedef struct _PerlIO PerlIOl; +typedef struct _PerlIO_funcs PerlIO_funcs; +typedef PerlIOl *PerlIO; +#define PerlIO PerlIO +#define PERLIO_LAYERS 1 + +/* PERLIO_FUNCS_CONST is now on by default for efficiency, PERLIO_FUNCS_CONST + can be removed 1 day once stable & then PerlIO vtables are permanently RO */ +#ifdef PERLIO_FUNCS_CONST +#define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs +#define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) +#else +#define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs +#define PERLIO_FUNCS_CAST(funcs) (funcs) +#endif + +PERL_CALLCONV void PerlIO_define_layer(pTHX_ PerlIO_funcs *tab); +PERL_CALLCONV PerlIO_funcs *PerlIO_find_layer(pTHX_ const char *name, + STRLEN len, + int load); +PERL_CALLCONV PerlIO *PerlIO_push(pTHX_ PerlIO *f, PERLIO_FUNCS_DECL(*tab), + const char *mode, SV *arg); +PERL_CALLCONV void PerlIO_pop(pTHX_ PerlIO *f); +PERL_CALLCONV AV* PerlIO_get_layers(pTHX_ PerlIO *f); +PERL_CALLCONV void PerlIO_clone(pTHX_ PerlInterpreter *proto, + CLONE_PARAMS *param); + +#endif /* PerlIO */ + +/* ----------- End of implementation choices ---------- */ + +/* We now need to determine what happens if source trys to use stdio. + * There are three cases based on PERLIO_NOT_STDIO which XS code + * can set how it wants. + */ + +#ifdef PERL_CORE +/* Make a choice for perl core code + - currently this is set to try and catch lingering raw stdio calls. + This is a known issue with some non UNIX ports which still use + "native" stdio features. +*/ +# ifndef PERLIO_NOT_STDIO +# define PERLIO_NOT_STDIO 1 # endif #else -extern void PerlIO_init _((void)); +# ifndef PERLIO_NOT_STDIO +# define PERLIO_NOT_STDIO 0 +# endif #endif -#include "perlsdio.h" +#ifdef PERLIO_NOT_STDIO +#if PERLIO_NOT_STDIO +/* + * PERLIO_NOT_STDIO #define'd as 1 + * Case 1: Strong denial of stdio - make all stdio calls (we can think of) errors + */ +#include "nostdio.h" +#else /* if PERLIO_NOT_STDIO */ +/* + * PERLIO_NOT_STDIO #define'd as 0 + * Case 2: Declares that both PerlIO and stdio can be used + */ +#endif /* if PERLIO_NOT_STDIO */ +#else /* ifdef PERLIO_NOT_STDIO */ +/* + * PERLIO_NOT_STDIO not defined + * Case 3: Try and fake stdio calls as PerlIO calls + */ +#include "fakesdio.h" +#endif /* ifndef PERLIO_NOT_STDIO */ -#ifndef PERLIO_IS_STDIO -#ifdef USE_SFIO -#include "perlsfio.h" -#endif /* USE_SFIO */ -#endif /* PERLIO_IS_STDIO */ +/* ----------- fill in things that have not got #define'd ---------- */ + +#ifndef Fpos_t +#define Fpos_t Off_t +#endif #ifndef EOF #define EOF (-1) @@ -37,6 +144,11 @@ extern void PerlIO_init _((void)); #define BUFSIZ 1024 #endif +/* The default buffer size for the perlio buffering layer */ +#ifndef PERLIOBUF_DEFAULT_BUFSIZ +#define PERLIOBUF_DEFAULT_BUFSIZ (BUFSIZ > 8192 ? BUFSIZ : 8192) +#endif + #ifndef SEEK_SET #define SEEK_SET 0 #endif @@ -49,151 +161,183 @@ extern void PerlIO_init _((void)); #define SEEK_END 2 #endif -#ifndef PerlIO -struct _PerlIO; -#define PerlIO struct _PerlIO -#endif /* No PerlIO */ +#define PERLIO_DUP_CLONE 1 +#define PERLIO_DUP_FD 2 -#ifndef Fpos_t -#define Fpos_t long -#endif +/* --------------------- Now prototypes for functions --------------- */ -#ifndef NEXT30_NO_ATTRIBUTE -#ifndef HASATTRIBUTE /* disable GNU-cc attribute checking? */ -#ifdef __attribute__ /* Avoid possible redefinition errors */ -#undef __attribute__ -#endif -#define __attribute__(attr) +START_EXTERN_C +#ifndef __attribute__format__ +# ifdef HASATTRIBUTE_FORMAT +# define __attribute__format__(x,y,z) __attribute__((format(x,y,z))) +# else +# define __attribute__format__(x,y,z) +# endif #endif +#ifndef PerlIO_init +PERL_CALLCONV void PerlIO_init(pTHX); #endif - #ifndef PerlIO_stdoutf -extern int PerlIO_stdoutf _((const char *,...)) - __attribute__((format (printf, 1, 2))); +PERL_CALLCONV int PerlIO_stdoutf(const char *, ...) + __attribute__format__(__printf__, 1, 2); #endif #ifndef PerlIO_puts -extern int PerlIO_puts _((PerlIO *,const char *)); +PERL_CALLCONV int PerlIO_puts(PerlIO *, const char *); #endif #ifndef PerlIO_open -extern PerlIO * PerlIO_open _((const char *,const char *)); +PERL_CALLCONV PerlIO *PerlIO_open(const char *, const char *); #endif -#ifndef PerlIO_close -extern int PerlIO_close _((PerlIO *)); +#ifndef PerlIO_openn +PERL_CALLCONV PerlIO *PerlIO_openn(pTHX_ const char *layers, const char *mode, + int fd, int imode, int perm, PerlIO *old, + int narg, SV **arg); #endif #ifndef PerlIO_eof -extern int PerlIO_eof _((PerlIO *)); +PERL_CALLCONV int PerlIO_eof(PerlIO *); #endif #ifndef PerlIO_error -extern int PerlIO_error _((PerlIO *)); +PERL_CALLCONV int PerlIO_error(PerlIO *); #endif #ifndef PerlIO_clearerr -extern void PerlIO_clearerr _((PerlIO *)); +PERL_CALLCONV void PerlIO_clearerr(PerlIO *); #endif #ifndef PerlIO_getc -extern int PerlIO_getc _((PerlIO *)); +PERL_CALLCONV int PerlIO_getc(PerlIO *); #endif #ifndef PerlIO_putc -extern int PerlIO_putc _((PerlIO *,int)); -#endif -#ifndef PerlIO_flush -extern int PerlIO_flush _((PerlIO *)); +PERL_CALLCONV int PerlIO_putc(PerlIO *, int); #endif #ifndef PerlIO_ungetc -extern int PerlIO_ungetc _((PerlIO *,int)); -#endif -#ifndef PerlIO_fileno -extern int PerlIO_fileno _((PerlIO *)); +PERL_CALLCONV int PerlIO_ungetc(PerlIO *, int); #endif #ifndef PerlIO_fdopen -extern PerlIO * PerlIO_fdopen _((int, const char *)); +PERL_CALLCONV PerlIO *PerlIO_fdopen(int, const char *); #endif #ifndef PerlIO_importFILE -extern PerlIO * PerlIO_importFILE _((FILE *,int)); +PERL_CALLCONV PerlIO *PerlIO_importFILE(FILE *, const char *); #endif #ifndef PerlIO_exportFILE -extern FILE * PerlIO_exportFILE _((PerlIO *,int)); +PERL_CALLCONV FILE *PerlIO_exportFILE(PerlIO *, const char *); #endif #ifndef PerlIO_findFILE -extern FILE * PerlIO_findFILE _((PerlIO *)); +PERL_CALLCONV FILE *PerlIO_findFILE(PerlIO *); #endif #ifndef PerlIO_releaseFILE -extern void PerlIO_releaseFILE _((PerlIO *,FILE *)); +PERL_CALLCONV void PerlIO_releaseFILE(PerlIO *, FILE *); #endif #ifndef PerlIO_read -extern int PerlIO_read _((PerlIO *,void *,size_t)); +PERL_CALLCONV SSize_t PerlIO_read(PerlIO *, void *, Size_t); +#endif +#ifndef PerlIO_unread +PERL_CALLCONV SSize_t PerlIO_unread(PerlIO *, const void *, Size_t); #endif #ifndef PerlIO_write -extern int PerlIO_write _((PerlIO *,const void *,size_t)); +PERL_CALLCONV SSize_t PerlIO_write(PerlIO *, const void *, Size_t); #endif #ifndef PerlIO_setlinebuf -extern void PerlIO_setlinebuf _((PerlIO *)); +PERL_CALLCONV void PerlIO_setlinebuf(PerlIO *); #endif #ifndef PerlIO_printf -extern int PerlIO_printf _((PerlIO *, const char *,...)) - __attribute__((format (printf, 2, 3))); -#endif -#ifndef PerlIO_sprintf -extern int PerlIO_sprintf _((char *, int, const char *,...)) - __attribute__((format (printf, 3, 4))); +PERL_CALLCONV int PerlIO_printf(PerlIO *, const char *, ...) + __attribute__format__(__printf__, 2, 3); #endif #ifndef PerlIO_vprintf -extern int PerlIO_vprintf _((PerlIO *, const char *, va_list)); +PERL_CALLCONV int PerlIO_vprintf(PerlIO *, const char *, va_list); #endif #ifndef PerlIO_tell -extern long PerlIO_tell _((PerlIO *)); +PERL_CALLCONV Off_t PerlIO_tell(PerlIO *); #endif #ifndef PerlIO_seek -extern int PerlIO_seek _((PerlIO *,off_t,int)); +PERL_CALLCONV int PerlIO_seek(PerlIO *, Off_t, int); #endif #ifndef PerlIO_rewind -extern void PerlIO_rewind _((PerlIO *)); +PERL_CALLCONV void PerlIO_rewind(PerlIO *); #endif #ifndef PerlIO_has_base -extern int PerlIO_has_base _((PerlIO *)); +PERL_CALLCONV int PerlIO_has_base(PerlIO *); #endif #ifndef PerlIO_has_cntptr -extern int PerlIO_has_cntptr _((PerlIO *)); +PERL_CALLCONV int PerlIO_has_cntptr(PerlIO *); #endif #ifndef PerlIO_fast_gets -extern int PerlIO_fast_gets _((PerlIO *)); +PERL_CALLCONV int PerlIO_fast_gets(PerlIO *); #endif #ifndef PerlIO_canset_cnt -extern int PerlIO_canset_cnt _((PerlIO *)); +PERL_CALLCONV int PerlIO_canset_cnt(PerlIO *); #endif #ifndef PerlIO_get_ptr -extern STDCHAR * PerlIO_get_ptr _((PerlIO *)); +PERL_CALLCONV STDCHAR *PerlIO_get_ptr(PerlIO *); #endif #ifndef PerlIO_get_cnt -extern int PerlIO_get_cnt _((PerlIO *)); +PERL_CALLCONV SSize_t PerlIO_get_cnt(PerlIO *); #endif #ifndef PerlIO_set_cnt -extern void PerlIO_set_cnt _((PerlIO *,int)); +PERL_CALLCONV void PerlIO_set_cnt(PerlIO *, SSize_t); #endif #ifndef PerlIO_set_ptrcnt -extern void PerlIO_set_ptrcnt _((PerlIO *,STDCHAR *,int)); +PERL_CALLCONV void PerlIO_set_ptrcnt(PerlIO *, STDCHAR *, SSize_t); #endif #ifndef PerlIO_get_base -extern STDCHAR * PerlIO_get_base _((PerlIO *)); +PERL_CALLCONV STDCHAR *PerlIO_get_base(PerlIO *); #endif #ifndef PerlIO_get_bufsiz -extern int PerlIO_get_bufsiz _((PerlIO *)); +PERL_CALLCONV SSize_t PerlIO_get_bufsiz(PerlIO *); #endif #ifndef PerlIO_tmpfile -extern PerlIO * PerlIO_tmpfile _((void)); +PERL_CALLCONV PerlIO *PerlIO_tmpfile(void); #endif #ifndef PerlIO_stdin -extern PerlIO * PerlIO_stdin _((void)); +PERL_CALLCONV PerlIO *PerlIO_stdin(void); #endif #ifndef PerlIO_stdout -extern PerlIO * PerlIO_stdout _((void)); +PERL_CALLCONV PerlIO *PerlIO_stdout(void); #endif #ifndef PerlIO_stderr -extern PerlIO * PerlIO_stderr _((void)); +PERL_CALLCONV PerlIO *PerlIO_stderr(void); #endif #ifndef PerlIO_getpos -extern int PerlIO_getpos _((PerlIO *,Fpos_t *)); +PERL_CALLCONV int PerlIO_getpos(PerlIO *, SV *); #endif #ifndef PerlIO_setpos -extern int PerlIO_setpos _((PerlIO *,const Fpos_t *)); +PERL_CALLCONV int PerlIO_setpos(PerlIO *, SV *); +#endif +#ifndef PerlIO_fdupopen +PERL_CALLCONV PerlIO *PerlIO_fdupopen(pTHX_ PerlIO *, CLONE_PARAMS *, int); #endif -#endif /* Include guard */ +#if !defined(PerlIO_modestr) +PERL_CALLCONV char *PerlIO_modestr(PerlIO *, char *buf); +#endif +#ifndef PerlIO_isutf8 +PERL_CALLCONV int PerlIO_isutf8(PerlIO *); +#endif +#ifndef PerlIO_apply_layers +PERL_CALLCONV int PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, + const char *names); +#endif +#ifndef PerlIO_binmode +PERL_CALLCONV int PerlIO_binmode(pTHX_ PerlIO *f, int iotype, int omode, + const char *names); +#endif +#ifndef PerlIO_getname +PERL_CALLCONV char *PerlIO_getname(PerlIO *, char *); +#endif + +PERL_CALLCONV void PerlIO_destruct(pTHX); + +PERL_CALLCONV int PerlIO_intmode2str(int rawmode, char *mode, int *writing); + +#ifdef PERLIO_LAYERS +PERL_CALLCONV void PerlIO_cleanup(pTHX); + +PERL_CALLCONV void PerlIO_debug(const char *fmt, ...) + __attribute__format__(__printf__, 1, 2); +typedef struct PerlIO_list_s PerlIO_list_t; + +#endif + +END_EXTERN_C +#endif /* _PERLIO_H */ + +/* + * ex: set ts=8 sts=4 sw=4 et: + */