Lines 1-5
Link Here
|
1 |
/* Implementation details of FILE streams. |
1 |
/* Implementation details of FILE streams. |
2 |
Copyright (C) 2007-2008, 2010-2015 Free Software Foundation, Inc. |
2 |
Copyright (C) 2007-2008, 2010-2018 Free Software Foundation, Inc. |
3 |
|
3 |
|
4 |
This program is free software: you can redistribute it and/or modify |
4 |
This program is free software: you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
5 |
it under the terms of the GNU General Public License as published by |
Lines 12-23
Link Here
|
12 |
GNU General Public License for more details. |
12 |
GNU General Public License for more details. |
13 |
|
13 |
|
14 |
You should have received a copy of the GNU General Public License |
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
16 |
|
16 |
|
17 |
/* Many stdio implementations have the same logic and therefore can share |
17 |
/* Many stdio implementations have the same logic and therefore can share |
18 |
the same implementation of stdio extension API, except that some fields |
18 |
the same implementation of stdio extension API, except that some fields |
19 |
have different naming conventions, or their access requires some casts. */ |
19 |
have different naming conventions, or their access requires some casts. */ |
20 |
|
20 |
|
|
|
21 |
/* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this |
22 |
problem by defining it ourselves. FIXME: Do not rely on glibc |
23 |
internals. */ |
24 |
#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN |
25 |
# define _IO_IN_BACKUP 0x100 |
26 |
#endif |
21 |
|
27 |
|
22 |
/* BSD stdio derived implementations. */ |
28 |
/* BSD stdio derived implementations. */ |
23 |
|
29 |
|
Lines 29-38
Link Here
|
29 |
#include <errno.h> /* For detecting Plan9. */ |
35 |
#include <errno.h> /* For detecting Plan9. */ |
30 |
|
36 |
|
31 |
#if defined __sferror || defined __DragonFly__ || defined __ANDROID__ |
37 |
#if defined __sferror || defined __DragonFly__ || defined __ANDROID__ |
32 |
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Android */ |
38 |
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */ |
33 |
|
39 |
|
34 |
# if defined __DragonFly__ /* DragonFly */ |
40 |
# if defined __DragonFly__ /* DragonFly */ |
35 |
/* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */ |
41 |
/* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/lib/libc/stdio/priv_stdio.h>. */ |
36 |
# define fp_ ((struct { struct __FILE_public pub; \ |
42 |
# define fp_ ((struct { struct __FILE_public pub; \ |
37 |
struct { unsigned char *_base; int _size; } _bf; \ |
43 |
struct { unsigned char *_base; int _size; } _bf; \ |
38 |
void *cookie; \ |
44 |
void *cookie; \ |
Lines 49-78
Link Here
|
49 |
fpos_t _offset; \ |
55 |
fpos_t _offset; \ |
50 |
/* More fields, not relevant here. */ \ |
56 |
/* More fields, not relevant here. */ \ |
51 |
} *) fp) |
57 |
} *) fp) |
52 |
/* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */ |
58 |
/* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/include/stdio.h>. */ |
53 |
# define _p pub._p |
59 |
# define _p pub._p |
54 |
# define _flags pub._flags |
60 |
# define _flags pub._flags |
55 |
# define _r pub._r |
61 |
# define _r pub._r |
56 |
# define _w pub._w |
62 |
# define _w pub._w |
|
|
63 |
# elif defined __ANDROID__ /* Android */ |
64 |
/* Up to this commit from 2015-10-12 |
65 |
<https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a> |
66 |
the innards of FILE were public, and fp_ub could be defined like for OpenBSD, |
67 |
see <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h> |
68 |
and <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h>. |
69 |
After this commit, the innards of FILE are hidden. */ |
70 |
# define fp_ ((struct { unsigned char *_p; \ |
71 |
int _r; \ |
72 |
int _w; \ |
73 |
int _flags; \ |
74 |
int _file; \ |
75 |
struct { unsigned char *_base; size_t _size; } _bf; \ |
76 |
int _lbfsize; \ |
77 |
void *_cookie; \ |
78 |
void *_close; \ |
79 |
void *_read; \ |
80 |
void *_seek; \ |
81 |
void *_write; \ |
82 |
struct { unsigned char *_base; size_t _size; } _ext; \ |
83 |
unsigned char *_up; \ |
84 |
int _ur; \ |
85 |
unsigned char _ubuf[3]; \ |
86 |
unsigned char _nbuf[1]; \ |
87 |
struct { unsigned char *_base; size_t _size; } _lb; \ |
88 |
int _blksize; \ |
89 |
fpos_t _offset; \ |
90 |
/* More fields, not relevant here. */ \ |
91 |
} *) fp) |
57 |
# else |
92 |
# else |
58 |
# define fp_ fp |
93 |
# define fp_ fp |
59 |
# endif |
94 |
# endif |
60 |
|
95 |
|
61 |
# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */ |
96 |
# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix /* NetBSD >= 1.5ZA, OpenBSD, Minix 3 */ |
62 |
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> |
97 |
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> |
63 |
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */ |
98 |
and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> |
|
|
99 |
and <https://github.com/Stichting-MINIX-Research-Foundation/minix/blob/master/lib/libc/stdio/fileext.h> */ |
64 |
struct __sfileext |
100 |
struct __sfileext |
65 |
{ |
101 |
{ |
66 |
struct __sbuf _ub; /* ungetc buffer */ |
102 |
struct __sbuf _ub; /* ungetc buffer */ |
67 |
/* More fields, not relevant here. */ |
103 |
/* More fields, not relevant here. */ |
68 |
}; |
104 |
}; |
69 |
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub |
105 |
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub |
70 |
# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin, Android */ |
106 |
# elif defined __ANDROID__ /* Android */ |
|
|
107 |
struct __sfileext |
108 |
{ |
109 |
struct { unsigned char *_base; size_t _size; } _ub; /* ungetc buffer */ |
110 |
/* More fields, not relevant here. */ |
111 |
}; |
112 |
# define fp_ub ((struct __sfileext *) fp_->_ext._base)->_ub |
113 |
# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */ |
71 |
# define fp_ub fp_->_ub |
114 |
# define fp_ub fp_->_ub |
72 |
# endif |
115 |
# endif |
73 |
|
116 |
|
74 |
# define HASUB(fp) (fp_ub._base != NULL) |
117 |
# define HASUB(fp) (fp_ub._base != NULL) |
75 |
|
118 |
|
|
|
119 |
# if defined __ANDROID__ /* Android */ |
120 |
/* Needed after this commit from 2016-01-25 |
121 |
<https://android.googlesource.com/platform/bionic.git/+/e70e0e9267d069bf56a5078c99307e08a7280de7> */ |
122 |
# ifndef __SEOF |
123 |
# define __SLBF 1 |
124 |
# define __SNBF 2 |
125 |
# define __SRD 4 |
126 |
# define __SWR 8 |
127 |
# define __SRW 0x10 |
128 |
# define __SEOF 0x20 |
129 |
# define __SERR 0x40 |
130 |
# endif |
131 |
# ifndef __SOFF |
132 |
# define __SOFF 0x1000 |
133 |
# endif |
134 |
# endif |
135 |
|
76 |
#endif |
136 |
#endif |
77 |
|
137 |
|
78 |
|
138 |
|
Lines 81-87
Link Here
|
81 |
#ifdef __TANDEM /* NonStop Kernel */ |
141 |
#ifdef __TANDEM /* NonStop Kernel */ |
82 |
# ifndef _IOERR |
142 |
# ifndef _IOERR |
83 |
/* These values were determined by the program 'stdioext-flags' at |
143 |
/* These values were determined by the program 'stdioext-flags' at |
84 |
<http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */ |
144 |
<https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */ |
85 |
# define _IOERR 0x40 |
145 |
# define _IOERR 0x40 |
86 |
# define _IOREAD 0x80 |
146 |
# define _IOREAD 0x80 |
87 |
# define _IOWRT 0x4 |
147 |
# define _IOWRT 0x4 |
Lines 99-104
Link Here
|
99 |
int _file; \ |
159 |
int _file; \ |
100 |
unsigned int _flag; \ |
160 |
unsigned int _flag; \ |
101 |
} *) fp) |
161 |
} *) fp) |
|
|
162 |
# elif defined __VMS /* OpenVMS */ |
163 |
# define fp_ ((struct _iobuf *) fp) |
102 |
# else |
164 |
# else |
103 |
# define fp_ fp |
165 |
# define fp_ fp |
104 |
# endif |
166 |
# endif |
Lines 110-113
Link Here
|
110 |
# define _flag __flag |
172 |
# define _flag __flag |
111 |
# endif |
173 |
# endif |
112 |
|
174 |
|
|
|
175 |
#elif defined _WIN32 && ! defined __CYGWIN__ /* newer Windows with MSVC */ |
176 |
|
177 |
/* <stdio.h> does not define the innards of FILE any more. */ |
178 |
# define WINDOWS_OPAQUE_FILE |
179 |
|
180 |
struct _gl_real_FILE |
181 |
{ |
182 |
/* Note: Compared to older Windows and to mingw, it has the fields |
183 |
_base and _cnt swapped. */ |
184 |
unsigned char *_ptr; |
185 |
unsigned char *_base; |
186 |
int _cnt; |
187 |
int _flag; |
188 |
int _file; |
189 |
int _charbuf; |
190 |
int _bufsiz; |
191 |
}; |
192 |
# define fp_ ((struct _gl_real_FILE *) fp) |
193 |
|
194 |
/* These values were determined by a program similar to the one at |
195 |
<https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */ |
196 |
# define _IOREAD 0x1 |
197 |
# define _IOWRT 0x2 |
198 |
# define _IORW 0x4 |
199 |
# define _IOEOF 0x8 |
200 |
# define _IOERR 0x10 |
201 |
|
113 |
#endif |
202 |
#endif |