Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | /* perlsdio.h |
2 | * | |
3 | * Copyright (c) 1997-2002, Larry Wall | |
4 | * | |
5 | * You may distribute under the terms of either the GNU General Public | |
6 | * License or the Artistic License, as specified in the README file. | |
7 | * | |
8 | */ | |
9 | ||
10 | #ifdef PERLIO_IS_STDIO | |
11 | ||
12 | #ifdef NETWARE | |
13 | #include "nwstdio.h" | |
14 | #else | |
15 | ||
16 | /* | |
17 | * This file #define-s the PerlIO_xxx abstraction onto stdio functions. | |
18 | * Make this as close to original stdio as possible. | |
19 | */ | |
20 | #define PerlIO FILE | |
21 | #define PerlIO_stderr() PerlSIO_stderr | |
22 | #define PerlIO_stdout() PerlSIO_stdout | |
23 | #define PerlIO_stdin() PerlSIO_stdin | |
24 | ||
25 | #define PerlIO_isutf8(f) 0 | |
26 | ||
27 | #define PerlIO_printf PerlSIO_printf | |
28 | #define PerlIO_stdoutf PerlSIO_stdoutf | |
29 | #define PerlIO_vprintf(f,fmt,a) PerlSIO_vprintf(f,fmt,a) | |
30 | #define PerlIO_write(f,buf,count) PerlSIO_fwrite(buf,1,count,f) | |
31 | #define PerlIO_unread(f,buf,count) (-1) | |
32 | #define PerlIO_open PerlSIO_fopen | |
33 | #define PerlIO_fdopen PerlSIO_fdopen | |
34 | #define PerlIO_reopen PerlSIO_freopen | |
35 | #define PerlIO_close(f) PerlSIO_fclose(f) | |
36 | #define PerlIO_puts(f,s) PerlSIO_fputs(f,s) | |
37 | #define PerlIO_putc(f,c) PerlSIO_fputc(f,c) | |
38 | #if defined(VMS) | |
39 | # if defined(__DECC) | |
40 | /* Unusual definition of ungetc() here to accomodate fast_sv_gets()' | |
41 | * belief that it can mix getc/ungetc with reads from stdio buffer */ | |
42 | int decc$ungetc(int __c, FILE *__stream); | |
43 | # define PerlIO_ungetc(f,c) ((c) == EOF ? EOF : \ | |
44 | ((*(f) && !((*(f))->_flag & _IONBF) && \ | |
45 | ((*(f))->_ptr > (*(f))->_base)) ? \ | |
46 | ((*(f))->_cnt++, *(--(*(f))->_ptr) = (c)) : decc$ungetc(c,f))) | |
47 | # else | |
48 | # define PerlIO_ungetc(f,c) ungetc(c,f) | |
49 | # endif | |
50 | /* Work around bug in DECCRTL/AXP (DECC v5.x) and some versions of old | |
51 | * VAXCRTL which causes read from a pipe after EOF has been returned | |
52 | * once to hang. | |
53 | */ | |
54 | # define PerlIO_getc(f) \ | |
55 | (feof(f) ? EOF : getc(f)) | |
56 | # define PerlIO_read(f,buf,count) \ | |
57 | (feof(f) ? 0 : (SSize_t)fread(buf,1,count,f)) | |
58 | # define PerlIO_tell(f) ftell(f) | |
59 | #else | |
60 | # define PerlIO_getc(f) PerlSIO_fgetc(f) | |
61 | # define PerlIO_ungetc(f,c) PerlSIO_ungetc(c,f) | |
62 | # define PerlIO_read(f,buf,count) (SSize_t)PerlSIO_fread(buf,1,count,f) | |
63 | # define PerlIO_tell(f) PerlSIO_ftell(f) | |
64 | #endif | |
65 | #define PerlIO_eof(f) PerlSIO_feof(f) | |
66 | #define PerlIO_getname(f,b) fgetname(f,b) | |
67 | #define PerlIO_error(f) PerlSIO_ferror(f) | |
68 | #define PerlIO_fileno(f) PerlSIO_fileno(f) | |
69 | #define PerlIO_clearerr(f) PerlSIO_clearerr(f) | |
70 | #define PerlIO_flush(f) PerlSIO_fflush(f) | |
71 | #if defined(VMS) && !defined(__DECC) | |
72 | /* Old VAXC RTL doesn't reset EOF on seek; Perl folk seem to expect this */ | |
73 | #define PerlIO_seek(f,o,w) (((f) && (*f) && ((*f)->_flag &= ~_IOEOF)),fseek(f,o,w)) | |
74 | #else | |
75 | # define PerlIO_seek(f,o,w) PerlSIO_fseek(f,o,w) | |
76 | #endif | |
77 | ||
78 | #define PerlIO_rewind(f) PerlSIO_rewind(f) | |
79 | #define PerlIO_tmpfile() PerlSIO_tmpfile() | |
80 | ||
81 | #define PerlIO_importFILE(f,fl) (f) | |
82 | #define PerlIO_exportFILE(f,fl) (f) | |
83 | #define PerlIO_findFILE(f) (f) | |
84 | #define PerlIO_releaseFILE(p,f) ((void) 0) | |
85 | ||
86 | #ifdef HAS_SETLINEBUF | |
87 | #define PerlIO_setlinebuf(f) PerlSIO_setlinebuf(f); | |
88 | #else | |
89 | #define PerlIO_setlinebuf(f) PerlSIO_setvbuf(f, Nullch, _IOLBF, 0); | |
90 | #endif | |
91 | ||
92 | /* Now our interface to Configure's FILE_xxx macros */ | |
93 | ||
94 | #ifdef USE_STDIO_PTR | |
95 | #define PerlIO_has_cntptr(f) 1 | |
96 | #define PerlIO_get_ptr(f) PerlSIO_get_ptr(f) | |
97 | #define PerlIO_get_cnt(f) PerlSIO_get_cnt(f) | |
98 | ||
99 | #ifdef STDIO_CNT_LVALUE | |
100 | #define PerlIO_canset_cnt(f) 1 | |
101 | #define PerlIO_set_cnt(f,c) PerlSIO_set_cnt(f,c) | |
102 | #ifdef STDIO_PTR_LVALUE | |
103 | #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT | |
104 | #define PerlIO_fast_gets(f) 1 | |
105 | #endif | |
106 | #endif /* STDIO_PTR_LVALUE */ | |
107 | #else /* STDIO_CNT_LVALUE */ | |
108 | #define PerlIO_canset_cnt(f) 0 | |
109 | #define PerlIO_set_cnt(f,c) abort() | |
110 | #endif | |
111 | ||
112 | #ifdef STDIO_PTR_LVALUE | |
113 | #ifdef STDIO_PTR_LVAL_NOCHANGE_CNT | |
114 | #define PerlIO_set_ptrcnt(f,p,c) STMT_START {PerlSIO_set_ptr(f,p), PerlIO_set_cnt(f,c);} STMT_END | |
115 | #else | |
116 | #ifdef STDIO_PTR_LVAL_SETS_CNT | |
117 | /* assert() may pre-process to ""; potential syntax error (FILE_ptr(), ) */ | |
118 | #define PerlIO_set_ptrcnt(f,p,c) STMT_START {PerlSIO_set_ptr(f,p); assert(PerlSIO_get_cnt(f) == (c));} STMT_END | |
119 | #define PerlIO_fast_gets(f) 1 | |
120 | #else | |
121 | #define PerlIO_set_ptrcnt(f,p,c) abort() | |
122 | #endif | |
123 | #endif | |
124 | #endif | |
125 | ||
126 | #else /* USE_STDIO_PTR */ | |
127 | ||
128 | #define PerlIO_has_cntptr(f) 0 | |
129 | #define PerlIO_canset_cnt(f) 0 | |
130 | #define PerlIO_get_cnt(f) (abort(),0) | |
131 | #define PerlIO_get_ptr(f) (abort(),(void *)0) | |
132 | #define PerlIO_set_cnt(f,c) abort() | |
133 | #define PerlIO_set_ptrcnt(f,p,c) abort() | |
134 | ||
135 | #endif /* USE_STDIO_PTR */ | |
136 | ||
137 | #ifndef PerlIO_fast_gets | |
138 | #define PerlIO_fast_gets(f) 0 | |
139 | #endif | |
140 | ||
141 | ||
142 | #ifdef FILE_base | |
143 | #define PerlIO_has_base(f) 1 | |
144 | #define PerlIO_get_base(f) PerlSIO_get_base(f) | |
145 | #define PerlIO_get_bufsiz(f) PerlSIO_get_bufsiz(f) | |
146 | #else | |
147 | #define PerlIO_has_base(f) 0 | |
148 | #define PerlIO_get_base(f) (abort(),(void *)0) | |
149 | #define PerlIO_get_bufsiz(f) (abort(),0) | |
150 | #endif | |
151 | ||
152 | #endif /* NETWARE */ | |
153 | #endif /* PERLIO_IS_STDIO */ |