ldbl-128ibm-compat: link tst-ldbl-efgcvt against loader too
[glibc.git] / libio / bits / stdio.h
blobda62908fd7060acabf57c462dfb357d08908d1cb
1 /* Optimizing macros and inline functions for stdio functions.
2 Copyright (C) 1998-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _BITS_STDIO_H
20 #define _BITS_STDIO_H 1
22 #ifndef _STDIO_H
23 # error "Never include <bits/stdio.h> directly; use <stdio.h> instead."
24 #endif
26 #ifndef __extern_inline
27 # define __STDIO_INLINE inline
28 #else
29 # define __STDIO_INLINE __extern_inline
30 #endif
33 #ifdef __USE_EXTERN_INLINES
34 /* For -D_FORTIFY_SOURCE{,=2} bits/stdio2.h will define a different
35 inline. */
36 # if !(__USE_FORTIFY_LEVEL > 0 && defined __fortify_function)
37 /* Write formatted output to stdout from argument list ARG. */
38 __STDIO_INLINE int
39 vprintf (const char *__restrict __fmt, __gnuc_va_list __arg)
41 return vfprintf (stdout, __fmt, __arg);
43 # endif
45 /* Read a character from stdin. */
46 __STDIO_INLINE int
47 getchar (void)
49 return getc (stdin);
53 # ifdef __USE_MISC
54 /* Faster version when locking is not necessary. */
55 __STDIO_INLINE int
56 fgetc_unlocked (FILE *__fp)
58 return __getc_unlocked_body (__fp);
60 # endif /* misc */
63 # ifdef __USE_POSIX
64 /* This is defined in POSIX.1:1996. */
65 __STDIO_INLINE int
66 getc_unlocked (FILE *__fp)
68 return __getc_unlocked_body (__fp);
71 /* This is defined in POSIX.1:1996. */
72 __STDIO_INLINE int
73 getchar_unlocked (void)
75 return __getc_unlocked_body (stdin);
77 # endif /* POSIX */
80 /* Write a character to stdout. */
81 __STDIO_INLINE int
82 putchar (int __c)
84 return putc (__c, stdout);
88 # ifdef __USE_MISC
89 /* Faster version when locking is not necessary. */
90 __STDIO_INLINE int
91 fputc_unlocked (int __c, FILE *__stream)
93 return __putc_unlocked_body (__c, __stream);
95 # endif /* misc */
98 # ifdef __USE_POSIX
99 /* This is defined in POSIX.1:1996. */
100 __STDIO_INLINE int
101 putc_unlocked (int __c, FILE *__stream)
103 return __putc_unlocked_body (__c, __stream);
106 /* This is defined in POSIX.1:1996. */
107 __STDIO_INLINE int
108 putchar_unlocked (int __c)
110 return __putc_unlocked_body (__c, stdout);
112 # endif /* POSIX */
115 # ifdef __USE_GNU
116 /* Like `getdelim', but reads up to a newline. */
117 __STDIO_INLINE __ssize_t
118 getline (char **__lineptr, size_t *__n, FILE *__stream)
120 return __getdelim (__lineptr, __n, '\n', __stream);
122 # endif /* GNU */
125 # ifdef __USE_MISC
126 /* Faster versions when locking is not required. */
127 __STDIO_INLINE int
128 __NTH (feof_unlocked (FILE *__stream))
130 return __feof_unlocked_body (__stream);
133 /* Faster versions when locking is not required. */
134 __STDIO_INLINE int
135 __NTH (ferror_unlocked (FILE *__stream))
137 return __ferror_unlocked_body (__stream);
139 # endif /* misc */
141 #endif /* Use extern inlines. */
144 #if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__ \
145 && !defined __cplusplus
146 /* Perform some simple optimizations. */
147 # define fread_unlocked(ptr, size, n, stream) \
148 (__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \
149 && (size_t) (size) * (size_t) (n) <= 8 \
150 && (size_t) (size) != 0) \
151 ? ({ char *__ptr = (char *) (ptr); \
152 FILE *__stream = (stream); \
153 size_t __cnt; \
154 for (__cnt = (size_t) (size) * (size_t) (n); \
155 __cnt > 0; --__cnt) \
157 int __c = getc_unlocked (__stream); \
158 if (__c == EOF) \
159 break; \
160 *__ptr++ = __c; \
162 ((size_t) (size) * (size_t) (n) - __cnt) \
163 / (size_t) (size); }) \
164 : (((__builtin_constant_p (size) && (size_t) (size) == 0) \
165 || (__builtin_constant_p (n) && (size_t) (n) == 0)) \
166 /* Evaluate all parameters once. */ \
167 ? ((void) (ptr), (void) (stream), (void) (size), \
168 (void) (n), (size_t) 0) \
169 : fread_unlocked (ptr, size, n, stream))))
171 # define fwrite_unlocked(ptr, size, n, stream) \
172 (__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \
173 && (size_t) (size) * (size_t) (n) <= 8 \
174 && (size_t) (size) != 0) \
175 ? ({ const char *__ptr = (const char *) (ptr); \
176 FILE *__stream = (stream); \
177 size_t __cnt; \
178 for (__cnt = (size_t) (size) * (size_t) (n); \
179 __cnt > 0; --__cnt) \
180 if (putc_unlocked (*__ptr++, __stream) == EOF) \
181 break; \
182 ((size_t) (size) * (size_t) (n) - __cnt) \
183 / (size_t) (size); }) \
184 : (((__builtin_constant_p (size) && (size_t) (size) == 0) \
185 || (__builtin_constant_p (n) && (size_t) (n) == 0)) \
186 /* Evaluate all parameters once. */ \
187 ? ((void) (ptr), (void) (stream), (void) (size), \
188 (void) (n), (size_t) 0) \
189 : fwrite_unlocked (ptr, size, n, stream))))
190 #endif
192 /* Define helper macro. */
193 #undef __STDIO_INLINE
195 #endif /* bits/stdio.h. */