| 1 | #ifdef PERLIO_IS_STDIO |
| 2 | /* |
| 3 | * This file #define-s the PerlIO_xxx abstraction onto stdio functions. |
| 4 | * Make this as close to original stdio as possible. |
| 5 | */ |
| 6 | #define PerlIO FILE |
| 7 | #define PerlIO_stderr() stderr |
| 8 | #define PerlIO_stdout() stdout |
| 9 | #define PerlIO_stdin() stdin |
| 10 | |
| 11 | #define PerlIO_fdupopen(f) (f) |
| 12 | #define PerlIO_isutf8(f) 0 |
| 13 | |
| 14 | #define PerlIO_printf fprintf |
| 15 | #define PerlIO_stdoutf printf |
| 16 | #define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a) |
| 17 | #define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f) |
| 18 | #define PerlIO_open fopen |
| 19 | #define PerlIO_fdopen fdopen |
| 20 | #define PerlIO_reopen freopen |
| 21 | #define PerlIO_close(f) fclose(f) |
| 22 | #define PerlIO_puts(f,s) fputs(s,f) |
| 23 | #define PerlIO_putc(f,c) fputc(c,f) |
| 24 | #if defined(VMS) |
| 25 | # if defined(__DECC) |
| 26 | /* Unusual definition of ungetc() here to accomodate fast_sv_gets()' |
| 27 | * belief that it can mix getc/ungetc with reads from stdio buffer */ |
| 28 | int decc$ungetc(int __c, FILE *__stream); |
| 29 | # define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \ |
| 30 | ((*(f) && !((*(f))->_flag & _IONBF) && \ |
| 31 | ((*(f))->_ptr > (*(f))->_base)) ? \ |
| 32 | ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f))) |
| 33 | # else |
| 34 | # define PerlIO_ungetc(f,c) ungetc(c,f) |
| 35 | # endif |
| 36 | /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old |
| 37 | * VAXCRTL which causes read from a pipe after EOF has been returned |
| 38 | * once to hang. |
| 39 | */ |
| 40 | # define PerlIO_getc(f) \ |
| 41 | (feof(f) ? EOF : getc(f)) |
| 42 | # define PerlIO_read(f,buf,count) \ |
| 43 | (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f)) |
| 44 | # define PerlIO_tell(f) ftell(f) |
| 45 | #else |
| 46 | # define PerlIO_getc(f) getc(f) |
| 47 | # define PerlIO_ungetc(f,c) ungetc(c,f) |
| 48 | # define PerlIO_read(f,buf,count) (SSize_t)fread(buf,1,count,f) |
| 49 | # define PerlIO_tell(f) ftell(f) |
| 50 | #endif |
| 51 | #define PerlIO_eof(f) feof(f) |
| 52 | #define PerlIO_getname(f,b) fgetname(f,b) |
| 53 | #define PerlIO_error(f) ferror(f) |
| 54 | #define PerlIO_fileno(f) fileno(f) |
| 55 | #define PerlIO_clearerr(f) clearerr(f) |
| 56 | #define PerlIO_flush(f) Fflush(f) |
| 57 | #if defined(VMS) && !defined(__DECC) |
| 58 | /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */ |
| 59 | #define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w)) |
| 60 | #else |
| 61 | # define PerlIO_seek(f,o,w) fseek(f,o,w) |
| 62 | #endif |
| 63 | |
| 64 | #define PerlIO_rewind(f) rewind(f) |
| 65 | #define PerlIO_tmpfile() tmpfile() |
| 66 | |
| 67 | #define PerlIO_importFILE(f,fl) (f) |
| 68 | #define PerlIO_exportFILE(f,fl) (f) |
| 69 | #define PerlIO_findFILE(f) (f) |
| 70 | #define PerlIO_releaseFILE(p,f) ((void) 0) |
| 71 | |
| 72 | #ifdef HAS_SETLINEBUF |
| 73 | #define PerlIO_setlinebuf(f) setlinebuf(f); |
| 74 | #else |
| 75 | #define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0); |
| 76 | #endif |
| 77 | |
| 78 | /* Now our interface to Configure's FILE_xxx macros */ |
| 79 | |
| 80 | #ifdef USE_STDIO_PTR |
| 81 | #define PerlIO_has_cntptr(f) 1 |
| 82 | #define PerlIO_get_ptr(f) FILE_ptr(f) |
| 83 | #define PerlIO_get_cnt(f) FILE_cnt(f) |
| 84 | |
| 85 | #ifdef STDIO_CNT_LVALUE |
| 86 | #define PerlIO_canset_cnt(f) 1 |
| 87 | #define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c)) |
| 88 | #ifdef STDIO_PTR_LVALUE |
| 89 | #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT |
| 90 | #define PerlIO_fast_gets(f) 1 |
| 91 | #endif |
| 92 | #endif /* STDIO_PTR_LVALUE */ |
| 93 | #else /* STDIO_CNT_LVALUE */ |
| 94 | #define PerlIO_canset_cnt(f) 0 |
| 95 | #define PerlIO_set_cnt(f,c) abort() |
| 96 | #endif |
| 97 | |
| 98 | #ifdef STDIO_PTR_LVALUE |
| 99 | #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT |
| 100 | #define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p), PerlIO_set_cnt(f,c);} STMT_END |
| 101 | #else |
| 102 | #ifdef STDIO_PTR_LVAL_SETS_CNT |
| 103 | /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */ |
| 104 | #define PerlIO_set_ptrcnt(f,p,c) STMT_START {FILE_ptr(f) = (p); assert(FILE_cnt(f) == (c));} STMT_END |
| 105 | #define PerlIO_fast_gets(f) 1 |
| 106 | #else |
| 107 | #define PerlIO_set_ptrcnt(f,p,c) abort() |
| 108 | #endif |
| 109 | #endif |
| 110 | #endif |
| 111 | |
| 112 | #else /* USE_STDIO_PTR */ |
| 113 | |
| 114 | #define PerlIO_has_cntptr(f) 0 |
| 115 | #define PerlIO_canset_cnt(f) 0 |
| 116 | #define PerlIO_get_cnt(f) (abort(),0) |
| 117 | #define PerlIO_get_ptr(f) (abort(),(void *)0) |
| 118 | #define PerlIO_set_cnt(f,c) abort() |
| 119 | #define PerlIO_set_ptrcnt(f,p,c) abort() |
| 120 | |
| 121 | #endif /* USE_STDIO_PTR */ |
| 122 | |
| 123 | #ifndef PerlIO_fast_gets |
| 124 | #define PerlIO_fast_gets(f) 0 |
| 125 | #endif |
| 126 | |
| 127 | |
| 128 | #ifdef FILE_base |
| 129 | #define PerlIO_has_base(f) 1 |
| 130 | #define PerlIO_get_base(f) FILE_base(f) |
| 131 | #define PerlIO_get_bufsiz(f) FILE_bufsiz(f) |
| 132 | #else |
| 133 | #define PerlIO_has_base(f) 0 |
| 134 | #define PerlIO_get_base(f) (abort(),(void *)0) |
| 135 | #define PerlIO_get_bufsiz(f) (abort(),0) |
| 136 | #endif |
| 137 | |
| 138 | #endif /* PERLIO_IS_STDIO */ |