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