3 ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
5 ?RCS: You may redistribute only under the terms of the Artistic License,
6 ?RCS: as specified in the README file that comes with the distribution.
7 ?RCS: You may reuse parts of this distribution only within the terms of
8 ?RCS: that same Artistic License; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 4.0.
11 ?RCS: Original Author: Tye McQueen <tye@metronet.com>
13 ?RCS: $Log: d_stdstdio.U,v $
14 ?RCS: Revision 3.0.1.3 1997/02/28 15:46:32 ram
15 ?RCS: patch61: merged with perl5's unit
17 ?RCS: Revision 3.0.1.2 1995/07/25 14:06:54 ram
18 ?RCS: patch56: typo fix on ?C: line for FILE_bufsiz
19 ?RCS: patch56: fixed unbalanced parenthesis (ADO)
20 ?RCS: patch56: check whether FILE_cnt and FILE_ptr can be assigned to (ADO)
22 ?RCS: Revision 3.0.1.1 1995/05/12 12:12:11 ram
23 ?RCS: patch54: complete rewrite by Tye McQueen to fit modern systems
25 ?RCS: Revision 3.0 1993/08/18 12:07:31 ram
26 ?RCS: Baseline for dist 3.0 netwide release.
28 ?MAKE:d_stdstdio d_stdiobase stdio_ptr stdio_cnt stdio_base \
29 stdio_bufsiz d_stdio_cnt_lval d_stdio_ptr_lval stdio_filbuf: cat \
30 +cc +ccflags contains +ldflags +libs rm \
31 Setvar Findhdr Oldconfig
32 ?MAKE: -pick add $@ %<
34 ?S: This variable conditionally defines USE_STDIO_PTR if this system
35 ?S: has a FILE structure declaring usable _ptr and _cnt fields (or
36 ?S: equivalent) in stdio.h.
39 ?S: This variable defines how, given a FILE pointer, fp, to access the
40 ?S: _ptr field (or equivalent) of stdio.h's FILE structure. This will
41 ?S: be used to define the macro FILE_ptr(fp).
44 ?S: This variable conditionally defines STDIO_PTR_LVALUE if the
45 ?S: FILE_ptr macro can be used as an lvalue.
48 ?S: This variable defines how, given a FILE pointer, fp, to access the
49 ?S: _cnt field (or equivalent) of stdio.h's FILE structure. This will
50 ?S: be used to define the macro FILE_cnt(fp).
53 ?S: This variable conditionally defines STDIO_CNT_LVALUE if the
54 ?S: FILE_cnt macro can be used as an lvalue.
57 ?S: This variable defines how, given a FILE pointer, fp, to tell
58 ?S: stdio to refill it's internal buffers (?). This will
59 ?S: be used to define the macro FILE_filbuf(fp).
62 ?S: This variable conditionally defines USE_STDIO_BASE if this system
63 ?S: has a FILE structure declaring a usable _base field (or equivalent)
67 ?S: This variable defines how, given a FILE pointer, fp, to access the
68 ?S: _base field (or equivalent) of stdio.h's FILE structure. This will
69 ?S: be used to define the macro FILE_base(fp).
72 ?S: This variable defines how, given a FILE pointer, fp, to determine
73 ?S: the number of bytes store in the I/O buffer pointer to by the
74 ?S: _base field (or equivalent) of stdio.h's FILE structure. This will
75 ?S: be used to define the macro FILE_bufsiz(fp).
77 ?C:USE_STDIO_PTR ~ d_stdstdio (USE_STD_STDIO STDSTDIO):
78 ?C: This symbol is defined if the _ptr and _cnt fields (or similar)
79 ?C: of the stdio FILE structure can be used to access the stdio buffer
80 ?C: for a file handle. If this is defined, then the FILE_ptr(fp)
81 ?C: and FILE_cnt(fp) macros will also be defined and should be used
82 ?C: to access these fields.
85 ?C: This macro is used to access the _ptr field (or equivalent) of the
86 ?C: FILE structure pointed to by its argument. This macro will always be
87 ?C: defined if USE_STDIO_PTR is defined.
90 ?C: This symbol is defined if the FILE_ptr macro can be used as an
94 ?C: This macro is used to access the _cnt field (or equivalent) of the
95 ?C: FILE structure pointed to by its argument. This macro will always be
96 ?C: defined if USE_STDIO_PTR is defined.
99 ?C: This symbol is defined if the FILE_cnt macro can be used as an
103 ?C: This macro is used to access the internal stdio _filbuf function
104 ?C: (or equivalent), if STDIO_CNT_LVALUE and STDIO_PTR_LVALUE
105 ?C: are defined. It is typically either _filbuf or __filbuf.
106 ?C: This macro will only be defined if both STDIO_CNT_LVALUE and
107 ?C: STDIO_PTR_LVALUE are defined.
109 ?H:?d_stdstdio:#$d_stdstdio USE_STDIO_PTR /**/
110 ?H:?d_stdstdio:#ifdef USE_STDIO_PTR
111 ?H:#define FILE_ptr(fp) $stdio_ptr
112 ?H:#$d_stdio_ptr_lval STDIO_PTR_LVALUE /**/
113 ?H:#define FILE_cnt(fp) $stdio_cnt
114 ?H:#$d_stdio_cnt_lval STDIO_CNT_LVALUE /**/
115 ?H:?d_stdstdio:#if defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE)
116 ?H:#define FILE_filbuf(fp) $stdio_filbuf /**/
117 ?H:?d_stdstdio:#endif
118 ?H:?d_stdstdio:#endif
120 ?W:d_stdstdio:FILE_ptr FILE_cnt FILE_filbuf
121 ?C:USE_STDIO_BASE ~ d_stdiobase:
122 ?C: This symbol is defined if the _base field (or similar) of the
123 ?C: stdio FILE structure can be used to access the stdio buffer for
124 ?C: a file handle. If this is defined, then the FILE_base(fp) macro
125 ?C: will also be defined and should be used to access this field.
126 ?C: Also, the FILE_bufsiz(fp) macro will be defined and should be used
127 ?C: to determine the number of bytes in the buffer. USE_STDIO_BASE
128 ?C: will never be defined unless USE_STDIO_PTR is.
131 ?C: This macro is used to access the _base field (or equivalent) of the
132 ?C: FILE structure pointed to by its argument. This macro will always be
133 ?C: defined if USE_STDIO_BASE is defined.
136 ?C: This macro is used to determine the number of bytes in the I/O
137 ?C: buffer pointed to by _base field (or equivalent) of the FILE
138 ?C: structure pointed to its argument. This macro will always be defined
139 ?C: if USE_STDIO_BASE is defined.
141 ?H:?d_stdiobase:#$d_stdiobase USE_STDIO_BASE /**/
142 ?H:?d_stdiobase:#ifdef USE_STDIO_BASE
143 ?H:#define FILE_base(fp) $stdio_base
144 ?H:#define FILE_bufsiz(fp) $stdio_bufsiz
145 ?H:?d_stdiobase:#endif
147 ?W:d_stdiobase:FILE_base FILE_bufsiz
148 ?LINT:set d_stdstdio d_stdiobase
149 ?T:ptr_lval cnt_lval filbuf xxx
151 : see if _ptr and _cnt from stdio act std
153 if $contains '_IO_fpos_t' `./findhdr stdio.h` >/dev/null 2>&1 ; then
154 echo "(Looks like you have stdio.h from Linux.)"
156 '') stdio_ptr='((fp)->_IO_read_ptr)'
159 *) ptr_lval=$d_stdio_ptr_lval;;
162 '') stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)'
165 *) cnt_lval=$d_stdio_cnt_lval;;
167 case "$stdio_base" in
168 '') stdio_base='((fp)->_IO_read_base)';;
170 case "$stdio_bufsiz" in
171 '') stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)';;
175 '') stdio_ptr='((fp)->_ptr)'
178 *) ptr_lval=$d_stdio_ptr_lval;;
181 '') stdio_cnt='((fp)->_cnt)'
184 *) cnt_lval=$d_stdio_cnt_lval;;
186 case "$stdio_base" in
187 '') stdio_base='((fp)->_base)';;
189 case "$stdio_bufsiz" in
190 '') stdio_bufsiz='((fp)->_cnt + (fp)->_ptr - (fp)->_base)';;
193 : test whether _ptr and _cnt really work
194 echo "Checking how std your stdio is..." >&4
197 #define FILE_ptr(fp) $stdio_ptr
198 #define FILE_cnt(fp) $stdio_cnt
200 FILE *fp = fopen("try.c", "r");
203 18 <= FILE_cnt(fp) &&
204 strncmp(FILE_ptr(fp), "include <stdio.h>\n", 18) == 0
211 if $cc $ccflags $ldflags -o try try.c $libs >/dev/null 2>&1; then
213 echo "Your stdio acts pretty std."
216 echo "Your stdio isn't very std."
219 echo "Your stdio doesn't appear very std."
225 @if STDIO_PTR_LVALUE || d_stdio_ptr_lval
226 : Can _ptr be used as an lvalue?
227 ?X: Only makes sense if we have a known stdio implementation.
228 case "$d_stdstdio$ptr_lval" in
229 $define$define) val=$define ;;
236 @if STDIO_CNT_LVALUE || d_stdio_cnt_lval
237 : Can _cnt be used as an lvalue?
238 ?X: Only makes sense if we have a known stdio implementation.
239 case "$d_stdstdio$cnt_lval" in
240 $define$define) val=$define ;;
248 : How to access the stdio _filbuf or __filbuf function.
249 : If this fails, check how the getc macro in stdio.h works.
250 case "${d_stdio_ptr_lval}${d_stdio_cnt_lval}" in
252 : Try hint value, if any, then _filbuf, __filbuf, _fill, then punt.
255 for filbuf in $stdio_filbuf '_filbuf(fp)' '__filbuf(fp) ' '_fill(fp)' ; do
258 #define FILE_ptr(fp) $stdio_ptr
259 #define FILE_cnt(fp) $stdio_cnt
260 #define FILE_filbuf(fp) $filbuf
262 FILE *fp = fopen("try.c", "r");
265 c = FILE_filbuf(fp); /* Just looking for linker errors.*/
269 if $cc $ccflags $ldflags -o try try.c $libs >/dev/null 2>&1 && ./try; then
270 echo "Your stdio appears to use $filbuf"
271 stdio_filbuf="$filbuf"
275 echo "Hmm. $filbuf doesn't seem to work."
280 notok) echo "I can't figure out how to access _filbuf"
281 echo "I'll just have to work around it."
282 d_stdio_ptr_lval="$undef"
283 d_stdio_cnt_lval="$undef"
289 @if d_stdiobase || USE_STDIO_BASE || FILE_base || FILE_bufsiz
290 : see if _base is also standard
292 case "$d_stdstdio" in
296 #define FILE_base(fp) $stdio_base
297 #define FILE_bufsiz(fp) $stdio_bufsiz
299 FILE *fp = fopen("try.c", "r");
302 19 <= FILE_bufsiz(fp) &&
303 strncmp(FILE_base(fp), "#include <stdio.h>\n", 19) == 0
309 if $cc $ccflags $ldflags -o try try.c $libs > /dev/null 2>&1; then
311 echo "And its _base field acts std."
314 echo "But its _base field isn't std."
317 echo "However, it seems to be lacking the _base field."