2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)schilyio.h 2.22 04/09/04 Copyright 1986, 1995-2003 J. Schilling */
15 * Copyright (c) 1986, 1995-2003 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifndef _STDIO_SCHILYIO_H
33 #define _STDIO_SCHILYIO_H
43 # ifdef HAVE_USG_STDIO
44 # undef HAVE_USG_STDIO
48 /*#if _LFS_LARGEFILE*/
49 #ifdef HAVE_LARGEFILES
51 * XXX We may need to put this code to a more global place to allow all
52 * XXX users of fseek()/ftell() to automaticaly use fseeko()/ftello()
53 * XXX if the latter are available.
55 * If HAVE_LARGEFILES is defined, it is guaranteed that fseeko()/ftello()
61 #else /* !HAVE_LARGEFILES */
63 * If HAVE_LARGEFILES is not defined, we depend on specific tests for
64 * fseeko()/ftello() which must have been done before the tests for
65 * Large File support have been done.
66 * Note that this only works if the tests used below are really done before
67 * the Large File autoconf test is run. This is because autoconf does no
68 * clean testing but instead cumulatively modifes the envivonment used for
87 #define _openfd(name, omode) (open(name, omode, 0666))
90 #define DO_MYFLAG /* use local flags */
93 * Flags used during fileopen(), ... by _fcons()/ _cvmod()
95 #define FI_NONE 0x0000 /* no flags defined */
97 #define FI_READ 0x0001 /* open for reading */
98 #define FI_WRITE 0x0002 /* open for writing */
99 #define FI_BINARY 0x0004 /* open in binary mode */
100 #define FI_APPEND 0x0008 /* append on each write */
102 #define FI_CREATE 0x0010 /* create if nessecary */
103 #define FI_TRUNC 0x0020 /* truncate file on open */
104 #define FI_UNBUF 0x0080 /* dont't buffer io */
105 #define FI_CLOSE 0x1000 /* close file on error */
110 #define _IONORAISE 01 /* do no raisecond() on errors */
111 #define _IOUNBUF 02 /* do unbuffered i/o */
116 FILE *fl_io; /* file pointer */
117 struct _io_flags /* pointer to next struct */
118 *fl_next; /* if more file pointer to same fd */
119 int fl_flags; /* my flags */
122 typedef struct _io_flags _io_fl;
124 extern int _io_glflag; /* global default flag */
125 extern _io_fl *_io_myfl; /* array of structs to hold my flags */
126 extern int _fl_max; /* max fd currently in _io_myfl */
131 * else if map[fileno].pointer == 0
133 * else if map[fileno].pointer == p
134 * return map[fileno].flags
138 #define flp(p) (&_io_myfl[fileno(p)])
140 #ifdef MY_FLAG_IS_MACRO
141 #define my_flag(p) ((int)fileno(p) >= _fl_max ? \
142 _io_get_my_flag(p) : \
143 ((flp(p)->fl_io == 0 || flp(p)->fl_io == p) ? \
147 #define my_flag(p) _io_get_my_flag(p)
150 #define set_my_flag(p, v) _io_set_my_flag(p, v)
151 #define add_my_flag(p, v) _io_add_my_flag(p, v)
153 extern int _io_get_my_flag __PR((FILE *));
154 extern void _io_set_my_flag __PR((FILE *, int));
155 extern void _io_add_my_flag __PR((FILE *, int));
157 #else /* DO_MYFLAG */
159 #define my_flag(p) _IONORAISE /* Always noraise */
160 #define set_my_flag(p, v) /* Ignore */
161 #define add_my_flag(p, v) /* Ignore */
163 #endif /* DO_MYFLAG */
165 #ifdef HAVE_USG_STDIO
168 * Use the right filbuf()/flsbuf() function.
171 # define usg_filbuf(fp) __filbuf(fp)
172 # define usg_flsbuf(c, fp) __flsbuf(c, fp)
174 * Define prototypes to verify if our interface is right
176 extern int __filbuf __PR((FILE *));
177 /*extern int __flsbuf __PR(());*/
180 # define usg_filbuf(fp) _filbuf(fp)
181 # define usg_flsbuf(c, fp) _flsbuf(c, fp)
183 * Define prototypes to verify if our interface is right
185 extern int _filbuf __PR((FILE *));
186 /*extern int _flsbuf __PR(());*/
189 * no filbuf() but this will not happen on USG_STDIO systems.
194 * Do not check this because flsbuf()'s 1st parameter may be
196 * unsigned int Apollo
197 * unsigned char HP-UX-11
199 * Note that the interface is now checked by autoconf.
201 /*extern int _flsbuf __PR((int, FILE *));*/
204 * If we are on a non USG system we cannot down file pointers
214 #define down1(f, fl1)
215 #define down2(f, fl1, fl2)
218 * Do stream checking (works only on USG stdio)
220 * New version of USG stdio.
221 * _iob[] holds only a small amount of pointers.
222 * Aditional space is allocated.
223 * We may check only if the file pointer is != NULL
224 * and if iop->_flag refers to a stream with appropriate modes.
225 * If _iob[] gets expanded by malloc() we cannot check upper bound.
227 #define down(f) ((f) == 0 || (f)->_flag == 0 ? \
228 (raisecond(_badfile, 0L), (FILE *)0) : (f))
230 #define down1(f, fl1) ((f) == 0 || (f)->_flag == 0 ? \
231 (raisecond(_badfile, 0L), (FILE *)0) : \
232 (((f)->_flag & fl1) != fl1 ? \
233 (raisecond(_badop, 0L), (FILE *)0) : \
236 #define down2(f, fl1, fl2) ((f) == 0 || (f)->_flag == 0 ? \
237 (raisecond(_badfile, 0L), (FILE *)0) : \
238 (((f)->_flag & fl1) != fl1 && \
239 ((f)->_flag & fl2) != fl2 ? \
240 (raisecond(_badop, 0L), (FILE *)0) : \
244 extern char _badfile[];
245 extern char _badmode[];
246 extern char _badop[];
248 #endif /* _STDIO_SCHILYIO_H */