libioP.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. /* Copyright (C) 1993-2026 Free Software Foundation, Inc.
  2. Copyright The GNU Toolchain Authors.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>.
  15. As a special exception, if you link the code in this file with
  16. files compiled with a GNU compiler to produce an executable,
  17. that does not cause the resulting executable to be covered by
  18. the GNU Lesser General Public License. This exception does not
  19. however invalidate any other reasons why the executable file
  20. might be covered by the GNU Lesser General Public License.
  21. This exception applies to code released by its copyright holders
  22. in files containing the exception. */
  23. /* NOTE: libio is now exclusively used only by glibc since libstdc++ has its
  24. own implementation. As a result, functions that were implemented for C++
  25. (like *sputn) may no longer have C++ semantics. This is of course only
  26. relevant for internal callers of these functions since these functions are
  27. not intended for external use otherwise.
  28. FIXME: All of the C++ cruft eventually needs to go away. */
  29. #ifndef _LIBIOP_H
  30. #define _LIBIOP_H 1
  31. #include <stddef.h>
  32. #include <errno.h>
  33. #include <libc-lock.h>
  34. #include <math_ldbl_opt.h>
  35. #include <stdio.h>
  36. #include <libio/libio.h>
  37. #include "iolibio.h"
  38. #include <shlib-compat.h>
  39. #include <pointer_guard.h>
  40. /* For historical reasons this is the name of the sysdeps header that
  41. adjusts the libio configuration. */
  42. #include <_G_config.h>
  43. #define _IO_seek_set 0
  44. #define _IO_seek_cur 1
  45. #define _IO_seek_end 2
  46. /* THE JUMPTABLE FUNCTIONS.
  47. * The _IO_FILE type is used to implement the FILE type in GNU libc,
  48. * as well as the streambuf class in GNU iostreams for C++.
  49. * These are all the same, just used differently.
  50. * An _IO_FILE (or FILE) object is allows followed by a pointer to
  51. * a jump table (of pointers to functions). The pointer is accessed
  52. * with the _IO_JUMPS macro. The jump table has an eccentric format,
  53. * so as to be compatible with the layout of a C++ virtual function table.
  54. * (as implemented by g++). When a pointer to a streambuf object is
  55. * coerced to an (FILE*), then _IO_JUMPS on the result just
  56. * happens to point to the virtual function table of the streambuf.
  57. * Thus the _IO_JUMPS function table used for C stdio/libio does
  58. * double duty as the virtual function table for C++ streambuf.
  59. *
  60. * The entries in the _IO_JUMPS function table (and hence also the
  61. * virtual functions of a streambuf) are described below.
  62. * The first parameter of each function entry is the _IO_FILE/streambuf
  63. * object being acted on (i.e. the 'this' parameter).
  64. */
  65. /* Setting this macro to 1 enables the use of the _vtable_offset bias
  66. in _IO_JUMPS_FUNCS, below. This is only needed for new-format
  67. _IO_FILE in libc that must support old binaries (see oldfileops.c). */
  68. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1) && !defined _IO_USE_OLD_IO_FILE
  69. # define _IO_JUMPS_OFFSET 1
  70. #else
  71. # define _IO_JUMPS_OFFSET 0
  72. #endif
  73. /* Type of MEMBER in struct type TYPE. */
  74. #define _IO_MEMBER_TYPE(TYPE, MEMBER) __typeof__ (((TYPE){}).MEMBER)
  75. /* Essentially ((TYPE *) THIS)->MEMBER, but avoiding the aliasing
  76. violation in case THIS has a different pointer type. */
  77. #define _IO_CAST_FIELD_ACCESS(THIS, TYPE, MEMBER) \
  78. (*(_IO_MEMBER_TYPE (TYPE, MEMBER) *)(((char *) (THIS)) \
  79. + offsetof(TYPE, MEMBER)))
  80. #define _IO_JUMPS(THIS) (THIS)->vtable
  81. #define _IO_JUMPS_FILE_plus(THIS) \
  82. _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE_plus, vtable)
  83. #define _IO_WIDE_JUMPS(THIS) \
  84. _IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data)->_wide_vtable
  85. #define _IO_CHECK_WIDE(THIS) \
  86. (_IO_CAST_FIELD_ACCESS ((THIS), struct _IO_FILE, _wide_data) != NULL)
  87. #if _IO_JUMPS_OFFSET
  88. # define _IO_JUMPS_FUNC(THIS) \
  89. (IO_validate_vtable \
  90. (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
  91. + (THIS)->_vtable_offset)))
  92. # define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \
  93. (*(const struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
  94. + (THIS)->_vtable_offset) = (VTABLE))
  95. # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset
  96. #else
  97. # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS)))
  98. # define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \
  99. (_IO_JUMPS_FILE_plus (THIS) = (VTABLE))
  100. # define _IO_vtable_offset(THIS) 0
  101. #endif
  102. #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)
  103. #define JUMP_FIELD(TYPE, NAME) TYPE NAME
  104. #define JUMP0(FUNC, THIS) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS)
  105. #define JUMP1(FUNC, THIS, X1) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
  106. #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
  107. #define JUMP3(FUNC, THIS, X1,X2,X3) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
  108. #define JUMP_INIT(NAME, VALUE) VALUE
  109. #define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0)
  110. #define WJUMP0(FUNC, THIS) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS)
  111. #define WJUMP1(FUNC, THIS, X1) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1)
  112. #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)
  113. #define WJUMP3(FUNC, THIS, X1,X2,X3) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1,X2, X3)
  114. /* The 'finish' function does any final cleaning up of an _IO_FILE object.
  115. It does not delete (free) it, but does everything else to finalize it.
  116. It matches the streambuf::~streambuf virtual destructor. */
  117. typedef void (*_IO_finish_t) (FILE *, int); /* finalize */
  118. #define _IO_FINISH(FP) JUMP1 (__finish, FP, 0)
  119. #define _IO_WFINISH(FP) WJUMP1 (__finish, FP, 0)
  120. /* The 'overflow' hook flushes the buffer.
  121. The second argument is a character, or EOF.
  122. It matches the streambuf::overflow virtual function. */
  123. typedef int (*_IO_overflow_t) (FILE *, int);
  124. #define _IO_OVERFLOW(FP, CH) JUMP1 (__overflow, FP, CH)
  125. #define _IO_WOVERFLOW(FP, CH) WJUMP1 (__overflow, FP, CH)
  126. /* The 'underflow' hook tries to fills the get buffer.
  127. It returns the next character (as an unsigned char) or EOF. The next
  128. character remains in the get buffer, and the get position is not changed.
  129. It matches the streambuf::underflow virtual function. */
  130. typedef int (*_IO_underflow_t) (FILE *);
  131. #define _IO_UNDERFLOW(FP) JUMP0 (__underflow, FP)
  132. #define _IO_WUNDERFLOW(FP) WJUMP0 (__underflow, FP)
  133. /* The 'uflow' hook returns the next character in the input stream
  134. (cast to unsigned char), and increments the read position;
  135. EOF is returned on failure.
  136. It matches the streambuf::uflow virtual function, which is not in the
  137. cfront implementation, but was added to C++ by the ANSI/ISO committee. */
  138. #define _IO_UFLOW(FP) JUMP0 (__uflow, FP)
  139. #define _IO_WUFLOW(FP) WJUMP0 (__uflow, FP)
  140. /* The 'pbackfail' hook handles backing up.
  141. It matches the streambuf::pbackfail virtual function. */
  142. typedef int (*_IO_pbackfail_t) (FILE *, int);
  143. #define _IO_PBACKFAIL(FP, CH) JUMP1 (__pbackfail, FP, CH)
  144. #define _IO_WPBACKFAIL(FP, CH) WJUMP1 (__pbackfail, FP, CH)
  145. /* The 'xsputn' hook writes upto N characters from buffer DATA.
  146. Returns EOF or the number of character actually written.
  147. It matches the streambuf::xsputn virtual function. */
  148. typedef size_t (*_IO_xsputn_t) (FILE *FP, const void *DATA,
  149. size_t N);
  150. #define _IO_XSPUTN(FP, DATA, N) JUMP2 (__xsputn, FP, DATA, N)
  151. #define _IO_WXSPUTN(FP, DATA, N) WJUMP2 (__xsputn, FP, DATA, N)
  152. /* The 'xsgetn' hook reads upto N characters into buffer DATA.
  153. Returns the number of character actually read.
  154. It matches the streambuf::xsgetn virtual function. */
  155. typedef size_t (*_IO_xsgetn_t) (FILE *FP, void *DATA, size_t N);
  156. #define _IO_XSGETN(FP, DATA, N) JUMP2 (__xsgetn, FP, DATA, N)
  157. #define _IO_WXSGETN(FP, DATA, N) WJUMP2 (__xsgetn, FP, DATA, N)
  158. /* The 'seekoff' hook moves the stream position to a new position
  159. relative to the start of the file (if DIR==0), the current position
  160. (MODE==1), or the end of the file (MODE==2).
  161. It matches the streambuf::seekoff virtual function.
  162. It is also used for the ANSI fseek function. */
  163. typedef off64_t (*_IO_seekoff_t) (FILE *FP, off64_t OFF, int DIR,
  164. int MODE);
  165. #define _IO_SEEKOFF(FP, OFF, DIR, MODE) JUMP3 (__seekoff, FP, OFF, DIR, MODE)
  166. #define _IO_WSEEKOFF(FP, OFF, DIR, MODE) WJUMP3 (__seekoff, FP, OFF, DIR, MODE)
  167. /* The 'seekpos' hook also moves the stream position,
  168. but to an absolute position given by a fpos64_t (seekpos).
  169. It matches the streambuf::seekpos virtual function.
  170. It is also used for the ANSI fgetpos and fsetpos functions. */
  171. /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
  172. typedef off64_t (*_IO_seekpos_t) (FILE *, off64_t, int);
  173. #define _IO_SEEKPOS(FP, POS, FLAGS) JUMP2 (__seekpos, FP, POS, FLAGS)
  174. #define _IO_WSEEKPOS(FP, POS, FLAGS) WJUMP2 (__seekpos, FP, POS, FLAGS)
  175. /* The 'setbuf' hook gives a buffer to the file.
  176. It matches the streambuf::setbuf virtual function. */
  177. typedef FILE* (*_IO_setbuf_t) (FILE *, char *, ssize_t);
  178. #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
  179. #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)
  180. /* The 'sync' hook attempts to synchronize the internal data structures
  181. of the file with the external state.
  182. It matches the streambuf::sync virtual function. */
  183. typedef int (*_IO_sync_t) (FILE *);
  184. #define _IO_SYNC(FP) JUMP0 (__sync, FP)
  185. #define _IO_WSYNC(FP) WJUMP0 (__sync, FP)
  186. /* The 'doallocate' hook is used to tell the file to allocate a buffer.
  187. It matches the streambuf::doallocate virtual function, which is not
  188. in the ANSI/ISO C++ standard, but is part traditional implementations. */
  189. typedef int (*_IO_doallocate_t) (FILE *);
  190. #define _IO_DOALLOCATE(FP) JUMP0 (__doallocate, FP)
  191. #define _IO_WDOALLOCATE(FP) WJUMP0 (__doallocate, FP)
  192. /* The following four hooks (sysread, syswrite, sysclose, sysseek, and
  193. sysstat) are low-level hooks specific to this implementation.
  194. There is no correspondence in the ANSI/ISO C++ standard library.
  195. The hooks basically correspond to the Unix system functions
  196. (read, write, close, lseek, and stat) except that a FILE*
  197. parameter is used instead of an integer file descriptor; the default
  198. implementation used for normal files just calls those functions.
  199. The advantage of overriding these functions instead of the higher-level
  200. ones (underflow, overflow etc) is that you can leave all the buffering
  201. higher-level functions. */
  202. /* The 'sysread' hook is used to read data from the external file into
  203. an existing buffer. It generalizes the Unix read(2) function.
  204. It matches the streambuf::sys_read virtual function, which is
  205. specific to this implementation. */
  206. typedef ssize_t (*_IO_read_t) (FILE *, void *, ssize_t);
  207. #define _IO_SYSREAD(FP, DATA, LEN) JUMP2 (__read, FP, DATA, LEN)
  208. #define _IO_WSYSREAD(FP, DATA, LEN) WJUMP2 (__read, FP, DATA, LEN)
  209. /* The 'syswrite' hook is used to write data from an existing buffer
  210. to an external file. It generalizes the Unix write(2) function.
  211. It matches the streambuf::sys_write virtual function, which is
  212. specific to this implementation. */
  213. typedef ssize_t (*_IO_write_t) (FILE *, const void *, ssize_t);
  214. #define _IO_SYSWRITE(FP, DATA, LEN) JUMP2 (__write, FP, DATA, LEN)
  215. #define _IO_WSYSWRITE(FP, DATA, LEN) WJUMP2 (__write, FP, DATA, LEN)
  216. /* The 'sysseek' hook is used to re-position an external file.
  217. It generalizes the Unix lseek(2) function.
  218. It matches the streambuf::sys_seek virtual function, which is
  219. specific to this implementation. */
  220. typedef off64_t (*_IO_seek_t) (FILE *, off64_t, int);
  221. #define _IO_SYSSEEK(FP, OFFSET, MODE) JUMP2 (__seek, FP, OFFSET, MODE)
  222. #define _IO_WSYSSEEK(FP, OFFSET, MODE) WJUMP2 (__seek, FP, OFFSET, MODE)
  223. /* The 'sysclose' hook is used to finalize (close, finish up) an
  224. external file. It generalizes the Unix close(2) function.
  225. It matches the streambuf::sys_close virtual function, which is
  226. specific to this implementation. */
  227. typedef int (*_IO_close_t) (FILE *); /* finalize */
  228. #define _IO_SYSCLOSE(FP) JUMP0 (__close, FP)
  229. #define _IO_WSYSCLOSE(FP) WJUMP0 (__close, FP)
  230. /* The 'sysstat' hook is used to get information about an external file
  231. into a struct stat buffer. It generalizes the Unix fstat(2) call.
  232. It matches the streambuf::sys_stat virtual function, which is
  233. specific to this implementation. */
  234. typedef int (*_IO_stat_t) (FILE *, void *);
  235. #define _IO_SYSSTAT(FP, BUF) JUMP1 (__stat, FP, BUF)
  236. #define _IO_WSYSSTAT(FP, BUF) WJUMP1 (__stat, FP, BUF)
  237. /* The 'showmany' hook can be used to get an image how much input is
  238. available. In many cases the answer will be 0 which means unknown
  239. but some cases one can provide real information. */
  240. typedef int (*_IO_showmanyc_t) (FILE *);
  241. #define _IO_SHOWMANYC(FP) JUMP0 (__showmanyc, FP)
  242. #define _IO_WSHOWMANYC(FP) WJUMP0 (__showmanyc, FP)
  243. /* The 'imbue' hook is used to get information about the currently
  244. installed locales. */
  245. typedef void (*_IO_imbue_t) (FILE *, void *);
  246. #define _IO_IMBUE(FP, LOCALE) JUMP1 (__imbue, FP, LOCALE)
  247. #define _IO_WIMBUE(FP, LOCALE) WJUMP1 (__imbue, FP, LOCALE)
  248. #define _IO_CHAR_TYPE char /* unsigned char ? */
  249. #define _IO_INT_TYPE int
  250. struct _IO_jump_t
  251. {
  252. JUMP_FIELD(size_t, __dummy);
  253. JUMP_FIELD(size_t, __dummy2);
  254. JUMP_FIELD(_IO_finish_t, __finish);
  255. JUMP_FIELD(_IO_overflow_t, __overflow);
  256. JUMP_FIELD(_IO_underflow_t, __underflow);
  257. JUMP_FIELD(_IO_underflow_t, __uflow);
  258. JUMP_FIELD(_IO_pbackfail_t, __pbackfail);
  259. /* showmany */
  260. JUMP_FIELD(_IO_xsputn_t, __xsputn);
  261. JUMP_FIELD(_IO_xsgetn_t, __xsgetn);
  262. JUMP_FIELD(_IO_seekoff_t, __seekoff);
  263. JUMP_FIELD(_IO_seekpos_t, __seekpos);
  264. JUMP_FIELD(_IO_setbuf_t, __setbuf);
  265. JUMP_FIELD(_IO_sync_t, __sync);
  266. JUMP_FIELD(_IO_doallocate_t, __doallocate);
  267. JUMP_FIELD(_IO_read_t, __read);
  268. JUMP_FIELD(_IO_write_t, __write);
  269. JUMP_FIELD(_IO_seek_t, __seek);
  270. JUMP_FIELD(_IO_close_t, __close);
  271. JUMP_FIELD(_IO_stat_t, __stat);
  272. JUMP_FIELD(_IO_showmanyc_t, __showmanyc);
  273. JUMP_FIELD(_IO_imbue_t, __imbue);
  274. };
  275. /* We always allocate an extra word following an _IO_FILE.
  276. This contains a pointer to the function jump table used.
  277. This is for compatibility with C++ streambuf; the word can
  278. be used to smash to a pointer to a virtual function table. */
  279. struct _IO_FILE_plus
  280. {
  281. FILE file;
  282. const struct _IO_jump_t *vtable;
  283. };
  284. #ifdef _IO_USE_OLD_IO_FILE
  285. /* This structure is used by the compatibility code as if it were an
  286. _IO_FILE_plus, but has enough space to initialize the _mode argument
  287. of an _IO_FILE_complete. */
  288. struct _IO_FILE_complete_plus
  289. {
  290. struct _IO_FILE_complete file;
  291. const struct _IO_jump_t *vtable;
  292. };
  293. #endif
  294. /* Special file type for fopencookie function. */
  295. struct _IO_cookie_file
  296. {
  297. struct _IO_FILE_plus __fp;
  298. void *__cookie;
  299. cookie_io_functions_t __io_functions;
  300. };
  301. FILE *_IO_fopencookie (void *cookie, const char *mode,
  302. cookie_io_functions_t io_functions);
  303. /* Iterator type for walking global linked list of _IO_FILE objects. */
  304. typedef FILE *_IO_ITER;
  305. /* Generic functions */
  306. extern void _IO_switch_to_main_get_area (FILE *) __THROW;
  307. extern void _IO_switch_to_backup_area (FILE *) __THROW;
  308. extern int _IO_switch_to_get_mode (FILE *);
  309. libc_hidden_proto (_IO_switch_to_get_mode)
  310. extern void _IO_init_internal (FILE *, int) attribute_hidden;
  311. extern int _IO_sputbackc (FILE *, int) __THROW;
  312. libc_hidden_proto (_IO_sputbackc)
  313. extern int _IO_sungetc (FILE *) __THROW;
  314. extern void _IO_un_link (struct _IO_FILE_plus *) __THROW;
  315. libc_hidden_proto (_IO_un_link)
  316. extern void _IO_link_in (struct _IO_FILE_plus *) __THROW;
  317. libc_hidden_proto (_IO_link_in)
  318. extern void _IO_doallocbuf (FILE *) __THROW;
  319. libc_hidden_proto (_IO_doallocbuf)
  320. extern void _IO_unsave_markers (FILE *) __THROW;
  321. libc_hidden_proto (_IO_unsave_markers)
  322. extern void _IO_setb (FILE *, char *, char *, int) __THROW;
  323. libc_hidden_proto (_IO_setb)
  324. extern unsigned _IO_adjust_column (unsigned, const char *, int) __THROW;
  325. libc_hidden_proto (_IO_adjust_column)
  326. #define _IO_sputn(__fp, __s, __n) _IO_XSPUTN (__fp, __s, __n)
  327. ssize_t _IO_least_wmarker (FILE *, wchar_t *) __THROW;
  328. libc_hidden_proto (_IO_least_wmarker)
  329. extern void _IO_switch_to_main_wget_area (FILE *) __THROW;
  330. libc_hidden_proto (_IO_switch_to_main_wget_area)
  331. extern void _IO_switch_to_wbackup_area (FILE *) __THROW;
  332. libc_hidden_proto (_IO_switch_to_wbackup_area)
  333. extern int _IO_switch_to_wget_mode (FILE *);
  334. libc_hidden_proto (_IO_switch_to_wget_mode)
  335. extern void _IO_wsetb (FILE *, wchar_t *, wchar_t *, int) __THROW;
  336. libc_hidden_proto (_IO_wsetb)
  337. extern wint_t _IO_sputbackwc (FILE *, wint_t) __THROW;
  338. libc_hidden_proto (_IO_sputbackwc)
  339. extern wint_t _IO_sungetwc (FILE *) __THROW;
  340. extern void _IO_wdoallocbuf (FILE *) __THROW;
  341. libc_hidden_proto (_IO_wdoallocbuf)
  342. extern void _IO_unsave_wmarkers (FILE *) __THROW;
  343. extern unsigned _IO_adjust_wcolumn (unsigned, const wchar_t *, int) __THROW;
  344. extern off64_t get_file_offset (FILE *fp);
  345. /* Marker-related function. */
  346. extern void _IO_init_marker (struct _IO_marker *, FILE *);
  347. extern void _IO_init_wmarker (struct _IO_marker *, FILE *);
  348. extern void _IO_remove_marker (struct _IO_marker *) __THROW;
  349. extern int _IO_marker_difference (struct _IO_marker *, struct _IO_marker *)
  350. __THROW;
  351. extern int _IO_marker_delta (struct _IO_marker *) __THROW;
  352. extern int _IO_wmarker_delta (struct _IO_marker *) __THROW;
  353. extern int _IO_seekmark (FILE *, struct _IO_marker *, int) __THROW;
  354. extern int _IO_seekwmark (FILE *, struct _IO_marker *, int) __THROW;
  355. /* Functions for iterating global list and dealing with its lock */
  356. extern _IO_ITER _IO_iter_begin (void) __THROW;
  357. libc_hidden_proto (_IO_iter_begin)
  358. extern _IO_ITER _IO_iter_end (void) __THROW;
  359. libc_hidden_proto (_IO_iter_end)
  360. extern _IO_ITER _IO_iter_next (_IO_ITER) __THROW;
  361. libc_hidden_proto (_IO_iter_next)
  362. extern FILE *_IO_iter_file (_IO_ITER) __THROW;
  363. libc_hidden_proto (_IO_iter_file)
  364. extern void _IO_list_lock (void) __THROW;
  365. libc_hidden_proto (_IO_list_lock)
  366. extern void _IO_list_unlock (void) __THROW;
  367. libc_hidden_proto (_IO_list_unlock)
  368. extern void _IO_list_resetlock (void) __THROW;
  369. libc_hidden_proto (_IO_list_resetlock)
  370. extern void _IO_enable_locks (void) __THROW;
  371. libc_hidden_proto (_IO_enable_locks)
  372. /* Functions for operating popen's proc_file_chain_lock during fork. */
  373. extern void _IO_proc_file_chain_lock (void) __THROW attribute_hidden;
  374. extern void _IO_proc_file_chain_unlock (void) __THROW attribute_hidden;
  375. extern void _IO_proc_file_chain_resetlock (void) __THROW attribute_hidden;
  376. /* Default jumptable functions. */
  377. extern int _IO_default_underflow (FILE *) __THROW;
  378. extern int _IO_default_uflow (FILE *);
  379. libc_hidden_proto (_IO_default_uflow)
  380. extern wint_t _IO_wdefault_uflow (FILE *);
  381. libc_hidden_proto (_IO_wdefault_uflow)
  382. extern int _IO_default_doallocate (FILE *) __THROW;
  383. libc_hidden_proto (_IO_default_doallocate)
  384. extern int _IO_wdefault_doallocate (FILE *) __THROW;
  385. libc_hidden_proto (_IO_wdefault_doallocate)
  386. extern void _IO_default_finish (FILE *, int) __THROW;
  387. libc_hidden_proto (_IO_default_finish)
  388. extern void _IO_wdefault_finish (FILE *, int) __THROW;
  389. libc_hidden_proto (_IO_wdefault_finish)
  390. extern int _IO_default_pbackfail (FILE *, int) __THROW;
  391. libc_hidden_proto (_IO_default_pbackfail)
  392. extern wint_t _IO_wdefault_pbackfail (FILE *, wint_t) __THROW;
  393. libc_hidden_proto (_IO_wdefault_pbackfail)
  394. extern FILE* _IO_default_setbuf (FILE *, char *, ssize_t);
  395. extern size_t _IO_default_xsputn (FILE *, const void *, size_t);
  396. libc_hidden_proto (_IO_default_xsputn)
  397. extern size_t _IO_wdefault_xsputn (FILE *, const void *, size_t);
  398. libc_hidden_proto (_IO_wdefault_xsputn)
  399. extern size_t _IO_default_xsgetn (FILE *, void *, size_t);
  400. libc_hidden_proto (_IO_default_xsgetn)
  401. extern size_t _IO_wdefault_xsgetn (FILE *, void *, size_t);
  402. libc_hidden_proto (_IO_wdefault_xsgetn)
  403. extern off64_t _IO_default_seekoff (FILE *, off64_t, int, int)
  404. __THROW;
  405. extern off64_t _IO_default_seekpos (FILE *, off64_t, int);
  406. extern ssize_t _IO_default_write (FILE *, const void *, ssize_t);
  407. extern ssize_t _IO_default_read (FILE *, void *, ssize_t);
  408. extern int _IO_default_stat (FILE *, void *) __THROW;
  409. extern off64_t _IO_default_seek (FILE *, off64_t, int) __THROW;
  410. extern int _IO_default_sync (FILE *) __THROW;
  411. #define _IO_default_close ((_IO_close_t) _IO_default_sync)
  412. extern int _IO_default_showmanyc (FILE *) __THROW;
  413. extern void _IO_default_imbue (FILE *, void *) __THROW;
  414. extern int __printf_buffer_as_file_overflow (FILE *fp, int ch);
  415. extern size_t __printf_buffer_as_file_xsputn (FILE *fp, const void *buf,
  416. size_t len);
  417. extern wint_t __wprintf_buffer_as_file_overflow (FILE *fp, int ch);
  418. extern size_t __wprintf_buffer_as_file_xsputn (FILE *fp, const void *buf,
  419. size_t len);
  420. enum
  421. {
  422. IO_STR_JUMPS = 0,
  423. IO_WSTR_JUMPS = 1,
  424. IO_FILE_JUMPS = 2,
  425. IO_FILE_JUMPS_MMAP = 3,
  426. IO_FILE_JUMPS_MAYBE_MMAP = 4,
  427. IO_WFILE_JUMPS = 5,
  428. IO_WFILE_JUMPS_MMAP = 6,
  429. IO_WFILE_JUMPS_MAYBE_MMAP = 7,
  430. IO_COOKIE_JUMPS = 8,
  431. IO_PROC_JUMPS = 9,
  432. IO_MEM_JUMPS = 10,
  433. IO_WMEM_JUMPS = 11,
  434. IO_PRINTF_BUFFER_AS_FILE_JUMPS = 12,
  435. IO_WPRINTF_BUFFER_AS_FILE_JUMPS = 13,
  436. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  437. IO_OLD_FILE_JUMPS = 14,
  438. IO_OLD_PROC_JUMPS = 15,
  439. IO_OLD_COOKIED_JUMPS = 16,
  440. IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1,
  441. #elif SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
  442. IO_OLD_COOKIED_JUMPS = 14,
  443. IO_VTABLES_NUM = IO_OLD_COOKIED_JUMPS + 1,
  444. #else
  445. IO_VTABLES_NUM = IO_WPRINTF_BUFFER_AS_FILE_JUMPS + 1
  446. #endif
  447. };
  448. #define IO_VTABLES_LEN (IO_VTABLES_NUM * sizeof (struct _IO_jump_t))
  449. extern const struct _IO_jump_t __io_vtables[] attribute_hidden;
  450. #define _IO_str_jumps (__io_vtables[IO_STR_JUMPS])
  451. #define _IO_wstr_jumps (__io_vtables[IO_WSTR_JUMPS])
  452. #define _IO_file_jumps (__io_vtables[IO_FILE_JUMPS])
  453. #define _IO_file_jumps_mmap (__io_vtables[IO_FILE_JUMPS_MMAP])
  454. #define _IO_file_jumps_maybe_mmap (__io_vtables[IO_FILE_JUMPS_MAYBE_MMAP])
  455. #define _IO_wfile_jumps (__io_vtables[IO_WFILE_JUMPS])
  456. #define _IO_wfile_jumps_mmap (__io_vtables[IO_WFILE_JUMPS_MMAP])
  457. #define _IO_wfile_jumps_maybe_mmap (__io_vtables[IO_WFILE_JUMPS_MAYBE_MMAP])
  458. #define _IO_cookie_jumps (__io_vtables[IO_COOKIE_JUMPS])
  459. #define _IO_proc_jumps (__io_vtables[IO_PROC_JUMPS])
  460. #define _IO_mem_jumps (__io_vtables[IO_MEM_JUMPS])
  461. #define _IO_wmem_jumps (__io_vtables[IO_WMEM_JUMPS])
  462. #define _IO_printf_buffer_as_file_jumps (__io_vtables[IO_PRINTF_BUFFER_AS_FILE_JUMPS])
  463. #define _IO_wprintf_buffer_as_file_jumps (__io_vtables[IO_WPRINTF_BUFFER_AS_FILE_JUMPS])
  464. #define _IO_old_file_jumps (__io_vtables[IO_OLD_FILE_JUMPS])
  465. #define _IO_old_proc_jumps (__io_vtables[IO_OLD_PROC_JUMPS])
  466. #define _IO_old_cookie_jumps (__io_vtables[IO_OLD_COOKIED_JUMPS])
  467. #ifdef SHARED
  468. # define libio_static_fn_required(name)
  469. #else
  470. # define libio_static_fn_required(name) \
  471. static __typeof (name) *const name##_p __attribute__((used)) = name;
  472. #endif
  473. extern int _IO_do_write (FILE *, const char *, size_t);
  474. libc_hidden_proto (_IO_do_write)
  475. extern int _IO_new_do_write (FILE *, const char *, size_t);
  476. extern int _IO_old_do_write (FILE *, const char *, size_t);
  477. extern int _IO_wdo_write (FILE *, const wchar_t *, size_t);
  478. libc_hidden_proto (_IO_wdo_write)
  479. extern int _IO_flush_all (void);
  480. libc_hidden_proto (_IO_flush_all)
  481. extern void _IO_flush_all_linebuffered (void);
  482. libc_hidden_proto (_IO_flush_all_linebuffered)
  483. extern int _IO_new_fgetpos (FILE *, __fpos_t *);
  484. extern int _IO_old_fgetpos (FILE *, __fpos_t *);
  485. extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
  486. extern int _IO_old_fsetpos (FILE *, const __fpos_t *);
  487. extern int _IO_new_fgetpos64 (FILE *, __fpos64_t *);
  488. extern int _IO_old_fgetpos64 (FILE *, __fpos64_t *);
  489. extern int _IO_new_fsetpos64 (FILE *, const __fpos64_t *);
  490. extern int _IO_old_fsetpos64 (FILE *, const __fpos64_t *);
  491. extern void _IO_old_init (FILE *fp, int flags) __THROW;
  492. #define _IO_do_flush(_f) \
  493. ((_f)->_mode <= 0 \
  494. ? _IO_do_write(_f, (_f)->_IO_write_base, \
  495. (_f)->_IO_write_ptr-(_f)->_IO_write_base) \
  496. : _IO_wdo_write(_f, (_f)->_wide_data->_IO_write_base, \
  497. ((_f)->_wide_data->_IO_write_ptr \
  498. - (_f)->_wide_data->_IO_write_base)))
  499. #define _IO_old_do_flush(_f) \
  500. _IO_old_do_write(_f, (_f)->_IO_write_base, \
  501. (_f)->_IO_write_ptr-(_f)->_IO_write_base)
  502. #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
  503. #define _IO_mask_flags(fp, f, mask) \
  504. ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
  505. #define _IO_setg(fp, eb, g, eg) ((fp)->_IO_read_base = (eb),\
  506. (fp)->_IO_read_ptr = (g), (fp)->_IO_read_end = (eg))
  507. #define _IO_wsetg(fp, eb, g, eg) ((fp)->_wide_data->_IO_read_base = (eb),\
  508. (fp)->_wide_data->_IO_read_ptr = (g), \
  509. (fp)->_wide_data->_IO_read_end = (eg))
  510. #define _IO_setp(__fp, __p, __ep) \
  511. ((__fp)->_IO_write_base = (__fp)->_IO_write_ptr \
  512. = __p, (__fp)->_IO_write_end = (__ep))
  513. #define _IO_wsetp(__fp, __p, __ep) \
  514. ((__fp)->_wide_data->_IO_write_base \
  515. = (__fp)->_wide_data->_IO_write_ptr = __p, \
  516. (__fp)->_wide_data->_IO_write_end = (__ep))
  517. #define _IO_have_backup(fp) ((fp)->_IO_backup_base != NULL)
  518. #define _IO_have_wbackup(fp) ((fp)->_wide_data->_IO_backup_base != NULL)
  519. #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
  520. #define _IO_have_markers(fp) ((fp)->_markers != NULL)
  521. #define _IO_blen(fp) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
  522. #define _IO_wblen(fp) ((fp)->_wide_data->_IO_buf_end \
  523. - (fp)->_wide_data->_IO_buf_base)
  524. /* Jumptable functions for files. */
  525. extern int _IO_file_doallocate (FILE *) __THROW;
  526. libc_hidden_proto (_IO_file_doallocate)
  527. extern FILE* _IO_file_setbuf (FILE *, char *, ssize_t);
  528. libc_hidden_proto (_IO_file_setbuf)
  529. extern off64_t _IO_file_seekoff (FILE *, off64_t, int, int);
  530. libc_hidden_proto (_IO_file_seekoff)
  531. extern off64_t _IO_file_seekoff_mmap (FILE *, off64_t, int, int)
  532. __THROW;
  533. extern size_t _IO_file_xsputn (FILE *, const void *, size_t);
  534. libc_hidden_proto (_IO_file_xsputn)
  535. extern size_t _IO_file_xsgetn (FILE *, void *, size_t);
  536. libc_hidden_proto (_IO_file_xsgetn)
  537. extern int _IO_file_stat (FILE *, void *) __THROW;
  538. libc_hidden_proto (_IO_file_stat)
  539. extern int _IO_file_close (FILE *) __THROW;
  540. libc_hidden_proto (_IO_file_close)
  541. extern int _IO_file_close_mmap (FILE *) __THROW;
  542. extern int _IO_file_underflow (FILE *);
  543. libc_hidden_proto (_IO_file_underflow)
  544. extern int _IO_file_underflow_mmap (FILE *);
  545. extern int _IO_file_underflow_maybe_mmap (FILE *);
  546. extern int _IO_file_overflow (FILE *, int);
  547. libc_hidden_proto (_IO_file_overflow)
  548. #define _IO_file_is_open(__fp) ((__fp)->_fileno != -1)
  549. extern FILE* _IO_file_attach (FILE *, int);
  550. libc_hidden_proto (_IO_file_attach)
  551. extern FILE* _IO_file_open (FILE *, const char *, int, int, int, int);
  552. libc_hidden_proto (_IO_file_open)
  553. extern FILE* _IO_file_fopen (FILE *, const char *, const char *, int);
  554. libc_hidden_proto (_IO_file_fopen)
  555. extern ssize_t _IO_file_write (FILE *, const void *, ssize_t);
  556. extern ssize_t _IO_file_read (FILE *, void *, ssize_t);
  557. libc_hidden_proto (_IO_file_read)
  558. extern int _IO_file_sync (FILE *);
  559. libc_hidden_proto (_IO_file_sync)
  560. extern int _IO_file_close_it (FILE *);
  561. libc_hidden_proto (_IO_file_close_it)
  562. extern off64_t _IO_file_seek (FILE *, off64_t, int) __THROW;
  563. libc_hidden_proto (_IO_file_seek)
  564. extern void _IO_file_finish (FILE *, int);
  565. libc_hidden_proto (_IO_file_finish)
  566. extern FILE* _IO_new_file_attach (FILE *, int);
  567. extern int _IO_new_file_close_it (FILE *);
  568. extern void _IO_new_file_finish (FILE *, int);
  569. extern FILE* _IO_new_file_fopen (FILE *, const char *, const char *,
  570. int);
  571. extern void _IO_no_init (FILE *, int, int, struct _IO_wide_data *,
  572. const struct _IO_jump_t *) __THROW;
  573. extern void _IO_new_file_init_internal (struct _IO_FILE_plus *)
  574. __THROW attribute_hidden;
  575. extern FILE* _IO_new_file_setbuf (FILE *, char *, ssize_t);
  576. extern FILE* _IO_file_setbuf_mmap (FILE *, char *, ssize_t);
  577. extern int _IO_new_file_sync (FILE *);
  578. extern int _IO_file_sync_mmap (FILE *) attribute_hidden;
  579. extern size_t _IO_file_xsgetn_maybe_mmap (FILE *fp, void *data, size_t n)
  580. attribute_hidden;
  581. extern size_t _IO_file_xsgetn_mmap (FILE *fp, void *data, size_t n)
  582. attribute_hidden;
  583. extern off64_t _IO_file_seekoff_maybe_mmap (FILE *fp, off64_t offset, int dir,
  584. int mode)
  585. attribute_hidden;
  586. extern int _IO_new_file_underflow (FILE *);
  587. extern int _IO_new_file_overflow (FILE *, int);
  588. extern off64_t _IO_new_file_seekoff (FILE *, off64_t, int, int);
  589. extern ssize_t _IO_new_file_write (FILE *, const void *, ssize_t);
  590. extern size_t _IO_new_file_xsputn (FILE *, const void *, size_t);
  591. extern FILE* _IO_old_file_setbuf (FILE *, char *, ssize_t);
  592. extern off64_t _IO_old_file_seekoff (FILE *, off64_t, int, int);
  593. extern size_t _IO_old_file_xsputn (FILE *, const void *, size_t);
  594. extern int _IO_old_file_underflow (FILE *);
  595. extern int _IO_old_file_overflow (FILE *, int);
  596. extern void _IO_old_file_init_internal (struct _IO_FILE_plus *)
  597. __THROW attribute_hidden;
  598. extern FILE* _IO_old_file_attach (FILE *, int);
  599. extern FILE* _IO_old_file_fopen (FILE *, const char *, const char *);
  600. extern ssize_t _IO_old_file_write (FILE *, const void *, ssize_t);
  601. extern int _IO_old_file_sync (FILE *);
  602. extern int _IO_old_file_close_it (FILE *);
  603. extern void _IO_old_file_finish (FILE *, int);
  604. extern int _IO_wfile_doallocate (FILE *) __THROW;
  605. extern size_t _IO_wfile_xsputn (FILE *, const void *, size_t);
  606. libc_hidden_proto (_IO_wfile_xsputn)
  607. extern FILE* _IO_wfile_setbuf (FILE *, wchar_t *, ssize_t);
  608. extern wint_t _IO_wfile_sync (FILE *);
  609. libc_hidden_proto (_IO_wfile_sync)
  610. extern wint_t _IO_wfile_underflow (FILE *);
  611. libc_hidden_proto (_IO_wfile_underflow)
  612. extern wint_t _IO_wfile_overflow (FILE *, wint_t);
  613. libc_hidden_proto (_IO_wfile_overflow)
  614. extern off64_t _IO_wfile_seekoff (FILE *, off64_t, int, int);
  615. libc_hidden_proto (_IO_wfile_seekoff)
  616. extern wint_t _IO_wfile_underflow_maybe_mmap (FILE *fp)
  617. attribute_hidden;
  618. extern wint_t _IO_wfile_underflow_mmap (FILE *fp)
  619. attribute_hidden;
  620. /* Jumptable functions for proc_files. */
  621. extern FILE* _IO_proc_open (FILE *, const char *, const char *)
  622. __THROW;
  623. extern FILE* _IO_new_proc_open (FILE *, const char *, const char *)
  624. __THROW;
  625. extern FILE* _IO_old_proc_open (FILE *, const char *, const char *);
  626. extern int _IO_proc_close (FILE *) __THROW;
  627. extern int _IO_new_proc_close (FILE *) __THROW;
  628. extern int _IO_old_proc_close (FILE *);
  629. /* Jumptable functions for strfiles. */
  630. extern int _IO_str_underflow (FILE *) __THROW;
  631. libc_hidden_proto (_IO_str_underflow)
  632. extern int _IO_str_overflow (FILE *, int) __THROW;
  633. libc_hidden_proto (_IO_str_overflow)
  634. extern int _IO_str_pbackfail (FILE *, int) __THROW;
  635. libc_hidden_proto (_IO_str_pbackfail)
  636. extern off64_t _IO_str_seekoff (FILE *, off64_t, int, int) __THROW
  637. ;
  638. libc_hidden_proto (_IO_str_seekoff)
  639. extern void _IO_str_finish (FILE *, int) __THROW;
  640. extern int _IO_str_chk_overflow (FILE *fp, int c) __THROW
  641. attribute_hidden;
  642. /* Jumptable functions for fopencookie. */
  643. extern ssize_t _IO_cookie_read (FILE *fp, void *buf, ssize_t size)
  644. attribute_hidden;
  645. extern ssize_t _IO_cookie_write (FILE *fp, const void *buf, ssize_t size)
  646. attribute_hidden;
  647. extern off64_t _IO_cookie_seek (FILE *fp, off64_t offset, int dir)
  648. attribute_hidden;
  649. extern int _IO_cookie_close (FILE *fp) attribute_hidden;
  650. extern off64_t _IO_cookie_seekoff (FILE *fp, off64_t offset, int dir, int mode)
  651. attribute_hidden;
  652. extern off64_t _IO_old_cookie_seek (FILE *fp, off64_t offset, int dir)
  653. attribute_hidden;
  654. /* Jumptable functions for obstack. */
  655. extern int __IO_obstack_overflow (FILE *fp, int c) attribute_hidden;
  656. extern size_t __IO_obstack_xsputn (FILE *fp, const void *data, size_t n)
  657. attribute_hidden;
  658. /* Jumptable functions for open_{w}memstream. */
  659. extern int _IO_mem_sync (FILE* fp) __THROW attribute_hidden;
  660. extern void _IO_mem_finish (FILE* fp, int) __THROW attribute_hidden;
  661. extern int _IO_wmem_sync (FILE* fp) __THROW attribute_hidden;
  662. extern void _IO_wmem_finish (FILE* fp, int) __THROW attribute_hidden;
  663. /* Other strfile functions */
  664. struct _IO_strfile_;
  665. extern ssize_t _IO_str_count (FILE *) __THROW;
  666. extern int _IO_strn_overflow (FILE *fp, int c) __THROW attribute_hidden;
  667. /* And the wide character versions. */
  668. extern void _IO_wstr_init_static (FILE *, wchar_t *, size_t, wchar_t *)
  669. __THROW;
  670. extern ssize_t _IO_wstr_count (FILE *) __THROW;
  671. extern wint_t _IO_wstr_overflow (FILE *, wint_t) __THROW;
  672. extern wint_t _IO_wstr_underflow (FILE *) __THROW;
  673. extern off64_t _IO_wstr_seekoff (FILE *, off64_t, int, int)
  674. __THROW;
  675. extern wint_t _IO_wstr_pbackfail (FILE *, wint_t) __THROW;
  676. extern void _IO_wstr_finish (FILE *, int) __THROW;
  677. /* Helper functions. */
  678. int _IO_helper_overflow (FILE *s, int c);
  679. int _IO_whelper_overflow (FILE *s, int c);
  680. /* Internal versions of v*printf that take an additional flags
  681. parameter. */
  682. extern int __vfprintf_internal (FILE *fp, const char *format, va_list ap,
  683. unsigned int mode_flags)
  684. attribute_hidden;
  685. extern int __vfwprintf_internal (FILE *fp, const wchar_t *format, va_list ap,
  686. unsigned int mode_flags)
  687. attribute_hidden;
  688. extern int __vasprintf_internal (char **result_ptr, const char *format,
  689. va_list ap, unsigned int mode_flags)
  690. attribute_hidden;
  691. extern int __vdprintf_internal (int d, const char *format, va_list ap,
  692. unsigned int mode_flags)
  693. attribute_hidden;
  694. extern int __obstack_vprintf_internal (struct obstack *ob, const char *fmt,
  695. va_list ap, unsigned int mode_flags)
  696. attribute_hidden;
  697. /* Note: __vsprintf_internal, unlike vsprintf, does take a maxlen argument,
  698. because it's called by both vsprintf and vsprintf_chk. If maxlen is
  699. not set to -1, overrunning the buffer will cause a prompt crash.
  700. This is the behavior of ordinary (v)sprintf functions, thus they call
  701. __vsprintf_internal with that argument set to -1. */
  702. extern int __vsprintf_internal (char *string, size_t maxlen,
  703. const char *format, va_list ap,
  704. unsigned int mode_flags)
  705. attribute_hidden;
  706. extern int __vsnprintf_internal (char *string, size_t maxlen,
  707. const char *format, va_list ap,
  708. unsigned int mode_flags)
  709. attribute_hidden;
  710. extern int __vswprintf_internal (wchar_t *string, size_t maxlen,
  711. const wchar_t *format, va_list ap,
  712. unsigned int mode_flags)
  713. attribute_hidden;
  714. /* Flags for __v*printf_internal.
  715. PRINTF_LDBL_IS_DBL indicates whether long double values are to be
  716. handled as having the same format as double, in which case the flag
  717. should be set to one, or as another format, otherwise.
  718. PRINTF_FORTIFY, when set to one, indicates that fortification checks
  719. are to be performed in input parameters. This is used by the
  720. __*printf_chk functions, which are used when _FORTIFY_SOURCE is
  721. defined to 1 or 2. Otherwise, such checks are ignored.
  722. PRINTF_CHK indicates, to the internal function being called, that the
  723. call is originated from one of the __*printf_chk functions.
  724. PRINTF_LDBL_USES_FLOAT128 is used on platforms where the long double
  725. format used to be different from the IEC 60559 double format *and*
  726. also different from the Quadruple 128-bits IEC 60559 format (such as
  727. the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
  728. format on x86), but was later converted to the Quadruple 128-bits IEC
  729. 60559 format, which is the same format that the _Float128 always has
  730. (hence the `USES_FLOAT128' suffix in the name of the flag). When set
  731. to one, this macro indicates that long double values are to be
  732. handled as having this new format. Otherwise, they should be handled
  733. as the previous format on that platform. */
  734. #define PRINTF_LDBL_IS_DBL 0x0001
  735. #define PRINTF_FORTIFY 0x0002
  736. #define PRINTF_CHK 0x0004
  737. #define PRINTF_LDBL_USES_FLOAT128 0x0008
  738. extern size_t _IO_getline (FILE *,char *, size_t, int, int);
  739. libc_hidden_proto (_IO_getline)
  740. extern size_t _IO_getline_info (FILE *,char *, size_t,
  741. int, int, int *);
  742. libc_hidden_proto (_IO_getline_info)
  743. extern size_t _IO_getwline (FILE *,wchar_t *, size_t, wint_t, int);
  744. extern size_t _IO_getwline_info (FILE *,wchar_t *, size_t,
  745. wint_t, int, wint_t *);
  746. extern struct _IO_FILE_plus *_IO_list_all;
  747. libc_hidden_proto (_IO_list_all)
  748. extern void (*_IO_cleanup_registration_needed) (void);
  749. extern void _IO_str_init_static_internal (struct _IO_strfile_ *, char *,
  750. size_t, char *) __THROW;
  751. extern off64_t _IO_seekoff_unlocked (FILE *, off64_t, int, int)
  752. attribute_hidden;
  753. extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int)
  754. attribute_hidden;
  755. #if _G_HAVE_MMAP
  756. # include <unistd.h>
  757. # include <fcntl.h>
  758. # include <sys/mman.h>
  759. # include <sys/param.h>
  760. # if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
  761. # define MAP_ANONYMOUS MAP_ANON
  762. # endif
  763. # if !defined(MAP_ANONYMOUS) || !defined(EXEC_PAGESIZE)
  764. # undef _G_HAVE_MMAP
  765. # define _G_HAVE_MMAP 0
  766. # endif
  767. #endif /* _G_HAVE_MMAP */
  768. /* Flags for __vfscanf_internal and __vfwscanf_internal.
  769. SCANF_LDBL_IS_DBL indicates whether long double values are to be
  770. handled as having the same format as double, in which case the flag
  771. should be set to one, or as another format, otherwise.
  772. SCANF_ISOC99_A, when set to one, indicates that the ISO C99 or POSIX
  773. behavior of the scanf functions is to be used, i.e. automatic
  774. allocation for input strings with %as, %aS and %a[, a GNU extension,
  775. is disabled. This is the behavior that the __isoc99_scanf family of
  776. functions use. When the flag is set to zero, automatic allocation is
  777. enabled.
  778. SCANF_ISOC23_BIN_CST, when set to one, indicates the %i accepts
  779. binary constants starting 0b or 0B.
  780. SCANF_LDBL_USES_FLOAT128 is used on platforms where the long double
  781. format used to be different from the IEC 60559 double format *and*
  782. also different from the Quadruple 128-bits IEC 60559 format (such as
  783. the IBM Extended Precision format on powerpc or the 80-bits IEC 60559
  784. format on x86), but was later converted to the Quadruple 128-bits IEC
  785. 60559 format, which is the same format that the _Float128 always has
  786. (hence the `USES_FLOAT128' suffix in the name of the flag). When set
  787. to one, this macros indicates that long double values are to be
  788. handled as having this new format. Otherwise, they should be handled
  789. as the previous format on that platform. */
  790. #define SCANF_LDBL_IS_DBL 0x0001
  791. #define SCANF_ISOC99_A 0x0002
  792. #define SCANF_ISOC23_BIN_CST 0x0004
  793. #define SCANF_LDBL_USES_FLOAT128 0x0008
  794. extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp,
  795. unsigned int flags)
  796. attribute_hidden;
  797. extern int __vfwscanf_internal (FILE *fp, const wchar_t *format, va_list argp,
  798. unsigned int flags)
  799. attribute_hidden;
  800. extern int _IO_vscanf (const char *, va_list) __THROW;
  801. #ifdef _IO_MTSAFE_IO
  802. /* check following! */
  803. # ifdef _IO_USE_OLD_IO_FILE
  804. # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
  805. { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
  806. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
  807. NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
  808. _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock }
  809. # else
  810. # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
  811. { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
  812. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
  813. NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
  814. _IO_pos_BAD, 0, 0, { 0 }, &_IO_stdfile_##FD##_lock, \
  815. _IO_pos_BAD, NULL, WDP, NULL }
  816. # endif
  817. #else
  818. # ifdef _IO_USE_OLD_IO_FILE
  819. # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
  820. { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
  821. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
  822. NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
  823. _IO_pos_BAD }
  824. # else
  825. # define FILEBUF_LITERAL(CHAIN, FLAGS, FD, WDP) \
  826. { _IO_MAGIC+_IO_LINKED+_IO_IS_FILEBUF+FLAGS, \
  827. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
  828. NULL, NULL, (FILE *) CHAIN, FD, 0, { 0 }, \
  829. _IO_pos_BAD, 0, 0, { 0 }, NULL, \
  830. _IO_pos_BAD, NULL, WDP, NULL }
  831. # endif
  832. #endif
  833. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  834. /* See oldstdfiles.c. These are the old stream variables. */
  835. extern struct _IO_FILE_plus _IO_stdin_;
  836. extern struct _IO_FILE_plus _IO_stdout_;
  837. extern struct _IO_FILE_plus _IO_stderr_;
  838. static inline bool
  839. _IO_legacy_file (FILE *fp)
  840. {
  841. return fp == (FILE *) &_IO_stdin_ || fp == (FILE *) &_IO_stdout_
  842. || fp == (FILE *) &_IO_stderr_;
  843. }
  844. #endif
  845. /* Deallocate a stream if it is heap-allocated. Preallocated
  846. stdin/stdout/stderr streams are not deallocated. */
  847. static inline void
  848. _IO_deallocate_file (FILE *fp)
  849. {
  850. /* The current stream variables. */
  851. if (fp == (FILE *) &_IO_2_1_stdin_ || fp == (FILE *) &_IO_2_1_stdout_
  852. || fp == (FILE *) &_IO_2_1_stderr_)
  853. return;
  854. #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
  855. if (_IO_legacy_file (fp))
  856. return;
  857. #endif
  858. free (fp);
  859. }
  860. #ifdef IO_DEBUG
  861. # define CHECK_FILE(FILE, RET) do { \
  862. if ((FILE) == NULL \
  863. || ((FILE)->_flags & _IO_MAGIC_MASK) != _IO_MAGIC) \
  864. { \
  865. __set_errno (EINVAL); \
  866. return RET; \
  867. } \
  868. } while (0)
  869. #else
  870. # define CHECK_FILE(FILE, RET) do { } while (0)
  871. #endif
  872. static inline void
  873. __attribute__ ((__always_inline__))
  874. _IO_acquire_lock_fct (FILE **p)
  875. {
  876. FILE *fp = *p;
  877. if ((fp->_flags & _IO_USER_LOCK) == 0)
  878. _IO_funlockfile (fp);
  879. }
  880. #if !defined _IO_MTSAFE_IO && IS_IN (libc)
  881. # define _IO_acquire_lock(_fp) \
  882. do {
  883. # define _IO_release_lock(_fp) \
  884. } while (0)
  885. #endif
  886. #ifdef SHARED
  887. /* If equal to &_IO_vtable_check (with pointer guard protection),
  888. unknown vtable pointers are valid. This function pointer is solely
  889. used as a flag. */
  890. extern void (*IO_accept_foreign_vtables) (void) attribute_hidden;
  891. /* Assigns the passed function pointer (either NULL or
  892. &_IO_vtable_check) to IO_accept_foreign_vtables. */
  893. static inline void
  894. IO_set_accept_foreign_vtables (void (*flag) (void))
  895. {
  896. PTR_MANGLE (flag);
  897. atomic_store_relaxed (&IO_accept_foreign_vtables, flag);
  898. }
  899. #else /* !SHARED */
  900. /* The statically-linked version does nothing. */
  901. static inline void
  902. IO_set_accept_foreign_vtables (void (*flag) (void))
  903. {
  904. }
  905. #endif
  906. /* Check if unknown vtable pointers are permitted; otherwise,
  907. terminate the process. */
  908. void _IO_vtable_check (void) attribute_hidden;
  909. /* Perform vtable pointer validation. If validation fails, terminate
  910. the process. */
  911. static inline const struct _IO_jump_t *
  912. IO_validate_vtable (const struct _IO_jump_t *vtable)
  913. {
  914. uintptr_t ptr = (uintptr_t) vtable;
  915. uintptr_t offset = ptr - (uintptr_t) &__io_vtables;
  916. if (__glibc_unlikely (offset >= IO_VTABLES_LEN))
  917. /* The vtable pointer is not in the expected section. Use the
  918. slow path, which will terminate the process if necessary. */
  919. _IO_vtable_check ();
  920. return vtable;
  921. }
  922. /* In case of an allocation failure, we resort to using the fixed buffer
  923. _SHORT_BACKUPBUF. Free PTR unless it points to that buffer. */
  924. static __always_inline void
  925. _IO_free_backup_buf (FILE *fp, char *ptr)
  926. {
  927. if (ptr != fp->_short_backupbuf)
  928. free (ptr);
  929. }
  930. /* Character set conversion. */
  931. enum __codecvt_result
  932. {
  933. __codecvt_ok,
  934. __codecvt_partial,
  935. __codecvt_error,
  936. __codecvt_noconv
  937. };
  938. enum __codecvt_result __libio_codecvt_out (struct _IO_codecvt *,
  939. __mbstate_t *,
  940. const wchar_t *,
  941. const wchar_t *,
  942. const wchar_t **, char *,
  943. char *, char **)
  944. attribute_hidden;
  945. enum __codecvt_result __libio_codecvt_in (struct _IO_codecvt *,
  946. __mbstate_t *,
  947. const char *, const char *,
  948. const char **, wchar_t *,
  949. wchar_t *, wchar_t **)
  950. attribute_hidden;
  951. int __libio_codecvt_encoding (struct _IO_codecvt *) attribute_hidden;
  952. int __libio_codecvt_length (struct _IO_codecvt *, __mbstate_t *,
  953. const char *, const char *, size_t)
  954. attribute_hidden;
  955. #endif /* libioP.h. */