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