[MKISOFS]
[reactos.git] / reactos / sdk / tools / mkisofs / schilytools / libschily / stdio / schilyio.h
1 /* @(#)schilyio.h 2.28 10/08/23 Copyright 1986, 1995-2010 J. Schilling */
2 /*
3 * Copyright (c) 1986, 1995-2010 J. Schilling
4 */
5 /*
6 * The contents of this file are subject to the terms of the
7 * Common Development and Distribution License, Version 1.0 only
8 * (the "License"). You may not use this file except in compliance
9 * with the License.
10 *
11 * See the file CDDL.Schily.txt in this distribution for details.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file CDDL.Schily.txt from this distribution.
15 */
16
17 #ifndef _STDIO_SCHILYIO_H
18 #define _STDIO_SCHILYIO_H
19
20 #include <schily/mconfig.h>
21 #include <schily/stdio.h>
22 #include <schily/standard.h>
23 #include <schily/types.h>
24 #include <schily/unistd.h>
25 #include <schily/fcntl.h>
26 #include <schily/schily.h>
27 #include <schily/errno.h>
28
29 #ifdef NO_USG_STDIO
30 # ifdef HAVE_USG_STDIO
31 # undef HAVE_USG_STDIO
32 # endif
33 #endif
34
35 #ifdef HAVE_LARGEFILES
36 /*
37 * XXX We may need to put this code to a more global place to allow all
38 * XXX users of fseek()/ftell() to automaticaly use fseeko()/ftello()
39 * XXX if the latter are available.
40 *
41 * If HAVE_LARGEFILES is defined, it is guaranteed that fseeko()/ftello()
42 * both are available.
43 */
44 # define fseek fseeko
45 # define ftell ftello
46
47 #else /* !HAVE_LARGEFILES */
48 /*
49 * If HAVE_LARGEFILES is not defined, we depend on specific tests for
50 * fseeko()/ftello() which must have been done before the tests for
51 * Large File support have been done.
52 * Note that this only works if the tests used below are really done before
53 * the Large File autoconf test is run. This is because autoconf does no
54 * clean testing but instead cumulatively modifes the envivonment used for
55 * testing.
56 */
57 #ifdef HAVE_FSEEKO
58 # define fseek fseeko
59 #endif
60 #ifdef HAVE_FTELLO
61 # define ftell ftello
62 #endif
63
64 #endif
65
66 /*
67 * speed things up...
68 */
69 #ifndef _OPENFD_SRC
70 #ifdef _openfd
71 #undef _openfd
72 #endif
73 #define _openfd(name, omode) (open(name, omode, (mode_t)0666))
74 #endif
75
76 #define DO_MYFLAG /* use local flags */
77
78 /*
79 * Flags used during fileopen(), ... by _fcons()/ _cvmod()
80 */
81 #define FI_NONE 0x0000 /* no flags defined */
82
83 #define FI_READ 0x0001 /* open for reading */
84 #define FI_WRITE 0x0002 /* open for writing */
85 #define FI_BINARY 0x0004 /* open in binary mode */
86 #define FI_APPEND 0x0008 /* append on each write */
87
88 #define FI_CREATE 0x0010 /* create if nessecary */
89 #define FI_TRUNC 0x0020 /* truncate file on open */
90 #define FI_UNBUF 0x0080 /* dont't buffer io */
91 #define FI_CLOSE 0x1000 /* close file on error */
92
93 /*
94 * Additional Schily FILE * flags that are not present with the
95 * standard stdio implementation.
96 */
97 #define _JS_IONORAISE 01 /* do no raisecond() on errors */
98 #define _JS_IOUNBUF 02 /* do unbuffered i/o */
99
100
101 #ifdef DO_MYFLAG
102
103 struct _io_flags {
104 FILE *fl_io; /* file pointer */
105 struct _io_flags /* pointer to next struct */
106 *fl_next; /* if more file pointer to same fd */
107 int fl_flags; /* my flags */
108 };
109
110 typedef struct _io_flags _io_fl;
111
112 extern int _io_glflag; /* global default flag */
113 extern _io_fl *_io_myfl; /* array of structs to hold my flags */
114 extern int _fl_max; /* max fd currently in _io_myfl */
115
116 /*
117 * if fileno > max
118 * expand
119 * else if map[fileno].pointer == 0
120 * return 0
121 * else if map[fileno].pointer == p
122 * return map[fileno].flags
123 * else
124 * search list
125 */
126 #define flp(p) (&_io_myfl[fileno(p)])
127
128 #ifdef MY_FLAG_IS_MACRO
129 #define my_flag(p) ((int)fileno(p) >= _fl_max ? \
130 _io_get_my_flag(p) : \
131 ((flp(p)->fl_io == 0 || flp(p)->fl_io == p) ? \
132 flp(p)->fl_flags : \
133 _io_get_my_flag(p)))
134 #else
135 #define my_flag(p) _io_get_my_flag(p)
136 #endif
137
138 #define set_my_flag(p, v) _io_set_my_flag(p, v)
139 #define add_my_flag(p, v) _io_add_my_flag(p, v)
140
141 extern int _io_get_my_flag __PR((FILE *));
142 extern void _io_set_my_flag __PR((FILE *, int));
143 extern void _io_add_my_flag __PR((FILE *, int));
144
145 #else /* DO_MYFLAG */
146
147 #define my_flag(p) _JS_IONORAISE /* Always noraise */
148 #define set_my_flag(p, v) /* Ignore */
149 #define add_my_flag(p, v) /* Ignore */
150
151 #endif /* DO_MYFLAG */
152
153 #ifdef HAVE_USG_STDIO
154
155 /*
156 * Use the right filbuf()/flsbuf() function.
157 */
158 #ifdef HAVE___FILBUF
159 # define usg_filbuf(fp) __filbuf(fp)
160 # define usg_flsbuf(c, fp) __flsbuf(c, fp)
161 /*
162 * Define prototypes to verify if our interface is right
163 */
164 extern int __filbuf __PR((FILE *));
165 #else
166 # ifdef HAVE__FILBUF
167 # define usg_filbuf(fp) _filbuf(fp)
168 # define usg_flsbuf(c, fp) _flsbuf(c, fp)
169 /*
170 * Define prototypes to verify if our interface is right
171 */
172 extern int _filbuf __PR((FILE *));
173 # else
174 /*
175 * no filbuf() but this will not happen on USG_STDIO systems.
176 */
177 # endif
178 #endif
179 /*
180 * Do not check this because flsbuf()'s 1st parameter may be
181 * int SunOS
182 * unsigned int Apollo
183 * unsigned char HP-UX-11
184 *
185 * Note that the interface is now checked by autoconf.
186 */
187 #else
188 /*
189 * If we are on a non USG system we cannot down file pointers
190 */
191 #undef DO_DOWN
192 #endif
193
194 #ifndef DO_DOWN
195 /*
196 * No stream checking
197 */
198 #define down(f)
199 #define down1(f, fl1)
200 #define down2(f, fl1, fl2)
201 #else
202 /*
203 * Do stream checking (works only on USG stdio)
204 *
205 * New version of USG stdio.
206 * _iob[] holds only a small amount of pointers.
207 * Aditional space is allocated.
208 * We may check only if the file pointer is != NULL
209 * and if iop->_flag refers to a stream with appropriate modes.
210 * If _iob[] gets expanded by malloc() we cannot check upper bound.
211 */
212 #define down(f) ((f) == 0 || (f)->_flag == 0 ? \
213 (raisecond(_badfile, 0L), (FILE *)0) : (f))
214
215 #define down1(f, fl1) ((f) == 0 || (f)->_flag == 0 ? \
216 (raisecond(_badfile, 0L), (FILE *)0) : \
217 (((f)->_flag & fl1) != fl1 ? \
218 (raisecond(_badop, 0L), (FILE *)0) : \
219 (f)))
220
221 #define down2(f, fl1, fl2) ((f) == 0 || (f)->_flag == 0 ? \
222 (raisecond(_badfile, 0L), (FILE *)0) : \
223 (((f)->_flag & fl1) != fl1 && \
224 ((f)->_flag & fl2) != fl2 ? \
225 (raisecond(_badop, 0L), (FILE *)0) : \
226 (f)))
227 #endif /* DO_DOWN */
228
229 extern char _badfile[];
230 extern char _badmode[];
231 extern char _badop[];
232
233 #endif /* _STDIO_SCHILYIO_H */