stdio.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #ifndef _STDIO_H
  2. # if !defined _ISOMAC && defined _IO_MTSAFE_IO
  3. # include <stdio-lock.h>
  4. # endif
  5. /* Workaround PR90731 with GCC 9 when using ldbl redirects in C++. */
  6. # include <bits/floatn.h>
  7. # if defined __cplusplus && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  8. # if __GNUC_PREREQ (9, 0) && !__GNUC_PREREQ (9, 3)
  9. # pragma GCC system_header
  10. # endif
  11. # endif
  12. # include <libio/stdio.h>
  13. # ifndef _ISOMAC
  14. # define _LIBC_STDIO_H 1
  15. # include <libio/libio.h>
  16. /* Now define the internal interfaces. */
  17. /* Some libc_hidden_ldbl_proto's do not map to a unique symbol when
  18. redirecting ldouble to _Float128 variants. We can therefore safely
  19. directly alias them to their internal name. */
  20. # if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && IS_IN (libc)
  21. # ifdef SHARED
  22. # define stdio_hidden_ldbl_proto(p, f) __LDBL_REDIR2_DECL (f)
  23. # else
  24. # define stdio_hidden_ldbl_proto(p, f) \
  25. extern __typeof (p ## f) p ## f __asm (#p __ASMNAME (#f "ieee128"));
  26. # endif
  27. # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  28. # define stdio_hidden_ldbl_proto(p,f) __LDBL_REDIR1_DECL (p ## f, p ## f ## ieee128)
  29. # else
  30. # define stdio_hidden_ldbl_proto(p,f) libc_hidden_proto (p ## f)
  31. # endif
  32. /* Set the error indicator on FP. */
  33. static inline void
  34. fseterr_unlocked (FILE *fp)
  35. {
  36. fp->_flags |= _IO_ERR_SEEN;
  37. }
  38. extern int __fcloseall (void) attribute_hidden;
  39. extern int __snprintf (char *__restrict __s, size_t __maxlen,
  40. const char *__restrict __format, ...)
  41. __attribute__ ((__format__ (__printf__, 3, 4)));
  42. stdio_hidden_ldbl_proto (__, snprintf)
  43. extern int __vfscanf (FILE *__restrict __s,
  44. const char *__restrict __format,
  45. __gnuc_va_list __arg)
  46. __attribute__ ((__format__ (__scanf__, 2, 0)));
  47. libc_hidden_proto (__vfscanf)
  48. extern int __vscanf (const char *__restrict __format,
  49. __gnuc_va_list __arg)
  50. __attribute__ ((__format__ (__scanf__, 1, 0)));
  51. extern __ssize_t __getline (char **__lineptr, size_t *__n,
  52. FILE *__stream) attribute_hidden;
  53. extern int __vsscanf (const char *__restrict __s,
  54. const char *__restrict __format,
  55. __gnuc_va_list __arg)
  56. __attribute__ ((__format__ (__scanf__, 2, 0)));
  57. extern int __sprintf_chk (char *, int, size_t, const char *, ...) __THROW;
  58. extern int __snprintf_chk (char *, size_t, int, size_t, const char *, ...)
  59. __THROW;
  60. extern int __vsprintf_chk (char *, int, size_t, const char *,
  61. __gnuc_va_list) __THROW;
  62. extern int __vsnprintf_chk (char *, size_t, int, size_t, const char *,
  63. __gnuc_va_list) __THROW;
  64. extern int __printf_chk (int, const char *, ...);
  65. extern int __fprintf_chk (FILE *, int, const char *, ...);
  66. extern int __vprintf_chk (int, const char *, __gnuc_va_list);
  67. extern int __vfprintf_chk (FILE *, int, const char *, __gnuc_va_list);
  68. stdio_hidden_ldbl_proto (__, vfprintf_chk)
  69. extern char *__fgets_unlocked_chk (char *buf, size_t size, int n, FILE *fp);
  70. extern char *__fgets_chk (char *buf, size_t size, int n, FILE *fp);
  71. extern int __asprintf_chk (char **, int, const char *, ...) __THROW;
  72. extern int __vasprintf_chk (char **, int, const char *, __gnuc_va_list) __THROW;
  73. stdio_hidden_ldbl_proto (__, vasprintf_chk)
  74. extern int __dprintf_chk (int, int, const char *, ...);
  75. extern int __vdprintf_chk (int, int, const char *, __gnuc_va_list);
  76. extern int __obstack_printf_chk (struct obstack *, int, const char *, ...)
  77. __THROW;
  78. extern int __obstack_vprintf_chk (struct obstack *, int, const char *,
  79. __gnuc_va_list) __THROW;
  80. extern int __isoc99_fscanf (FILE *__restrict __stream,
  81. const char *__restrict __format, ...) __wur;
  82. extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
  83. extern int __isoc99_sscanf (const char *__restrict __s,
  84. const char *__restrict __format, ...) __THROW;
  85. extern int __isoc99_vfscanf (FILE *__restrict __s,
  86. const char *__restrict __format,
  87. __gnuc_va_list __arg) __wur;
  88. extern int __isoc99_vscanf (const char *__restrict __format,
  89. __gnuc_va_list __arg) __wur;
  90. extern int __isoc99_vsscanf (const char *__restrict __s,
  91. const char *__restrict __format,
  92. __gnuc_va_list __arg) __THROW;
  93. extern int __isoc23_fscanf (FILE *__restrict __stream,
  94. const char *__restrict __format, ...) __wur;
  95. extern int __isoc23_scanf (const char *__restrict __format, ...) __wur;
  96. extern int __isoc23_sscanf (const char *__restrict __s,
  97. const char *__restrict __format, ...) __THROW;
  98. extern int __isoc23_vfscanf (FILE *__restrict __s,
  99. const char *__restrict __format,
  100. __gnuc_va_list __arg) __wur;
  101. extern int __isoc23_vscanf (const char *__restrict __format,
  102. __gnuc_va_list __arg) __wur;
  103. extern int __isoc23_vsscanf (const char *__restrict __s,
  104. const char *__restrict __format,
  105. __gnuc_va_list __arg) __THROW;
  106. libc_hidden_proto (__isoc99_sscanf)
  107. libc_hidden_proto (__isoc99_vsscanf)
  108. libc_hidden_proto (__isoc99_vfscanf)
  109. libc_hidden_proto (__isoc23_sscanf)
  110. libc_hidden_proto (__isoc23_vsscanf)
  111. libc_hidden_proto (__isoc23_vfscanf)
  112. /* Internal uses of sscanf should call the C23-compliant version.
  113. Unfortunately, symbol redirection is not transitive, so the
  114. __REDIRECT in the public header does not link up with the above
  115. libc_hidden_proto. Bridge the gap with a macro. */
  116. # if !__GLIBC_USE (DEPRECATED_SCANF)
  117. # undef sscanf
  118. # define sscanf __isoc23_sscanf
  119. # endif
  120. # if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 && IS_IN (libc)
  121. /* These are implemented as redirects to other public API.
  122. Therefore, the usual redirection fails to avoid PLT. */
  123. extern __typeof (__isoc99_sscanf) ___ieee128_isoc99_sscanf __THROW;
  124. extern __typeof (__isoc99_vsscanf) ___ieee128_isoc99_vsscanf __THROW;
  125. extern __typeof (__isoc99_vfscanf) ___ieee128_isoc99_vfscanf __THROW;
  126. extern __typeof (__isoc23_sscanf) ___ieee128_isoc23_sscanf __THROW;
  127. extern __typeof (__isoc23_vsscanf) ___ieee128_isoc23_vsscanf __THROW;
  128. extern __typeof (__isoc23_vfscanf) ___ieee128_isoc23_vfscanf __THROW;
  129. libc_hidden_proto (___ieee128_isoc99_sscanf)
  130. libc_hidden_proto (___ieee128_isoc99_vsscanf)
  131. libc_hidden_proto (___ieee128_isoc99_vfscanf)
  132. libc_hidden_proto (___ieee128_isoc23_sscanf)
  133. libc_hidden_proto (___ieee128_isoc23_vsscanf)
  134. libc_hidden_proto (___ieee128_isoc23_vfscanf)
  135. #define __isoc99_sscanf ___ieee128_isoc99_sscanf
  136. #define __isoc99_vsscanf ___ieee128_isoc99_vsscanf
  137. #define __isoc99_vfscanf ___ieee128_isoc99_vfscanf
  138. #define __isoc23_sscanf ___ieee128_isoc23_sscanf
  139. #define __isoc23_vsscanf ___ieee128_isoc23_vsscanf
  140. #define __isoc23_vfscanf ___ieee128_isoc23_vfscanf
  141. # endif
  142. /* Prototypes for compatibility functions. */
  143. extern FILE *__new_tmpfile (void);
  144. extern FILE *__old_tmpfile (void);
  145. # define __need_size_t
  146. # include <stddef.h>
  147. # include <bits/types/wint_t.h>
  148. extern int __gen_tempname (char *__tmpl, int __suffixlen, int __flags,
  149. int __kind) attribute_hidden;
  150. /* The __kind argument to __gen_tempname may be one of: */
  151. # define __GT_FILE 0 /* create a file */
  152. # define __GT_DIR 1 /* create a directory */
  153. # define __GT_NOCREATE 2 /* just find a name not currently in use */
  154. /* Print out MESSAGE (which should end with a newline) on the error output
  155. and abort. */
  156. extern void __libc_fatal (const char *__message)
  157. __attribute__ ((__noreturn__));
  158. extern void __fortify_fail (const char *msg) __attribute__ ((__noreturn__));
  159. libc_hidden_proto (__fortify_fail)
  160. /* The maximum number of varargs allowed in a __libc_message format string */
  161. #define LIBC_MESSAGE_MAX_ARGS 7
  162. #define IOVEC_MAX_ERR_MSG "Fatal glibc error: Internal " \
  163. "__libc_message error. Too many arguments.\n"
  164. #define IOVEC_MAX_ERR_MSG_LEN (sizeof (IOVEC_MAX_ERR_MSG) - 1)
  165. _Noreturn void __libc_message_impl (const char *__vmaname, const char *__fmt,
  166. ...) attribute_hidden
  167. __attribute__ ((__format__ (__printf__, 2, 3)));
  168. #define __libc_fatal_vma_name "glibc: fatal"
  169. #define __libc_assert_vma_name "glibc: assert"
  170. #ifdef __va_arg_pack
  171. static inline __always_inline
  172. _Noreturn void __libc_message_wrapper (const char *vmaname,
  173. const char *fmt, ...)
  174. {
  175. if (__va_arg_pack_len () > LIBC_MESSAGE_MAX_ARGS)
  176. {
  177. __errordecl (__libc_message_error, "invalid number of arguments");
  178. __libc_message_error ();
  179. }
  180. __libc_message_impl (vmaname, fmt, __va_arg_pack ());
  181. }
  182. #else
  183. # define __libc_message_wrapper(__vmaname, __fmt, ...) \
  184. __libc_message_impl (__vmaname, __fmt, __VA_ARGS__)
  185. #endif
  186. #define __libc_message(...) \
  187. __libc_message_wrapper (__libc_fatal_vma_name, __VA_ARGS__)
  188. #define __libc_assert(...) \
  189. __libc_message_wrapper (__libc_assert_vma_name, __VA_ARGS__)
  190. /* Acquire ownership of STREAM. */
  191. extern void __flockfile (FILE *__stream);
  192. libc_hidden_proto (__flockfile)
  193. /* Relinquish the ownership granted for STREAM. */
  194. extern void __funlockfile (FILE *__stream);
  195. libc_hidden_proto (__funlockfile)
  196. /* Try to acquire ownership of STREAM but do not block if it is not
  197. possible. */
  198. extern int __ftrylockfile (FILE *__stream);
  199. extern int __getc_unlocked (FILE *__fp) attribute_hidden;
  200. extern wint_t __getwc_unlocked (FILE *__fp);
  201. extern int __fxprintf (FILE *__fp, const char *__fmt, ...)
  202. __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
  203. extern int __fxprintf_nocancel (FILE *__fp, const char *__fmt, ...)
  204. __attribute__ ((__format__ (__printf__, 2, 3))) attribute_hidden;
  205. int __vfxprintf (FILE *__fp, const char *__fmt, __gnuc_va_list,
  206. unsigned int)
  207. attribute_hidden;
  208. extern const char *const _sys_errlist_internal[] attribute_hidden;
  209. extern const size_t _sys_errlist_internal_len attribute_hidden;
  210. extern const char *__get_errlist (int) attribute_hidden;
  211. extern const char *__get_errname (int) attribute_hidden;
  212. libc_hidden_ldbl_proto (__asprintf)
  213. # if IS_IN (libc)
  214. extern FILE *_IO_new_fopen (const char*, const char*);
  215. # define fopen(fname, mode) _IO_new_fopen (fname, mode)
  216. extern FILE *_IO_new_fdopen (int, const char*);
  217. # define fdopen(fd, mode) _IO_new_fdopen (fd, mode)
  218. extern int _IO_new_fclose (FILE*);
  219. # define fclose(fp) _IO_new_fclose (fp)
  220. extern int _IO_fputs (const char*, FILE*);
  221. libc_hidden_proto (_IO_fputs)
  222. /* The compiler may optimize calls to fprintf into calls to fputs.
  223. Use libc_hidden_proto to ensure that those calls, not redirected by
  224. the fputs macro, also do not go through the PLT. */
  225. libc_hidden_proto (fputs)
  226. # define fputs(str, fp) _IO_fputs (str, fp)
  227. extern int _IO_new_fsetpos (FILE *, const __fpos_t *);
  228. # define fsetpos(fp, posp) _IO_new_fsetpos (fp, posp)
  229. extern int _IO_new_fgetpos (FILE *, __fpos_t *);
  230. # define fgetpos(fp, posp) _IO_new_fgetpos (fp, posp)
  231. # endif
  232. extern __typeof (dprintf) __dprintf
  233. __attribute__ ((__format__ (__printf__, 2, 3)));
  234. stdio_hidden_ldbl_proto (__, dprintf)
  235. libc_hidden_ldbl_proto (dprintf)
  236. libc_hidden_ldbl_proto (fprintf)
  237. libc_hidden_ldbl_proto (vfprintf)
  238. libc_hidden_ldbl_proto (sprintf)
  239. libc_hidden_proto (ungetc)
  240. libc_hidden_proto (__getdelim)
  241. libc_hidden_proto (fwrite)
  242. libc_hidden_proto (perror)
  243. libc_hidden_proto (remove)
  244. libc_hidden_proto (rewind)
  245. libc_hidden_proto (fileno)
  246. extern __typeof (fileno) __fileno;
  247. libc_hidden_proto (__fileno)
  248. libc_hidden_proto (fwrite)
  249. libc_hidden_proto (fseek)
  250. extern __typeof (ftello) __ftello;
  251. libc_hidden_proto (__ftello)
  252. extern __typeof (fseeko64) __fseeko64;
  253. libc_hidden_proto (__fseeko64)
  254. extern __typeof (ftello64) __ftello64;
  255. libc_hidden_proto (__ftello64)
  256. libc_hidden_proto (fflush)
  257. libc_hidden_proto (fflush_unlocked)
  258. extern __typeof (fflush_unlocked) __fflush_unlocked;
  259. libc_hidden_proto (__fflush_unlocked)
  260. extern __typeof (fread_unlocked) __fread_unlocked;
  261. libc_hidden_proto (__fread_unlocked)
  262. libc_hidden_proto (fwrite_unlocked)
  263. libc_hidden_proto (fgets_unlocked)
  264. extern __typeof (fgets_unlocked) __fgets_unlocked;
  265. libc_hidden_proto (__fgets_unlocked)
  266. libc_hidden_proto (fputs_unlocked)
  267. extern __typeof (fputs_unlocked) __fputs_unlocked;
  268. libc_hidden_proto (__fputs_unlocked)
  269. libc_hidden_proto (feof_unlocked)
  270. extern __typeof (feof_unlocked) __feof_unlocked attribute_hidden;
  271. libc_hidden_proto (ferror_unlocked)
  272. extern __typeof (ferror_unlocked) __ferror_unlocked attribute_hidden;
  273. libc_hidden_proto (getc_unlocked)
  274. libc_hidden_proto (fputc_unlocked)
  275. libc_hidden_proto (putc_unlocked)
  276. extern __typeof (putc_unlocked) __putc_unlocked attribute_hidden;
  277. libc_hidden_proto (fmemopen)
  278. /* The prototype needs repeating instead of using __typeof to use
  279. __THROW in C++ tests. */
  280. extern FILE *__open_memstream (char **, size_t *) __THROW __wur;
  281. libc_hidden_proto (__open_memstream)
  282. libc_hidden_proto (__libc_fatal)
  283. rtld_hidden_proto (__libc_fatal)
  284. libc_hidden_proto (__fgets_unlocked_chk)
  285. #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  286. libc_hidden_ldbl_proto (__asprintf_chk)
  287. #else
  288. libc_hidden_proto (__asprintf_chk)
  289. #endif
  290. libc_hidden_ldbl_proto (__fprintf_chk)
  291. libc_hidden_ldbl_proto (__sprintf_chk)
  292. libc_hidden_ldbl_proto (__vsprintf_chk)
  293. extern FILE * __fmemopen (void *buf, size_t len, const char *mode);
  294. libc_hidden_proto (__fmemopen)
  295. extern int __gen_tempfd (int flags);
  296. libc_hidden_proto (__gen_tempfd)
  297. # ifdef __USE_EXTERN_INLINES
  298. __extern_inline int
  299. __NTH (__feof_unlocked (FILE *__stream))
  300. {
  301. return __feof_unlocked_body (__stream);
  302. }
  303. __extern_inline int
  304. __NTH (__ferror_unlocked (FILE *__stream))
  305. {
  306. return __ferror_unlocked_body (__stream);
  307. }
  308. __extern_inline int
  309. __getc_unlocked (FILE *__fp)
  310. {
  311. return __getc_unlocked_body (__fp);
  312. }
  313. __extern_inline int
  314. __putc_unlocked (int __c, FILE *__stream)
  315. {
  316. return __putc_unlocked_body (__c, __stream);
  317. }
  318. # endif
  319. extern __typeof (renameat) __renameat;
  320. libc_hidden_proto (__renameat)
  321. extern __typeof (renameat2) __renameat2;
  322. libc_hidden_proto (__renameat2)
  323. # endif /* not _ISOMAC */
  324. #endif /* stdio.h */