Allow 'browse-url-emacs' to fetch URL in the selected window
[emacs.git] / lib / stdio-impl.h
blob05c5752a24367b92408d768a01e4d0a887e5f2a5
1 /* Implementation details of FILE streams.
2 Copyright (C) 2007-2008, 2010-2018 Free Software Foundation, Inc.
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
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Many stdio implementations have the same logic and therefore can share
18 the same implementation of stdio extension API, except that some fields
19 have different naming conventions, or their access requires some casts. */
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
28 /* BSD stdio derived implementations. */
30 #if defined __NetBSD__ /* NetBSD */
31 /* Get __NetBSD_Version__. */
32 # include <sys/param.h>
33 #endif
35 #include <errno.h> /* For detecting Plan9. */
37 #if defined __sferror || defined __DragonFly__ || defined __ANDROID__
38 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
40 # if defined __DragonFly__ /* DragonFly */
41 /* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/lib/libc/stdio/priv_stdio.h>. */
42 # define fp_ ((struct { struct __FILE_public pub; \
43 struct { unsigned char *_base; int _size; } _bf; \
44 void *cookie; \
45 void *_close; \
46 void *_read; \
47 void *_seek; \
48 void *_write; \
49 struct { unsigned char *_base; int _size; } _ub; \
50 int _ur; \
51 unsigned char _ubuf[3]; \
52 unsigned char _nbuf[1]; \
53 struct { unsigned char *_base; int _size; } _lb; \
54 int _blksize; \
55 fpos_t _offset; \
56 /* More fields, not relevant here. */ \
57 } *) fp)
58 /* See <https://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/include/stdio.h>. */
59 # define _p pub._p
60 # define _flags pub._flags
61 # define _r pub._r
62 # define _w pub._w
63 # else
64 # define fp_ fp
65 # endif
67 # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Minix 3, Android */
68 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
69 and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
70 struct __sfileext
72 struct __sbuf _ub; /* ungetc buffer */
73 /* More fields, not relevant here. */
75 # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
76 # else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin, Android */
77 # define fp_ub fp_->_ub
78 # endif
80 # define HASUB(fp) (fp_ub._base != NULL)
82 #endif
85 /* SystemV derived implementations. */
87 #ifdef __TANDEM /* NonStop Kernel */
88 # ifndef _IOERR
89 /* These values were determined by the program 'stdioext-flags' at
90 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
91 # define _IOERR 0x40
92 # define _IOREAD 0x80
93 # define _IOWRT 0x4
94 # define _IORW 0x100
95 # endif
96 #endif
98 #if defined _IOERR
100 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
101 # define fp_ ((struct { unsigned char *_ptr; \
102 unsigned char *_base; \
103 unsigned char *_end; \
104 long _cnt; \
105 int _file; \
106 unsigned int _flag; \
107 } *) fp)
108 # elif defined __VMS /* OpenVMS */
109 # define fp_ ((struct _iobuf *) fp)
110 # else
111 # define fp_ fp
112 # endif
114 # if defined _SCO_DS /* OpenServer */
115 # define _cnt __cnt
116 # define _ptr __ptr
117 # define _base __base
118 # define _flag __flag
119 # endif
121 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* newer Windows with MSVC */
123 /* <stdio.h> does not define the innards of FILE any more. */
124 # define WINDOWS_OPAQUE_FILE
126 struct _gl_real_FILE
128 /* Note: Compared to older Windows and to mingw, it has the fields
129 _base and _cnt swapped. */
130 unsigned char *_ptr;
131 unsigned char *_base;
132 int _cnt;
133 int _flag;
134 int _file;
135 int _charbuf;
136 int _bufsiz;
138 # define fp_ ((struct _gl_real_FILE *) fp)
140 /* These values were determined by a program similar to the one at
141 <https://lists.gnu.org/r/bug-gnulib/2010-12/msg00165.html>. */
142 # define _IOREAD 0x1
143 # define _IOWRT 0x2
144 # define _IORW 0x4
145 # define _IOEOF 0x8
146 # define _IOERR 0x10
148 #endif