From: Nick Ing-Simmons Date: Tue, 14 Nov 2000 17:43:04 +0000 (+0000) Subject: PerlIO #include and #ifdef re-work. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=76ced9add7b621dfc9d4ecb534aeea8e131a418a;p=p5sagit%2Fp5-mst-13.2.git PerlIO #include and #ifdef re-work. p4raw-id: //depot/perlio@7684 --- diff --git a/MANIFEST b/MANIFEST index eb1ec5c..6d71e69 100644 --- a/MANIFEST +++ b/MANIFEST @@ -442,6 +442,7 @@ ext/re/re.xs re extension external subroutines ext/util/make_ext Used by Makefile to execute extension Makefiles ext/util/mkbootstrap Turns ext/*/*_BS into bootstrap info fakethr.h Fake threads header +fakesdio.h stdio in terms of PerlIO form.h Public declarations for the above global.sym Symbols that need hiding when embedded globals.c File to declare global symbols (for shared library) @@ -1147,7 +1148,8 @@ perl.h Global declarations perlapi.c Perl API functions perlapi.h Perl API function declarations perlio.c C code for PerlIO abstraction -perlio.h compatibility stub +perlio.h PerlIO abstraction +perliol.h PerlIO Layer definition perlio.sym Symbols for PerlIO abstraction perlsdio.h Fake stdio using perlio perlsfio.h Prototype sfio mapping for PerlIO diff --git a/fakesdio.h b/fakesdio.h new file mode 100644 index 0000000..19aa0c9 --- /dev/null +++ b/fakesdio.h @@ -0,0 +1,104 @@ +/* + * This is "source level" stdio compatibility mode. + * We try and #define stdio functions in terms of PerlIO. + */ +#define _CANNOT "CANNOT" +#undef FILE +#define FILE PerlIO +#undef fprintf +#undef tmpfile +#undef fclose +#undef fopen +#undef vfprintf +#undef fgetc +#undef getc_unlocked +#undef fputc +#undef putc_unlocked +#undef fputs +#undef ungetc +#undef fread +#undef fwrite +#undef fgetpos +#undef fseek +#undef fsetpos +#undef ftell +#undef rewind +#undef fdopen +#undef popen +#undef pclose +#undef getw +#undef putw +#undef freopen +#undef setbuf +#undef setvbuf +#undef fscanf +#undef fgets +#undef stdin +#undef stdout +#undef stderr +#undef getc +#undef putc +#undef clearerr +#undef feof +#undef ferror +#define fprintf PerlIO_printf +#define stdin PerlIO_stdin() +#define stdout PerlIO_stdout() +#define stderr PerlIO_stderr() +#define tmpfile() PerlIO_tmpfile() +#define fclose(f) PerlIO_close(f) +#define fflush(f) PerlIO_flush(f) +#define fopen(p,m) PerlIO_open(p,m) +#define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a) +#define fgetc(f) PerlIO_getc(f) +#define fputc(c,f) PerlIO_putc(f,c) +#define fputs(s,f) PerlIO_puts(f,s) +#define getc(f) PerlIO_getc(f) +#ifdef getc_unlocked +#undef getc_unlocked +#endif +#define getc_unlocked(f) PerlIO_getc(f) +#define putc(c,f) PerlIO_putc(f,c) +#ifdef putc_unlocked +#undef putc_unlocked +#endif +#define putc_unlocked(c,f) PerlIO_putc(c,f) +#define ungetc(c,f) PerlIO_ungetc(f,c) +#if 0 +/* return values of read/write need work */ +#define fread(b,s,c,f) PerlIO_read(f,b,(s*c)) +#define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c)) +#else +#define fread(b,s,c,f) _CANNOT fread +#define fwrite(b,s,c,f) _CANNOT fwrite +#endif +#define fgetpos(f,p) PerlIO_getpos(f,p) +#define fseek(f,o,w) PerlIO_seek(f,o,w) +#define fsetpos(f,p) PerlIO_setpos(f,p) +#define ftell(f) PerlIO_tell(f) +#define rewind(f) PerlIO_rewind(f) +#define clearerr(f) PerlIO_clearerr(f) +#define feof(f) PerlIO_eof(f) +#define ferror(f) PerlIO_error(f) +#define fdopen(fd,p) PerlIO_fdopen(fd,p) +#define fileno(f) PerlIO_fileno(f) +#define popen(c,m) my_popen(c,m) +#define pclose(f) my_pclose(f) + +#define __filbuf(f) _CANNOT __filbuf_ +#define _filbuf(f) _CANNOT _filbuf_ +#define __flsbuf(c,f) _CANNOT __flsbuf_ +#define _flsbuf(c,f) _CANNOT _flsbuf_ +#define getw(f) _CANNOT _getw_ +#define putw(v,f) _CANNOT _putw_ +#if SFIO_VERSION < 20000101L +#define flockfile(f) _CANNOT _flockfile_ +#define ftrylockfile(f) _CANNOT _ftrylockfile_ +#define funlockfile(f) _CANNOT _funlockfile_ +#endif +#define freopen(p,m,f) _CANNOT _freopen_ +#define setbuf(f,b) _CANNOT _setbuf_ +#define setvbuf(f,b,x,s) _CANNOT _setvbuf_ +#define fscanf _CANNOT _fscanf_ +#define fgets(s,n,f) _CANNOT _fgets_ + diff --git a/iperlsys.h b/iperlsys.h index 55471cd..9bf7387 100644 --- a/iperlsys.h +++ b/iperlsys.h @@ -49,47 +49,18 @@ * */ - /* - Interface for perl stdio functions + Interface for perl stdio functions, or whatever we are Configure-d + to use. */ - - -/* 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 -*/ -#ifndef USE_PERLIO -# define PERLIO_IS_STDIO -#endif - -/* Below is the 5.003_02 stuff. */ -#ifdef USE_STDIO -# ifndef PERLIO_IS_STDIO -# define PERLIO_IS_STDIO -# endif -#else -extern void PerlIO_init (void); -#endif +#include "perlio.h" #ifndef Sighandler_t typedef Signal_t (*Sighandler_t) (int); #endif -#ifndef Fpos_t -#define Fpos_t Off_t -#endif - #if defined(PERL_IMPLICIT_SYS) -#ifndef PerlIO -typedef struct _PerlIO PerlIOl; -typedef PerlIOl *PerlIO; -#define PerlIO PerlIO -#endif /* No PerlIO */ - /* IPerlStdIO */ struct IPerlStdIO; struct IPerlStdIOInfo; @@ -192,6 +163,8 @@ struct IPerlStdIOInfo struct IPerlStdIO perlStdIOList; }; +/* These do not belong here ... NI-S, 14 Nov 2000 */ + #ifdef USE_STDIO_PTR # define PerlIO_has_cntptr(f) 1 # ifdef STDIO_PTR_LVALUE @@ -223,6 +196,8 @@ struct IPerlStdIOInfo #define PerlIO_has_base(f) 0 #endif +/* Now take PerlIO * via function table */ + #define PerlIO_stdin() \ (*PL_StdIO->pStdin)(PL_StdIO) #define PerlIO_stdout() \ @@ -305,194 +280,8 @@ struct IPerlStdIOInfo #define PerlIO_isutf8(f) \ (*PL_StdIO->pIsUtf8)(PL_StdIO, (f)) -#else /* PERL_IMPLICIT_SYS */ - -#include "perlsdio.h" -#include "perl.h" -#define PerlIO_fdupopen(f) (f) -#define PerlIO_isutf8(f) 0 - #endif /* PERL_IMPLICIT_SYS */ -#ifndef PERLIO_IS_STDIO -#ifdef USE_SFIO -#include "perlsfio.h" -#define PerlIO_isutf8(f) 0 -#endif /* USE_SFIO */ -#endif /* PERLIO_IS_STDIO */ - -#ifndef EOF -#define EOF (-1) -#endif - -/* This is to catch case with no stdio */ -#ifndef BUFSIZ -#define BUFSIZ 1024 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef PerlIO -typedef struct _PerlIO PerlIOl; -typedef PerlIOl *PerlIO; -#define PerlIO PerlIO -#endif /* No PerlIO */ - -#ifndef NEXT30_NO_ATTRIBUTE -#ifndef HASATTRIBUTE /* disable GNU-cc attribute checking? */ -#ifdef __attribute__ /* Avoid possible redefinition errors */ -#undef __attribute__ -#endif -#define __attribute__(attr) -#endif -#endif - -#ifndef PerlIO_stdoutf -extern int PerlIO_stdoutf (const char *,...) - __attribute__((__format__ (__printf__, 1, 2))); -#endif -#ifndef PerlIO_puts -extern int PerlIO_puts (PerlIO *,const char *); -#endif -#ifndef PerlIO_open -extern PerlIO * PerlIO_open (const char *,const char *); -#endif -#ifndef PerlIO_close -extern int PerlIO_close (PerlIO *); -#endif -#ifndef PerlIO_eof -extern int PerlIO_eof (PerlIO *); -#endif -#ifndef PerlIO_error -extern int PerlIO_error (PerlIO *); -#endif -#ifndef PerlIO_clearerr -extern void PerlIO_clearerr (PerlIO *); -#endif -#ifndef PerlIO_getc -extern int PerlIO_getc (PerlIO *); -#endif -#ifndef PerlIO_putc -extern int PerlIO_putc (PerlIO *,int); -#endif -#ifndef PerlIO_flush -extern int PerlIO_flush (PerlIO *); -#endif -#ifndef PerlIO_ungetc -extern int PerlIO_ungetc (PerlIO *,int); -#endif -#ifndef PerlIO_fileno -extern int PerlIO_fileno (PerlIO *); -#endif -#ifndef PerlIO_fdopen -extern PerlIO * PerlIO_fdopen (int, const char *); -#endif -#ifndef PerlIO_importFILE -extern PerlIO * PerlIO_importFILE (FILE *,int); -#endif -#ifndef PerlIO_exportFILE -extern FILE * PerlIO_exportFILE (PerlIO *,int); -#endif -#ifndef PerlIO_findFILE -extern FILE * PerlIO_findFILE (PerlIO *); -#endif -#ifndef PerlIO_releaseFILE -extern void PerlIO_releaseFILE (PerlIO *,FILE *); -#endif -#ifndef PerlIO_read -extern SSize_t PerlIO_read (PerlIO *,void *,Size_t); -#endif -#ifndef PerlIO_write -extern SSize_t PerlIO_write (PerlIO *,const void *,Size_t); -#endif -#ifndef PerlIO_setlinebuf -extern 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))); -#endif -#ifndef PerlIO_vprintf -extern int PerlIO_vprintf (PerlIO *, const char *, va_list); -#endif -#ifndef PerlIO_tell -extern Off_t PerlIO_tell (PerlIO *); -#endif -#ifndef PerlIO_seek -extern int PerlIO_seek (PerlIO *, Off_t, int); -#endif -#ifndef PerlIO_rewind -extern void PerlIO_rewind (PerlIO *); -#endif -#ifndef PerlIO_has_base -extern int PerlIO_has_base (PerlIO *); -#endif -#ifndef PerlIO_has_cntptr -extern int PerlIO_has_cntptr (PerlIO *); -#endif -#ifndef PerlIO_fast_gets -extern int PerlIO_fast_gets (PerlIO *); -#endif -#ifndef PerlIO_canset_cnt -extern int PerlIO_canset_cnt (PerlIO *); -#endif -#ifndef PerlIO_get_ptr -extern STDCHAR * PerlIO_get_ptr (PerlIO *); -#endif -#ifndef PerlIO_get_cnt -extern int PerlIO_get_cnt (PerlIO *); -#endif -#ifndef PerlIO_set_cnt -extern void PerlIO_set_cnt (PerlIO *,int); -#endif -#ifndef PerlIO_set_ptrcnt -extern void PerlIO_set_ptrcnt (PerlIO *,STDCHAR *,int); -#endif -#ifndef PerlIO_get_base -extern STDCHAR * PerlIO_get_base (PerlIO *); -#endif -#ifndef PerlIO_get_bufsiz -extern int PerlIO_get_bufsiz (PerlIO *); -#endif -#ifndef PerlIO_tmpfile -extern PerlIO * PerlIO_tmpfile (void); -#endif -#ifndef PerlIO_stdin -extern PerlIO * PerlIO_stdin (void); -#endif -#ifndef PerlIO_stdout -extern PerlIO * PerlIO_stdout (void); -#endif -#ifndef PerlIO_stderr -extern PerlIO * PerlIO_stderr (void); -#endif -#ifndef PerlIO_getpos -extern int PerlIO_getpos (PerlIO *,Fpos_t *); -#endif -#ifndef PerlIO_setpos -extern int PerlIO_setpos (PerlIO *,const Fpos_t *); -#endif -#ifndef PerlIO_fdupopen -extern PerlIO * PerlIO_fdupopen (PerlIO *); -#endif -#ifndef PerlIO_isutf8 -extern int PerlIO_isutf8 (PerlIO *); -#endif - /* * Interface for directory functions */ diff --git a/nostdio.h b/nostdio.h index 256a638..31befc8 100644 --- a/nostdio.h +++ b/nostdio.h @@ -1,7 +1,11 @@ -/* This is an 1st attempt to stop other include files pulling +/* + * Strong denial of stdio - make all stdio calls (we can think of) errors + */ +/* This is an 1st attempt to stop other include files pulling in real . A more ambitious set of possible symbols can be found in sfio.h (inside an _cplusplus gard). + It is completely pointless as we have already included it ourselves. */ #if !defined(_STDIO_H) && !defined(FILE) && !defined(_STDIO_INCLUDED) && !defined(__STDIO_LOADED) #define _STDIO_H @@ -24,3 +28,81 @@ struct _FILE; #undef ferror #undef fileno +#undef fprintf +#undef tmpfile +#undef fclose +#undef fopen +#undef vfprintf +#undef fgetc +#undef fputc +#undef fputs +#undef ungetc +#undef fread +#undef fwrite +#undef fgetpos +#undef fseek +#undef fsetpos +#undef ftell +#undef rewind +#undef fdopen +#undef popen +#undef pclose +#undef getw +#undef putw +#undef freopen +#undef setbuf +#undef setvbuf +#undef fscanf +#undef fgets +#undef getc_unlocked +#undef putc_unlocked +#define fprintf _CANNOT _fprintf_ +#define stdin _CANNOT _stdin_ +#define stdout _CANNOT _stdout_ +#define stderr _CANNOT _stderr_ +#define tmpfile() _CANNOT _tmpfile_ +#define fclose(f) _CANNOT _fclose_ +#define fflush(f) _CANNOT _fflush_ +#define fopen(p,m) _CANNOT _fopen_ +#define freopen(p,m,f) _CANNOT _freopen_ +#define setbuf(f,b) _CANNOT _setbuf_ +#define setvbuf(f,b,x,s) _CANNOT _setvbuf_ +#define fscanf _CANNOT _fscanf_ +#define vfprintf(f,fmt,a) _CANNOT _vfprintf_ +#define fgetc(f) _CANNOT _fgetc_ +#define fgets(s,n,f) _CANNOT _fgets_ +#define fputc(c,f) _CANNOT _fputc_ +#define fputs(s,f) _CANNOT _fputs_ +#define getc(f) _CANNOT _getc_ +#define putc(c,f) _CANNOT _putc_ +#define ungetc(c,f) _CANNOT _ungetc_ +#define fread(b,s,c,f) _CANNOT _fread_ +#define fwrite(b,s,c,f) _CANNOT _fwrite_ +#define fgetpos(f,p) _CANNOT _fgetpos_ +#define fseek(f,o,w) _CANNOT _fseek_ +#define fsetpos(f,p) _CANNOT _fsetpos_ +#define ftell(f) _CANNOT _ftell_ +#define rewind(f) _CANNOT _rewind_ +#define clearerr(f) _CANNOT _clearerr_ +#define feof(f) _CANNOT _feof_ +#define ferror(f) _CANNOT _ferror_ +#define __filbuf(f) _CANNOT __filbuf_ +#define __flsbuf(c,f) _CANNOT __flsbuf_ +#define _filbuf(f) _CANNOT _filbuf_ +#define _flsbuf(c,f) _CANNOT _flsbuf_ +#define fdopen(fd,p) _CANNOT _fdopen_ +#define fileno(f) _CANNOT _fileno_ +#if SFIO_VERSION < 20000101L +#define flockfile(f) _CANNOT _flockfile_ +#define ftrylockfile(f) _CANNOT _ftrylockfile_ +#define funlockfile(f) _CANNOT _funlockfile_ +#endif +#define getc_unlocked(f) _CANNOT _getc_unlocked_ +#define putc_unlocked(c,f) _CANNOT _putc_unlocked_ +#define popen(c,m) _CANNOT _popen_ +#define getw(f) _CANNOT _getw_ +#define putw(v,f) _CANNOT _putw_ +#define pclose(f) _CANNOT _pclose_ + + + diff --git a/perlio.c b/perlio.c index 8d54f77..7dc895c 100644 --- a/perlio.c +++ b/perlio.c @@ -88,6 +88,8 @@ PerlIO_init(void) /* Implement all the PerlIO interface ourselves. */ +#include "perliol.h" + /* We _MUST_ have if we are using lseek() and may have large files */ #ifdef I_UNISTD #include @@ -98,8 +100,7 @@ PerlIO_init(void) #include "XSUB.h" -#undef printf -void PerlIO_debug(char *fmt,...) __attribute__((format(printf,1,2))); +void PerlIO_debug(char *fmt,...) __attribute__((format(__printf__,1,2))); void PerlIO_debug(char *fmt,...) @@ -136,69 +137,6 @@ PerlIO_debug(char *fmt,...) /*--------------------------------------------------------------------------------------*/ -typedef struct _PerlIO_funcs PerlIO_funcs; -struct _PerlIO_funcs -{ - char * name; - Size_t size; - IV kind; - IV (*Fileno)(PerlIO *f); - PerlIO * (*Fdopen)(PerlIO_funcs *tab, int fd, const char *mode); - PerlIO * (*Open)(PerlIO_funcs *tab, const char *path, const char *mode); - int (*Reopen)(const char *path, const char *mode, PerlIO *f); - IV (*Pushed)(PerlIO *f,const char *mode); - IV (*Popped)(PerlIO *f); - /* Unix-like functions - cf sfio line disciplines */ - SSize_t (*Read)(PerlIO *f, void *vbuf, Size_t count); - SSize_t (*Unread)(PerlIO *f, const void *vbuf, Size_t count); - SSize_t (*Write)(PerlIO *f, const void *vbuf, Size_t count); - IV (*Seek)(PerlIO *f, Off_t offset, int whence); - Off_t (*Tell)(PerlIO *f); - IV (*Close)(PerlIO *f); - /* Stdio-like buffered IO functions */ - IV (*Flush)(PerlIO *f); - IV (*Fill)(PerlIO *f); - IV (*Eof)(PerlIO *f); - IV (*Error)(PerlIO *f); - void (*Clearerr)(PerlIO *f); - void (*Setlinebuf)(PerlIO *f); - /* Perl's snooping functions */ - STDCHAR * (*Get_base)(PerlIO *f); - Size_t (*Get_bufsiz)(PerlIO *f); - STDCHAR * (*Get_ptr)(PerlIO *f); - SSize_t (*Get_cnt)(PerlIO *f); - void (*Set_ptrcnt)(PerlIO *f,STDCHAR *ptr,SSize_t cnt); -}; - -struct _PerlIO -{ - PerlIOl * next; /* Lower layer */ - PerlIO_funcs * tab; /* Functions for this layer */ - IV flags; /* Various flags for state */ -}; - -/*--------------------------------------------------------------------------------------*/ - -/* Flag values */ -#define PERLIO_F_EOF 0x00010000 -#define PERLIO_F_CANWRITE 0x00020000 -#define PERLIO_F_CANREAD 0x00040000 -#define PERLIO_F_ERROR 0x00080000 -#define PERLIO_F_TRUNCATE 0x00100000 -#define PERLIO_F_APPEND 0x00200000 -#define PERLIO_F_BINARY 0x00400000 -#define PERLIO_F_UTF8 0x00800000 -#define PERLIO_F_LINEBUF 0x01000000 -#define PERLIO_F_WRBUF 0x02000000 -#define PERLIO_F_RDBUF 0x04000000 -#define PERLIO_F_TEMP 0x08000000 -#define PERLIO_F_OPEN 0x10000000 - -#define PerlIOBase(f) (*(f)) -#define PerlIOSelf(f,type) ((type *)PerlIOBase(f)) -#define PerlIONext(f) (&(PerlIOBase(f)->next)) - -/*--------------------------------------------------------------------------------------*/ /* Inner level routines */ /* Table of pointers to the PerlIO structs (malloc'ed) */ @@ -293,14 +231,6 @@ PerlIO_fileno(PerlIO *f) return (*PerlIOBase(f)->tab->Fileno)(f); } - -extern PerlIO_funcs PerlIO_unix; -extern PerlIO_funcs PerlIO_perlio; -extern PerlIO_funcs PerlIO_stdio; -#ifdef HAS_MMAP -extern PerlIO_funcs PerlIO_mmap; -#endif - XS(XS_perlio_import) { dXSARGS; @@ -430,6 +360,26 @@ PerlIO_stdstreams() } } +PerlIO * +PerlIO_push(PerlIO *f,PerlIO_funcs *tab,const char *mode) +{ + PerlIOl *l = NULL; + Newc('L',l,tab->size,char,PerlIOl); + if (l) + { + Zero(l,tab->size,char); + l->next = *f; + l->tab = tab; + *f = l; + if ((*l->tab->Pushed)(f,mode) != 0) + { + PerlIO_pop(f); + return NULL; + } + } + return f; +} + #undef PerlIO_fdopen PerlIO * PerlIO_fdopen(int fd, const char *mode) @@ -450,57 +400,6 @@ PerlIO_open(const char *path, const char *mode) return (*tab->Open)(tab,path,mode); } -IV -PerlIOBase_pushed(PerlIO *f, const char *mode) -{ - PerlIOl *l = PerlIOBase(f); - l->flags &= ~(PERLIO_F_CANREAD|PERLIO_F_CANWRITE| - PERLIO_F_TRUNCATE|PERLIO_F_APPEND|PERLIO_F_BINARY); - if (mode) - { - switch (*mode++) - { - case 'r': - l->flags = PERLIO_F_CANREAD; - break; - case 'a': - l->flags = PERLIO_F_APPEND|PERLIO_F_CANWRITE; - break; - case 'w': - l->flags = PERLIO_F_TRUNCATE|PERLIO_F_CANWRITE; - break; - default: - errno = EINVAL; - return -1; - } - while (*mode) - { - switch (*mode++) - { - case '+': - l->flags |= PERLIO_F_CANREAD|PERLIO_F_CANWRITE; - break; - case 'b': - l->flags |= PERLIO_F_BINARY; - break; - default: - errno = EINVAL; - return -1; - } - } - } - else - { - if (l->next) - { - l->flags |= l->next->flags & - (PERLIO_F_CANREAD|PERLIO_F_CANWRITE| - PERLIO_F_TRUNCATE|PERLIO_F_APPEND|PERLIO_F_BINARY); - } - } - return 0; -} - #undef PerlIO_reopen PerlIO * PerlIO_reopen(const char *path, const char *mode, PerlIO *f) @@ -721,24 +620,61 @@ PerlIOBase_fileno(PerlIO *f) return PerlIO_fileno(PerlIONext(f)); } -PerlIO * -PerlIO_push(PerlIO *f,PerlIO_funcs *tab,const char *mode) +IV +PerlIOBase_pushed(PerlIO *f, const char *mode) { - PerlIOl *l = NULL; - Newc('L',l,tab->size,char,PerlIOl); - if (l) + PerlIOl *l = PerlIOBase(f); + l->flags &= ~(PERLIO_F_CANREAD|PERLIO_F_CANWRITE| + PERLIO_F_TRUNCATE|PERLIO_F_APPEND|PERLIO_F_BINARY); + if (mode) { - Zero(l,tab->size,char); - l->next = *f; - l->tab = tab; - *f = l; - if ((*l->tab->Pushed)(f,mode) != 0) + switch (*mode++) { - PerlIO_pop(f); - return NULL; + case 'r': + l->flags = PERLIO_F_CANREAD; + break; + case 'a': + l->flags = PERLIO_F_APPEND|PERLIO_F_CANWRITE; + break; + case 'w': + l->flags = PERLIO_F_TRUNCATE|PERLIO_F_CANWRITE; + break; + default: + errno = EINVAL; + return -1; + } + while (*mode) + { + switch (*mode++) + { + case '+': + l->flags |= PERLIO_F_CANREAD|PERLIO_F_CANWRITE; + break; + case 'b': + l->flags |= PERLIO_F_BINARY; + break; + default: + errno = EINVAL; + return -1; + } } } - return f; + else + { + if (l->next) + { + l->flags |= l->next->flags & + (PERLIO_F_CANREAD|PERLIO_F_CANWRITE| + PERLIO_F_TRUNCATE|PERLIO_F_APPEND|PERLIO_F_BINARY); + } + } + return 0; +} + +IV +PerlIOBase_popped(PerlIO *f) +{ + return 0; } SSize_t @@ -812,8 +748,6 @@ PerlIOBase_setlinebuf(PerlIO *f) } - - /*--------------------------------------------------------------------------------------*/ /* Bottom-most level for UNIX-like case */ @@ -1021,8 +955,8 @@ PerlIO_funcs PerlIO_unix = { PerlIOUnix_seek, PerlIOUnix_tell, PerlIOUnix_close, - PerlIOBase_noop_ok, - PerlIOBase_noop_fail, + PerlIOBase_noop_ok, /* flush */ + PerlIOBase_noop_fail, /* fill */ PerlIOBase_eof, PerlIOBase_error, PerlIOBase_clearerr, @@ -1037,15 +971,6 @@ PerlIO_funcs PerlIO_unix = { /*--------------------------------------------------------------------------------------*/ /* stdio as a layer */ -#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64) -#define fseek fseeko -#endif - -#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64) -#define ftell ftello -#endif - - typedef struct { struct _PerlIO base; @@ -1386,18 +1311,6 @@ PerlIO_releaseFILE(PerlIO *p, FILE *f) /*--------------------------------------------------------------------------------------*/ /* perlio buffer layer */ -typedef struct -{ - struct _PerlIO base; - Off_t posn; /* Offset of buf into the file */ - STDCHAR * buf; /* Start of buffer */ - STDCHAR * end; /* End of valid part of buffer */ - STDCHAR * ptr; /* Current position in buffer */ - Size_t bufsiz; /* Size of buffer */ - IV oneword; /* Emergency buffer */ -} PerlIOBuf; - - PerlIO * PerlIOBuf_fdopen(PerlIO_funcs *self, int fd, const char *mode) { @@ -1422,7 +1335,6 @@ PerlIOBuf_fdopen(PerlIO_funcs *self, int fd, const char *mode) return f; } - PerlIO * PerlIOBuf_open(PerlIO_funcs *self, const char *path, const char *mode) { @@ -1700,17 +1612,6 @@ PerlIOBuf_setlinebuf(PerlIO *f) } } -void -PerlIOBuf_set_cnt(PerlIO *f, int cnt) -{ - PerlIOBuf *b = PerlIOSelf(f,PerlIOBuf); - dTHX; - if (!b->buf) - PerlIO_get_base(f); - b->ptr = b->end - cnt; - assert(b->ptr >= b->buf); -} - STDCHAR * PerlIOBuf_get_ptr(PerlIO *f) { @@ -2111,8 +2012,6 @@ PerlIO_funcs PerlIO_mmap = { #endif /* HAS_MMAP */ - - void PerlIO_init(void) { diff --git a/perlio.h b/perlio.h index e699a3e..d8ea15a 100644 --- a/perlio.h +++ b/perlio.h @@ -1 +1,308 @@ -#include "iperlsys.h" +#ifndef _PERLIO_H +#define _PERLIO_H +/* + Interface for perl to IO functions. + There is a hierachy of Configure determined #define controls: + USE_STDIO - forces PerlIO_xxx() to be #define-d onto stdio functions. + This is used for x2p subdirectory and for conservative + builds - "just like perl5.00X used to be". + This dominates over the others. + + USE_PERLIO - The primary Configure variable that enables PerlIO. + If USE_PERLIO is _NOT_ set + then USE_STDIO above will be set to be conservative. + If USE_PERLIO is set + then there are two modes determined by USE_SFIO: + + USE_SFIO - If set causes PerlIO_xxx() to be #define-d onto sfio functions. + A backward compatability mode for some specialist applications. + + If USE_SFIO is not set then PerlIO_xxx() are real functions + defined in perlio.c which implement extra functionality + required for utf8 support. + + One further note - the table-of-functions scheme controlled + by PERL_IMPLICIT_SYS turns on USE_PERLIO so that iperlsys.h can + #define PerlIO_xxx() to go via the function table, without having + to #undef them from (say) stdio forms. + +*/ + +#if defined(PERL_IMPLICIT_SYS) +#ifndef USE_PERLIO +# define USE_PERLIO +#endif +#endif + +#ifndef USE_PERLIO +# define USE_STDIO +#endif + +#ifdef USE_STDIO +# ifndef PERLIO_IS_STDIO +# define PERLIO_IS_STDIO +# endif +#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 + +#ifdef PERLIO_IS_STDIO +/* #define PerlIO_xxxx() as equivalent stdio function */ +#include "perlsdio.h" +#else /* PERLIO_IS_STDIO */ +#ifdef USE_SFIO +/* #define PerlIO_xxxx() as equivalent sfio function */ +#include "perlsfio.h" +#endif /* USE_SFIO */ +#endif /* PERLIO_IS_STDIO */ + +#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 + +extern void PerlIO_define_layer (PerlIO_funcs *tab); +extern PerlIO * PerlIO_push (PerlIO *f,PerlIO_funcs *tab,const char *mode); +extern void PerlIO_pop (PerlIO *f); + +#endif /* PerlIO */ + +/* ----------- End of implementation choices ---------- */ + +#ifndef PERLIO_IS_STDIO +/* Not using stdio _directly_ as PerlIO */ + +/* 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 +#endif + +#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 */ +#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) +#endif + +/* This is to catch case with no stdio */ +#ifndef BUFSIZ +#define BUFSIZ 1024 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#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) +#endif +#endif + +#ifndef PerlIO_init +extern void PerlIO_init (void); +#endif +#ifndef PerlIO_stdoutf +extern int PerlIO_stdoutf (const char *,...) + __attribute__((__format__ (__printf__, 1, 2))); +#endif +#ifndef PerlIO_puts +extern int PerlIO_puts (PerlIO *,const char *); +#endif +#ifndef PerlIO_open +extern PerlIO * PerlIO_open (const char *,const char *); +#endif +#ifndef PerlIO_close +extern int PerlIO_close (PerlIO *); +#endif +#ifndef PerlIO_eof +extern int PerlIO_eof (PerlIO *); +#endif +#ifndef PerlIO_error +extern int PerlIO_error (PerlIO *); +#endif +#ifndef PerlIO_clearerr +extern void PerlIO_clearerr (PerlIO *); +#endif +#ifndef PerlIO_getc +extern int PerlIO_getc (PerlIO *); +#endif +#ifndef PerlIO_putc +extern int PerlIO_putc (PerlIO *,int); +#endif +#ifndef PerlIO_flush +extern int PerlIO_flush (PerlIO *); +#endif +#ifndef PerlIO_ungetc +extern int PerlIO_ungetc (PerlIO *,int); +#endif +#ifndef PerlIO_fileno +extern int PerlIO_fileno (PerlIO *); +#endif +#ifndef PerlIO_fdopen +extern PerlIO * PerlIO_fdopen (int, const char *); +#endif +#ifndef PerlIO_importFILE +extern PerlIO * PerlIO_importFILE (FILE *,int); +#endif +#ifndef PerlIO_exportFILE +extern FILE * PerlIO_exportFILE (PerlIO *,int); +#endif +#ifndef PerlIO_findFILE +extern FILE * PerlIO_findFILE (PerlIO *); +#endif +#ifndef PerlIO_releaseFILE +extern void PerlIO_releaseFILE (PerlIO *,FILE *); +#endif +#ifndef PerlIO_read +extern SSize_t PerlIO_read (PerlIO *,void *,Size_t); +#endif +#ifndef PerlIO_write +extern SSize_t PerlIO_write (PerlIO *,const void *,Size_t); +#endif +#ifndef PerlIO_setlinebuf +extern 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))); +#endif +#ifndef PerlIO_vprintf +extern int PerlIO_vprintf (PerlIO *, const char *, va_list); +#endif +#ifndef PerlIO_tell +extern Off_t PerlIO_tell (PerlIO *); +#endif +#ifndef PerlIO_seek +extern int PerlIO_seek (PerlIO *, Off_t, int); +#endif +#ifndef PerlIO_rewind +extern void PerlIO_rewind (PerlIO *); +#endif +#ifndef PerlIO_has_base +extern int PerlIO_has_base (PerlIO *); +#endif +#ifndef PerlIO_has_cntptr +extern int PerlIO_has_cntptr (PerlIO *); +#endif +#ifndef PerlIO_fast_gets +extern int PerlIO_fast_gets (PerlIO *); +#endif +#ifndef PerlIO_canset_cnt +extern int PerlIO_canset_cnt (PerlIO *); +#endif +#ifndef PerlIO_get_ptr +extern STDCHAR * PerlIO_get_ptr (PerlIO *); +#endif +#ifndef PerlIO_get_cnt +extern int PerlIO_get_cnt (PerlIO *); +#endif +#ifndef PerlIO_set_cnt +extern void PerlIO_set_cnt (PerlIO *,int); +#endif +#ifndef PerlIO_set_ptrcnt +extern void PerlIO_set_ptrcnt (PerlIO *,STDCHAR *,int); +#endif +#ifndef PerlIO_get_base +extern STDCHAR * PerlIO_get_base (PerlIO *); +#endif +#ifndef PerlIO_get_bufsiz +extern int PerlIO_get_bufsiz (PerlIO *); +#endif +#ifndef PerlIO_tmpfile +extern PerlIO * PerlIO_tmpfile (void); +#endif +#ifndef PerlIO_stdin +extern PerlIO * PerlIO_stdin (void); +#endif +#ifndef PerlIO_stdout +extern PerlIO * PerlIO_stdout (void); +#endif +#ifndef PerlIO_stderr +extern PerlIO * PerlIO_stderr (void); +#endif +#ifndef PerlIO_getpos +extern int PerlIO_getpos (PerlIO *,Fpos_t *); +#endif +#ifndef PerlIO_setpos +extern int PerlIO_setpos (PerlIO *,const Fpos_t *); +#endif +#ifndef PerlIO_fdupopen +extern PerlIO * PerlIO_fdupopen (PerlIO *); +#endif +#ifndef PerlIO_isutf8 +extern int PerlIO_isutf8 (PerlIO *); +#endif + +#endif /* _PERLIO_H */ diff --git a/perliol.h b/perliol.h new file mode 100644 index 0000000..58fad63 --- /dev/null +++ b/perliol.h @@ -0,0 +1,131 @@ +#ifndef _PERLIOL_H +#define _PERLIOL_H + +struct _PerlIO_funcs +{ + char * name; + Size_t size; + IV kind; + IV (*Fileno)(PerlIO *f); + PerlIO * (*Fdopen)(PerlIO_funcs *tab, int fd, const char *mode); + PerlIO * (*Open)(PerlIO_funcs *tab, const char *path, const char *mode); + int (*Reopen)(const char *path, const char *mode, PerlIO *f); + IV (*Pushed)(PerlIO *f,const char *mode); + IV (*Popped)(PerlIO *f); + /* Unix-like functions - cf sfio line disciplines */ + SSize_t (*Read)(PerlIO *f, void *vbuf, Size_t count); + SSize_t (*Unread)(PerlIO *f, const void *vbuf, Size_t count); + SSize_t (*Write)(PerlIO *f, const void *vbuf, Size_t count); + IV (*Seek)(PerlIO *f, Off_t offset, int whence); + Off_t (*Tell)(PerlIO *f); + IV (*Close)(PerlIO *f); + /* Stdio-like buffered IO functions */ + IV (*Flush)(PerlIO *f); + IV (*Fill)(PerlIO *f); + IV (*Eof)(PerlIO *f); + IV (*Error)(PerlIO *f); + void (*Clearerr)(PerlIO *f); + void (*Setlinebuf)(PerlIO *f); + /* Perl's snooping functions */ + STDCHAR * (*Get_base)(PerlIO *f); + Size_t (*Get_bufsiz)(PerlIO *f); + STDCHAR * (*Get_ptr)(PerlIO *f); + SSize_t (*Get_cnt)(PerlIO *f); + void (*Set_ptrcnt)(PerlIO *f,STDCHAR *ptr,SSize_t cnt); +}; + +struct _PerlIO +{ + PerlIOl * next; /* Lower layer */ + PerlIO_funcs * tab; /* Functions for this layer */ + IV flags; /* Various flags for state */ +}; + +/*--------------------------------------------------------------------------------------*/ + +/* Flag values */ +#define PERLIO_F_EOF 0x00010000 +#define PERLIO_F_CANWRITE 0x00020000 +#define PERLIO_F_CANREAD 0x00040000 +#define PERLIO_F_ERROR 0x00080000 +#define PERLIO_F_TRUNCATE 0x00100000 +#define PERLIO_F_APPEND 0x00200000 +#define PERLIO_F_BINARY 0x00400000 +#define PERLIO_F_UTF8 0x00800000 +#define PERLIO_F_LINEBUF 0x01000000 +#define PERLIO_F_WRBUF 0x02000000 +#define PERLIO_F_RDBUF 0x04000000 +#define PERLIO_F_TEMP 0x08000000 +#define PERLIO_F_OPEN 0x10000000 + +#define PerlIOBase(f) (*(f)) +#define PerlIOSelf(f,type) ((type *)PerlIOBase(f)) +#define PerlIONext(f) (&(PerlIOBase(f)->next)) + +/*--------------------------------------------------------------------------------------*/ + +extern PerlIO_funcs PerlIO_unix; +extern PerlIO_funcs PerlIO_perlio; +extern PerlIO_funcs PerlIO_stdio; +#ifdef HAS_MMAP +extern PerlIO_funcs PerlIO_mmap; +#endif + +extern PerlIO *PerlIO_allocate(void); + +/*--------------------------------------------------------------------------------------*/ +/* Generic, or stub layer functions */ + +extern IV PerlIOBase_fileno (PerlIO *f); +extern IV PerlIOBase_pushed (PerlIO *f, const char *mode); +extern IV PerlIOBase_popped (PerlIO *f); +extern SSize_t PerlIOBase_unread (PerlIO *f, const void *vbuf, Size_t count); +extern IV PerlIOBase_eof (PerlIO *f); +extern IV PerlIOBase_error (PerlIO *f); +extern void PerlIOBase_clearerr (PerlIO *f); +extern IV PerlIOBase_flush (PerlIO *f); +extern IV PerlIOBase_fill (PerlIO *f); +extern IV PerlIOBase_close (PerlIO *f); +extern void PerlIOBase_setlinebuf(PerlIO *f); + +extern IV PerlIOBase_noop_ok (PerlIO *f); +extern IV PerlIOBase_noop_fail (PerlIO *f); + +/*--------------------------------------------------------------------------------------*/ +/* perlio buffer layer + As this is reasonably generic its struct and "methods" are declared here + so they can be used to "inherit" from it. +*/ + +typedef struct +{ + struct _PerlIO base; /* Base "class" info */ + STDCHAR * buf; /* Start of buffer */ + STDCHAR * end; /* End of valid part of buffer */ + STDCHAR * ptr; /* Current position in buffer */ + Off_t posn; /* Offset of buf into the file */ + Size_t bufsiz; /* Real size of buffer */ + IV oneword; /* Emergency buffer */ +} PerlIOBuf; + +extern PerlIO * PerlIOBuf_fdopen (PerlIO_funcs *self, int fd, const char *mode); +extern PerlIO * PerlIOBuf_open (PerlIO_funcs *self, const char *path, const char *mode); +extern int PerlIOBuf_reopen (const char *path, const char *mode, PerlIO *f); +extern SSize_t PerlIOBuf_read (PerlIO *f, void *vbuf, Size_t count); +extern SSize_t PerlIOBuf_unread (PerlIO *f, const void *vbuf, Size_t count); +extern SSize_t PerlIOBuf_write (PerlIO *f, const void *vbuf, Size_t count); +extern IV PerlIOBuf_seek (PerlIO *f, Off_t offset, int whence); +extern Off_t PerlIOBuf_tell (PerlIO *f); +extern IV PerlIOBuf_close (PerlIO *f); +extern IV PerlIOBuf_flush (PerlIO *f); +extern IV PerlIOBuf_fill (PerlIO *f); +extern void PerlIOBuf_setlinebuf (PerlIO *f); +extern STDCHAR *PerlIOBuf_get_base (PerlIO *f); +extern Size_t PerlIOBuf_bufsiz (PerlIO *f); +extern STDCHAR *PerlIOBuf_get_ptr (PerlIO *f); +extern SSize_t PerlIOBuf_get_cnt (PerlIO *f); +extern void PerlIOBuf_set_ptrcnt (PerlIO *f, STDCHAR *ptr, SSize_t cnt); + +/*--------------------------------------------------------------------------------------*/ + +#endif /* _PERLIOL_H */ diff --git a/perlsdio.h b/perlsdio.h index 6ce82d8..4b86634 100644 --- a/perlsdio.h +++ b/perlsdio.h @@ -1,25 +1,23 @@ -/* - * Although we may not want stdio to be used including here - * avoids issues where stdio.h has strange side effects - */ -#include - #ifdef PERLIO_IS_STDIO /* + * This file #define-s the PerlIO_xxx abstraction onto stdio functions. * Make this as close to original stdio as possible. */ -#define PerlIO FILE +#define PerlIO FILE #define PerlIO_stderr() stderr #define PerlIO_stdout() stdout #define PerlIO_stdin() stdin +#define PerlIO_fdupopen(f) (f) +#define PerlIO_isutf8(f) 0 + #define PerlIO_printf fprintf #define PerlIO_stdoutf printf -#define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a) +#define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a) #define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f) #define PerlIO_open fopen #define PerlIO_fdopen fdopen -#define PerlIO_reopen freopen +#define PerlIO_reopen freopen #define PerlIO_close(f) fclose(f) #define PerlIO_puts(f,s) fputs(s,f) #define PerlIO_putc(f,c) fputc(c,f) @@ -55,18 +53,12 @@ #define PerlIO_clearerr(f) clearerr(f) #define PerlIO_flush(f) Fflush(f) #define PerlIO_tell(f) ftell(f) -#if defined(USE_64_BIT_STDIO) && defined(HAS_FTELLO) && !defined(USE_FTELL64) -#define ftell ftello -#endif #if defined(VMS) && !defined(__DECC) /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */ # define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w)) #else # define PerlIO_seek(f,o,w) fseek(f,o,w) #endif -#if defined(USE_64_BIT_STDIO) && defined(HAS_FSEEKO) && !defined(USE_FSEEK64) -#define fseek fseeko -#endif #ifdef HAS_FGETPOS #define PerlIO_getpos(f,p) fgetpos(f,p) #endif @@ -77,10 +69,10 @@ #define PerlIO_rewind(f) rewind(f) #define PerlIO_tmpfile() tmpfile() -#define PerlIO_importFILE(f,fl) (f) -#define PerlIO_exportFILE(f,fl) (f) -#define PerlIO_findFILE(f) (f) -#define PerlIO_releaseFILE(p,f) ((void) 0) +#define PerlIO_importFILE(f,fl) (f) +#define PerlIO_exportFILE(f,fl) (f) +#define PerlIO_findFILE(f) (f) +#define PerlIO_releaseFILE(p,f) ((void) 0) #ifdef HAS_SETLINEBUF #define PerlIO_setlinebuf(f) setlinebuf(f); @@ -91,20 +83,20 @@ /* Now our interface to Configure's FILE_xxx macros */ #ifdef USE_STDIO_PTR -#define PerlIO_has_cntptr(f) 1 -#define PerlIO_get_ptr(f) FILE_ptr(f) -#define PerlIO_get_cnt(f) FILE_cnt(f) +#define PerlIO_has_cntptr(f) 1 +#define PerlIO_get_ptr(f) FILE_ptr(f) +#define PerlIO_get_cnt(f) FILE_cnt(f) #ifdef STDIO_CNT_LVALUE -#define PerlIO_canset_cnt(f) 1 -#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c)) +#define PerlIO_canset_cnt(f) 1 +#define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c)) #ifdef STDIO_PTR_LVALUE #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT -#define PerlIO_fast_gets(f) 1 +#define PerlIO_fast_gets(f) 1 #endif #endif /* STDIO_PTR_LVALUE */ #else /* STDIO_CNT_LVALUE */ -#define PerlIO_canset_cnt(f) 0 +#define PerlIO_canset_cnt(f) 0 #define PerlIO_set_cnt(f,c) abort() #endif @@ -115,7 +107,7 @@ #ifdef STDIO_PTR_LVAL_SETS_CNT /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */ #define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END -#define PerlIO_fast_gets(f) 1 +#define PerlIO_fast_gets(f) 1 #else #define PerlIO_set_ptrcnt(f,p,c) abort() #endif @@ -134,209 +126,18 @@ #endif /* USE_STDIO_PTR */ #ifndef PerlIO_fast_gets -#define PerlIO_fast_gets(f) 0 +#define PerlIO_fast_gets(f) 0 #endif #ifdef FILE_base -#define PerlIO_has_base(f) 1 -#define PerlIO_get_base(f) FILE_base(f) -#define PerlIO_get_bufsiz(f) FILE_bufsiz(f) +#define PerlIO_has_base(f) 1 +#define PerlIO_get_base(f) FILE_base(f) +#define PerlIO_get_bufsiz(f) FILE_bufsiz(f) #else #define PerlIO_has_base(f) 0 #define PerlIO_get_base(f) (abort(),(void *)0) #define PerlIO_get_bufsiz(f) (abort(),0) #endif -#else /* PERLIO_IS_STDIO */ -#ifdef PERL_CORE -#ifndef PERLIO_NOT_STDIO -#define PERLIO_NOT_STDIO 1 -#endif -#endif -#ifdef PERLIO_NOT_STDIO -#if PERLIO_NOT_STDIO -/* - * Strong denial of stdio - make all stdio calls (we can think of) errors - */ -#include "nostdio.h" -#undef fprintf -#undef tmpfile -#undef fclose -#undef fopen -#undef vfprintf -#undef fgetc -#undef fputc -#undef fputs -#undef ungetc -#undef fread -#undef fwrite -#undef fgetpos -#undef fseek -#undef fsetpos -#undef ftell -#undef rewind -#undef fdopen -#undef popen -#undef pclose -#undef getw -#undef putw -#undef freopen -#undef setbuf -#undef setvbuf -#undef fscanf -#undef fgets -#undef getc_unlocked -#undef putc_unlocked -#define fprintf _CANNOT _fprintf_ -#define stdin _CANNOT _stdin_ -#define stdout _CANNOT _stdout_ -#define stderr _CANNOT _stderr_ -#define tmpfile() _CANNOT _tmpfile_ -#define fclose(f) _CANNOT _fclose_ -#define fflush(f) _CANNOT _fflush_ -#define fopen(p,m) _CANNOT _fopen_ -#define freopen(p,m,f) _CANNOT _freopen_ -#define setbuf(f,b) _CANNOT _setbuf_ -#define setvbuf(f,b,x,s) _CANNOT _setvbuf_ -#define fscanf _CANNOT _fscanf_ -#define vfprintf(f,fmt,a) _CANNOT _vfprintf_ -#define fgetc(f) _CANNOT _fgetc_ -#define fgets(s,n,f) _CANNOT _fgets_ -#define fputc(c,f) _CANNOT _fputc_ -#define fputs(s,f) _CANNOT _fputs_ -#define getc(f) _CANNOT _getc_ -#define putc(c,f) _CANNOT _putc_ -#define ungetc(c,f) _CANNOT _ungetc_ -#define fread(b,s,c,f) _CANNOT _fread_ -#define fwrite(b,s,c,f) _CANNOT _fwrite_ -#define fgetpos(f,p) _CANNOT _fgetpos_ -#define fseek(f,o,w) _CANNOT _fseek_ -#define fsetpos(f,p) _CANNOT _fsetpos_ -#define ftell(f) _CANNOT _ftell_ -#define rewind(f) _CANNOT _rewind_ -#define clearerr(f) _CANNOT _clearerr_ -#define feof(f) _CANNOT _feof_ -#define ferror(f) _CANNOT _ferror_ -#define __filbuf(f) _CANNOT __filbuf_ -#define __flsbuf(c,f) _CANNOT __flsbuf_ -#define _filbuf(f) _CANNOT _filbuf_ -#define _flsbuf(c,f) _CANNOT _flsbuf_ -#define fdopen(fd,p) _CANNOT _fdopen_ -#define fileno(f) _CANNOT _fileno_ -#if SFIO_VERSION < 20000101L -#define flockfile(f) _CANNOT _flockfile_ -#define ftrylockfile(f) _CANNOT _ftrylockfile_ -#define funlockfile(f) _CANNOT _funlockfile_ -#endif -#define getc_unlocked(f) _CANNOT _getc_unlocked_ -#define putc_unlocked(c,f) _CANNOT _putc_unlocked_ -#define popen(c,m) _CANNOT _popen_ -#define getw(f) _CANNOT _getw_ -#define putw(v,f) _CANNOT _putw_ -#define pclose(f) _CANNOT _pclose_ - -#else /* if PERLIO_NOT_STDIO */ -/* - * PERLIO_NOT_STDIO defined as 0 - * Declares that both PerlIO and stdio can be used - */ -#endif /* if PERLIO_NOT_STDIO */ -#else /* ifdef PERLIO_NOT_STDIO */ -/* - * PERLIO_NOT_STDIO not defined - * This is "source level" stdio compatibility mode. - */ -#include "nostdio.h" -#undef FILE -#define FILE PerlIO -#undef fprintf -#undef tmpfile -#undef fclose -#undef fopen -#undef vfprintf -#undef fgetc -#undef getc_unlocked -#undef fputc -#undef putc_unlocked -#undef fputs -#undef ungetc -#undef fread -#undef fwrite -#undef fgetpos -#undef fseek -#undef fsetpos -#undef ftell -#undef rewind -#undef fdopen -#undef popen -#undef pclose -#undef getw -#undef putw -#undef freopen -#undef setbuf -#undef setvbuf -#undef fscanf -#undef fgets -#define fprintf PerlIO_printf -#define stdin PerlIO_stdin() -#define stdout PerlIO_stdout() -#define stderr PerlIO_stderr() -#define tmpfile() PerlIO_tmpfile() -#define fclose(f) PerlIO_close(f) -#define fflush(f) PerlIO_flush(f) -#define fopen(p,m) PerlIO_open(p,m) -#define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a) -#define fgetc(f) PerlIO_getc(f) -#define fputc(c,f) PerlIO_putc(f,c) -#define fputs(s,f) PerlIO_puts(f,s) -#define getc(f) PerlIO_getc(f) -#ifdef getc_unlocked -#undef getc_unlocked -#endif -#define getc_unlocked(f) PerlIO_getc(f) -#define putc(c,f) PerlIO_putc(f,c) -#ifdef putc_unlocked -#undef putc_unlocked -#endif -#define putc_unlocked(c,f) PerlIO_putc(c,f) -#define ungetc(c,f) PerlIO_ungetc(f,c) -#if 0 -/* return values of read/write need work */ -#define fread(b,s,c,f) PerlIO_read(f,b,(s*c)) -#define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c)) -#else -#define fread(b,s,c,f) _CANNOT fread -#define fwrite(b,s,c,f) _CANNOT fwrite -#endif -#define fgetpos(f,p) PerlIO_getpos(f,p) -#define fseek(f,o,w) PerlIO_seek(f,o,w) -#define fsetpos(f,p) PerlIO_setpos(f,p) -#define ftell(f) PerlIO_tell(f) -#define rewind(f) PerlIO_rewind(f) -#define clearerr(f) PerlIO_clearerr(f) -#define feof(f) PerlIO_eof(f) -#define ferror(f) PerlIO_error(f) -#define fdopen(fd,p) PerlIO_fdopen(fd,p) -#define fileno(f) PerlIO_fileno(f) -#define popen(c,m) my_popen(c,m) -#define pclose(f) my_pclose(f) - -#define __filbuf(f) _CANNOT __filbuf_ -#define _filbuf(f) _CANNOT _filbuf_ -#define __flsbuf(c,f) _CANNOT __flsbuf_ -#define _flsbuf(c,f) _CANNOT _flsbuf_ -#define getw(f) _CANNOT _getw_ -#define putw(v,f) _CANNOT _putw_ -#if SFIO_VERSION < 20000101L -#define flockfile(f) _CANNOT _flockfile_ -#define ftrylockfile(f) _CANNOT _ftrylockfile_ -#define funlockfile(f) _CANNOT _funlockfile_ -#endif -#define freopen(p,m,f) _CANNOT _freopen_ -#define setbuf(f,b) _CANNOT _setbuf_ -#define setvbuf(f,b,x,s) _CANNOT _setvbuf_ -#define fscanf _CANNOT _fscanf_ -#define fgets(s,n,f) _CANNOT _fgets_ -#endif /* ifdef PERLIO_NOT_STDIO */ #endif /* PERLIO_IS_STDIO */ diff --git a/perlsfio.h b/perlsfio.h index 22f5427..de7e9ac 100644 --- a/perlsfio.h +++ b/perlsfio.h @@ -5,7 +5,7 @@ /* sfio 2000 changed _stdopen to _stdfdopen */ #if SFIO_VERSION >= 20000101L -#define _stdopen _stdfdopen +#define _stdopen _stdfdopen #endif extern Sfio_t* _stdopen _ARG_((int, const char*)); @@ -16,9 +16,11 @@ extern int _stdprintf _ARG_((const char*, ...)); #define PerlIO_stdout() sfstdout #define PerlIO_stdin() sfstdin +#define PerlIO_isutf8(f) 0 + #define PerlIO_printf sfprintf #define PerlIO_stdoutf _stdprintf -#define PerlIO_vprintf(f,fmt,a) sfvprintf(f,fmt,a) +#define PerlIO_vprintf(f,fmt,a) sfvprintf(f,fmt,a) #define PerlIO_read(f,buf,count) sfread(f,buf,count) #define PerlIO_write(f,buf,count) sfwrite(f,buf,count) #define PerlIO_open(path,mode) sfopen(NULL,path,mode) @@ -35,7 +37,12 @@ extern int _stdprintf _ARG_((const char*, ...)); #define PerlIO_fileno(f) sffileno(f) #define PerlIO_clearerr(f) sfclrerr(f) #define PerlIO_flush(f) sfsync(f) -#define PerlIO_tell(f) sfseek(f,0,1|SF_SHARE) +#if 0 +/* This breaks tests */ +#define PerlIO_tell(f) sfseek(f,0,1|SF_SHARE) +#else +#define PerlIO_tell(f) sftell(f) +#endif #define PerlIO_seek(f,o,w) sfseek(f,o,w) #define PerlIO_rewind(f) (void) sfseek((f),0L,0) #define PerlIO_tmpfile() sftmp(0) @@ -49,15 +56,15 @@ extern int _stdprintf _ARG_((const char*, ...)); /* Now our interface to equivalent of Configure's FILE_xxx macros */ -#define PerlIO_has_cntptr(f) 1 +#define PerlIO_has_cntptr(f) 1 #define PerlIO_get_ptr(f) ((f)->next) #define PerlIO_get_cnt(f) ((f)->endr - (f)->next) -#define PerlIO_canset_cnt(f) 0 +#define PerlIO_canset_cnt(f) 1 #define PerlIO_fast_gets(f) 1 -#define PerlIO_set_ptrcnt(f,p,c) STMT_START {(f)->next = (unsigned char *)(p); assert(FILE_cnt(f) == (c))} STMT_END -#define PerlIO_set_cnt(f,c) Perl_croak(aTHX_ "Cannot set 'cnt' of FILE * on this system"); +#define PerlIO_set_ptrcnt(f,p,c) STMT_START {(f)->next = (unsigned char *)(p); assert(PerlIO_get_cnt(f) == (c));} STMT_END +#define PerlIO_set_cnt(f,c) STMT_START {(f)->next = (f)->endr - (c);} STMT_END -#define PerlIO_has_base(f) 1 +#define PerlIO_has_base(f) 1 #define PerlIO_get_base(f) ((f)->data) #define PerlIO_get_bufsiz(f) ((f)->endr - (f)->data)