[10723] | 1 | /* |
---|
| 2 | * Although we may not want stdio to be used including <stdio.h> here |
---|
| 3 | * avoids issues where stdio.h has strange side effects |
---|
| 4 | */ |
---|
| 5 | #include <stdio.h> |
---|
| 6 | |
---|
| 7 | #ifdef PERLIO_IS_STDIO |
---|
| 8 | /* |
---|
| 9 | * Make this as close to original stdio as possible. |
---|
| 10 | */ |
---|
| 11 | #define PerlIO FILE |
---|
| 12 | #define PerlIO_stderr() stderr |
---|
| 13 | #define PerlIO_stdout() stdout |
---|
| 14 | #define PerlIO_stdin() stdin |
---|
| 15 | |
---|
| 16 | #define PerlIO_printf fprintf |
---|
| 17 | #define PerlIO_stdoutf printf |
---|
| 18 | #define PerlIO_vprintf(f,fmt,a) vfprintf(f,fmt,a) |
---|
| 19 | #define PerlIO_write(f,buf,count) fwrite1(buf,1,count,f) |
---|
| 20 | #define PerlIO_open fopen |
---|
| 21 | #define PerlIO_fdopen fdopen |
---|
| 22 | #define PerlIO_reopen freopen |
---|
| 23 | #define PerlIO_close(f) fclose(f) |
---|
| 24 | #define PerlIO_puts(f,s) fputs(s,f) |
---|
| 25 | #define PerlIO_putc(f,c) fputc(c,f) |
---|
| 26 | #if defined(VMS) |
---|
| 27 | # if defined(__DECC) |
---|
| 28 | /* Unusual definition of ungetc() here to accomodate fast_sv_gets()' |
---|
| 29 | * belief that it can mix getc/ungetc with reads from stdio buffer */ |
---|
| 30 | int decc$ungetc(int __c, FILE *__stream); |
---|
| 31 | # define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \ |
---|
| 32 | ((*(f) && !((*(f))->_flag & _IONBF) && \ |
---|
| 33 | ((*(f))->_ptr > (*(f))->_base)) ? \ |
---|
| 34 | ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f))) |
---|
| 35 | # else |
---|
| 36 | # define PerlIO_ungetc(f,c) ungetc(c,f) |
---|
| 37 | # endif |
---|
| 38 | /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old |
---|
| 39 | * VAXCRTL which causes read from a pipe after EOF has been returned |
---|
| 40 | * once to hang. |
---|
| 41 | */ |
---|
| 42 | # define PerlIO_getc(f) \ |
---|
| 43 | (feof(f) ? EOF : getc(f)) |
---|
| 44 | # define PerlIO_read(f,buf,count) \ |
---|
| 45 | (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f)) |
---|
| 46 | #else |
---|
| 47 | # define PerlIO_ungetc(f,c) ungetc(c,f) |
---|
| 48 | # define PerlIO_getc(f) getc(f) |
---|
| 49 | # define PerlIO_read(f,buf,count) (SSize_t)fread(buf,1,count,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 | #define PerlIO_tell(f) ftell(f) |
---|
| 58 | #define PerlIO_seek(f,o,w) fseek(f,o,w) |
---|
| 59 | #ifdef HAS_FGETPOS |
---|
| 60 | #define PerlIO_getpos(f,p) fgetpos(f,p) |
---|
| 61 | #endif |
---|
| 62 | #ifdef HAS_FSETPOS |
---|
| 63 | #define PerlIO_setpos(f,p) fsetpos(f,p) |
---|
| 64 | #endif |
---|
| 65 | |
---|
| 66 | #define PerlIO_rewind(f) rewind(f) |
---|
| 67 | #define PerlIO_tmpfile() tmpfile() |
---|
| 68 | |
---|
| 69 | #define PerlIO_importFILE(f,fl) (f) |
---|
| 70 | #define PerlIO_exportFILE(f,fl) (f) |
---|
| 71 | #define PerlIO_findFILE(f) (f) |
---|
| 72 | #define PerlIO_releaseFILE(p,f) ((void) 0) |
---|
| 73 | |
---|
| 74 | #ifdef HAS_SETLINEBUF |
---|
| 75 | #define PerlIO_setlinebuf(f) setlinebuf(f); |
---|
| 76 | #else |
---|
| 77 | #define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0); |
---|
| 78 | #endif |
---|
| 79 | |
---|
| 80 | /* Now our interface to Configure's FILE_xxx macros */ |
---|
| 81 | |
---|
| 82 | #ifdef USE_STDIO_PTR |
---|
| 83 | #define PerlIO_has_cntptr(f) 1 |
---|
| 84 | #define PerlIO_get_ptr(f) FILE_ptr(f) |
---|
| 85 | #define PerlIO_get_cnt(f) FILE_cnt(f) |
---|
| 86 | |
---|
| 87 | #ifdef STDIO_CNT_LVALUE |
---|
| 88 | #define PerlIO_canset_cnt(f) 1 |
---|
| 89 | #ifdef STDIO_PTR_LVALUE |
---|
| 90 | #define PerlIO_fast_gets(f) 1 |
---|
| 91 | #endif |
---|
| 92 | #define PerlIO_set_cnt(f,c) (FILE_cnt(f) = (c)) |
---|
| 93 | #else |
---|
| 94 | #define PerlIO_canset_cnt(f) 0 |
---|
| 95 | #define PerlIO_set_cnt(f,c) abort() |
---|
| 96 | #endif |
---|
| 97 | |
---|
| 98 | #ifdef STDIO_PTR_LVALUE |
---|
| 99 | #define PerlIO_set_ptrcnt(f,p,c) (FILE_ptr(f) = (p), PerlIO_set_cnt(f,c)) |
---|
| 100 | #else |
---|
| 101 | #define PerlIO_set_ptrcnt(f,p,c) abort() |
---|
| 102 | #endif |
---|
| 103 | |
---|
| 104 | #else /* USE_STDIO_PTR */ |
---|
| 105 | |
---|
| 106 | #define PerlIO_has_cntptr(f) 0 |
---|
| 107 | #define PerlIO_canset_cnt(f) 0 |
---|
| 108 | #define PerlIO_get_cnt(f) (abort(),0) |
---|
| 109 | #define PerlIO_get_ptr(f) (abort(),(void *)0) |
---|
| 110 | #define PerlIO_set_cnt(f,c) abort() |
---|
| 111 | #define PerlIO_set_ptrcnt(f,p,c) abort() |
---|
| 112 | |
---|
| 113 | #endif /* USE_STDIO_PTR */ |
---|
| 114 | |
---|
| 115 | #ifndef PerlIO_fast_gets |
---|
| 116 | #define PerlIO_fast_gets(f) 0 |
---|
| 117 | #endif |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | #ifdef FILE_base |
---|
| 121 | #define PerlIO_has_base(f) 1 |
---|
| 122 | #define PerlIO_get_base(f) FILE_base(f) |
---|
| 123 | #define PerlIO_get_bufsiz(f) FILE_bufsiz(f) |
---|
| 124 | #else |
---|
| 125 | #define PerlIO_has_base(f) 0 |
---|
| 126 | #define PerlIO_get_base(f) (abort(),(void *)0) |
---|
| 127 | #define PerlIO_get_bufsiz(f) (abort(),0) |
---|
| 128 | #endif |
---|
| 129 | #else /* PERLIO_IS_STDIO */ |
---|
| 130 | #ifdef PERL_CORE |
---|
| 131 | #ifndef PERLIO_NOT_STDIO |
---|
| 132 | #define PERLIO_NOT_STDIO 1 |
---|
| 133 | #endif |
---|
| 134 | #endif |
---|
| 135 | #ifdef PERLIO_NOT_STDIO |
---|
| 136 | #if PERLIO_NOT_STDIO |
---|
| 137 | /* |
---|
| 138 | * Strong denial of stdio - make all stdio calls (we can think of) errors |
---|
| 139 | */ |
---|
| 140 | #include "nostdio.h" |
---|
| 141 | #undef fprintf |
---|
| 142 | #undef tmpfile |
---|
| 143 | #undef fclose |
---|
| 144 | #undef fopen |
---|
| 145 | #undef vfprintf |
---|
| 146 | #undef fgetc |
---|
| 147 | #undef fputc |
---|
| 148 | #undef fputs |
---|
| 149 | #undef ungetc |
---|
| 150 | #undef fread |
---|
| 151 | #undef fwrite |
---|
| 152 | #undef fgetpos |
---|
| 153 | #undef fseek |
---|
| 154 | #undef fsetpos |
---|
| 155 | #undef ftell |
---|
| 156 | #undef rewind |
---|
| 157 | #undef fdopen |
---|
| 158 | #undef popen |
---|
| 159 | #undef pclose |
---|
| 160 | #undef getw |
---|
| 161 | #undef putw |
---|
| 162 | #undef freopen |
---|
| 163 | #undef setbuf |
---|
| 164 | #undef setvbuf |
---|
| 165 | #undef fscanf |
---|
| 166 | #undef fgets |
---|
| 167 | #undef getc_unlocked |
---|
| 168 | #undef putc_unlocked |
---|
| 169 | #define fprintf _CANNOT _fprintf_ |
---|
| 170 | #define stdin _CANNOT _stdin_ |
---|
| 171 | #define stdout _CANNOT _stdout_ |
---|
| 172 | #define stderr _CANNOT _stderr_ |
---|
| 173 | #define tmpfile() _CANNOT _tmpfile_ |
---|
| 174 | #define fclose(f) _CANNOT _fclose_ |
---|
| 175 | #define fflush(f) _CANNOT _fflush_ |
---|
| 176 | #define fopen(p,m) _CANNOT _fopen_ |
---|
| 177 | #define freopen(p,m,f) _CANNOT _freopen_ |
---|
| 178 | #define setbuf(f,b) _CANNOT _setbuf_ |
---|
| 179 | #define setvbuf(f,b,x,s) _CANNOT _setvbuf_ |
---|
| 180 | #define fscanf _CANNOT _fscanf_ |
---|
| 181 | #define vfprintf(f,fmt,a) _CANNOT _vfprintf_ |
---|
| 182 | #define fgetc(f) _CANNOT _fgetc_ |
---|
| 183 | #define fgets(s,n,f) _CANNOT _fgets_ |
---|
| 184 | #define fputc(c,f) _CANNOT _fputc_ |
---|
| 185 | #define fputs(s,f) _CANNOT _fputs_ |
---|
| 186 | #define getc(f) _CANNOT _getc_ |
---|
| 187 | #define putc(c,f) _CANNOT _putc_ |
---|
| 188 | #define ungetc(c,f) _CANNOT _ungetc_ |
---|
| 189 | #define fread(b,s,c,f) _CANNOT _fread_ |
---|
| 190 | #define fwrite(b,s,c,f) _CANNOT _fwrite_ |
---|
| 191 | #define fgetpos(f,p) _CANNOT _fgetpos_ |
---|
| 192 | #define fseek(f,o,w) _CANNOT _fseek_ |
---|
| 193 | #define fsetpos(f,p) _CANNOT _fsetpos_ |
---|
| 194 | #define ftell(f) _CANNOT _ftell_ |
---|
| 195 | #define rewind(f) _CANNOT _rewind_ |
---|
| 196 | #define clearerr(f) _CANNOT _clearerr_ |
---|
| 197 | #define feof(f) _CANNOT _feof_ |
---|
| 198 | #define ferror(f) _CANNOT _ferror_ |
---|
| 199 | #define __filbuf(f) _CANNOT __filbuf_ |
---|
| 200 | #define __flsbuf(c,f) _CANNOT __flsbuf_ |
---|
| 201 | #define _filbuf(f) _CANNOT _filbuf_ |
---|
| 202 | #define _flsbuf(c,f) _CANNOT _flsbuf_ |
---|
| 203 | #define fdopen(fd,p) _CANNOT _fdopen_ |
---|
| 204 | #define fileno(f) _CANNOT _fileno_ |
---|
| 205 | #define flockfile(f) _CANNOT _flockfile_ |
---|
| 206 | #define ftrylockfile(f) _CANNOT _ftrylockfile_ |
---|
| 207 | #define funlockfile(f) _CANNOT _funlockfile_ |
---|
| 208 | #define getc_unlocked(f) _CANNOT _getc_unlocked_ |
---|
| 209 | #define putc_unlocked(c,f) _CANNOT _putc_unlocked_ |
---|
| 210 | #define popen(c,m) _CANNOT _popen_ |
---|
| 211 | #define getw(f) _CANNOT _getw_ |
---|
| 212 | #define putw(v,f) _CANNOT _putw_ |
---|
| 213 | #define pclose(f) _CANNOT _pclose_ |
---|
| 214 | |
---|
| 215 | #else /* if PERLIO_NOT_STDIO */ |
---|
| 216 | /* |
---|
| 217 | * PERLIO_NOT_STDIO defined as 0 |
---|
| 218 | * Declares that both PerlIO and stdio can be used |
---|
| 219 | */ |
---|
| 220 | #endif /* if PERLIO_NOT_STDIO */ |
---|
| 221 | #else /* ifdef PERLIO_NOT_STDIO */ |
---|
| 222 | /* |
---|
| 223 | * PERLIO_NOT_STDIO not defined |
---|
| 224 | * This is "source level" stdio compatibility mode. |
---|
| 225 | */ |
---|
| 226 | #include "nostdio.h" |
---|
| 227 | #undef FILE |
---|
| 228 | #define FILE PerlIO |
---|
| 229 | #undef fprintf |
---|
| 230 | #undef tmpfile |
---|
| 231 | #undef fclose |
---|
| 232 | #undef fopen |
---|
| 233 | #undef vfprintf |
---|
| 234 | #undef fgetc |
---|
| 235 | #undef fputc |
---|
| 236 | #undef fputs |
---|
| 237 | #undef ungetc |
---|
| 238 | #undef fread |
---|
| 239 | #undef fwrite |
---|
| 240 | #undef fgetpos |
---|
| 241 | #undef fseek |
---|
| 242 | #undef fsetpos |
---|
| 243 | #undef ftell |
---|
| 244 | #undef rewind |
---|
| 245 | #undef fdopen |
---|
| 246 | #undef popen |
---|
| 247 | #undef pclose |
---|
| 248 | #undef getw |
---|
| 249 | #undef putw |
---|
| 250 | #undef freopen |
---|
| 251 | #undef setbuf |
---|
| 252 | #undef setvbuf |
---|
| 253 | #undef fscanf |
---|
| 254 | #undef fgets |
---|
| 255 | #define fprintf PerlIO_printf |
---|
| 256 | #define stdin PerlIO_stdin() |
---|
| 257 | #define stdout PerlIO_stdout() |
---|
| 258 | #define stderr PerlIO_stderr() |
---|
| 259 | #define tmpfile() PerlIO_tmpfile() |
---|
| 260 | #define fclose(f) PerlIO_close(f) |
---|
| 261 | #define fflush(f) PerlIO_flush(f) |
---|
| 262 | #define fopen(p,m) PerlIO_open(p,m) |
---|
| 263 | #define vfprintf(f,fmt,a) PerlIO_vprintf(f,fmt,a) |
---|
| 264 | #define fgetc(f) PerlIO_getc(f) |
---|
| 265 | #define fputc(c,f) PerlIO_putc(f,c) |
---|
| 266 | #define fputs(s,f) PerlIO_puts(f,s) |
---|
| 267 | #define getc(f) PerlIO_getc(f) |
---|
| 268 | #define getc_unlocked(f) PerlIO_getc(f) |
---|
| 269 | #define putc(c,f) PerlIO_putc(f,c) |
---|
| 270 | #define putc_unlocked(c,f) PerlIO_putc(c,f) |
---|
| 271 | #define ungetc(c,f) PerlIO_ungetc(f,c) |
---|
| 272 | #if 0 |
---|
| 273 | /* return values of read/write need work */ |
---|
| 274 | #define fread(b,s,c,f) PerlIO_read(f,b,(s*c)) |
---|
| 275 | #define fwrite(b,s,c,f) PerlIO_write(f,b,(s*c)) |
---|
| 276 | #else |
---|
| 277 | #define fread(b,s,c,f) _CANNOT fread |
---|
| 278 | #define fwrite(b,s,c,f) _CANNOT fwrite |
---|
| 279 | #endif |
---|
| 280 | #define fgetpos(f,p) PerlIO_getpos(f,p) |
---|
| 281 | #define fseek(f,o,w) PerlIO_seek(f,o,w) |
---|
| 282 | #define fsetpos(f,p) PerlIO_setpos(f,p) |
---|
| 283 | #define ftell(f) PerlIO_tell(f) |
---|
| 284 | #define rewind(f) PerlIO_rewind(f) |
---|
| 285 | #define clearerr(f) PerlIO_clearerr(f) |
---|
| 286 | #define feof(f) PerlIO_eof(f) |
---|
| 287 | #define ferror(f) PerlIO_error(f) |
---|
| 288 | #define fdopen(fd,p) PerlIO_fdopen(fd,p) |
---|
| 289 | #define fileno(f) PerlIO_fileno(f) |
---|
| 290 | #define popen(c,m) my_popen(c,m) |
---|
| 291 | #define pclose(f) my_pclose(f) |
---|
| 292 | |
---|
| 293 | #define __filbuf(f) _CANNOT __filbuf_ |
---|
| 294 | #define _filbuf(f) _CANNOT _filbuf_ |
---|
| 295 | #define __flsbuf(c,f) _CANNOT __flsbuf_ |
---|
| 296 | #define _flsbuf(c,f) _CANNOT _flsbuf_ |
---|
| 297 | #define getw(f) _CANNOT _getw_ |
---|
| 298 | #define putw(v,f) _CANNOT _putw_ |
---|
| 299 | #define flockfile(f) _CANNOT _flockfile_ |
---|
| 300 | #define ftrylockfile(f) _CANNOT _ftrylockfile_ |
---|
| 301 | #define funlockfile(f) _CANNOT _funlockfile_ |
---|
| 302 | #define freopen(p,m,f) _CANNOT _freopen_ |
---|
| 303 | #define setbuf(f,b) _CANNOT _setbuf_ |
---|
| 304 | #define setvbuf(f,b,x,s) _CANNOT _setvbuf_ |
---|
| 305 | #define fscanf _CANNOT _fscanf_ |
---|
| 306 | #define fgets(s,n,f) _CANNOT _fgets_ |
---|
| 307 | |
---|
| 308 | #endif /* ifdef PERLIO_NOT_STDIO */ |
---|
| 309 | #endif /* PERLIO_IS_STDIO */ |
---|