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