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