1 /* Optimizing macros and inline functions for stdio functions.
2 Copyright (C) 198 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 # error "Never include <bits/stdio.h> directly; use <stdio.h> instead."
24 # define __STDIO_INLINE inline
26 # define __STDIO_INLINE extern __inline
30 #ifdef __USE_EXTERN_INLINES
31 /* Write formatted output to stdout from argument list ARG. */
33 vprintf (__const
char *__restrict __fmt
, _G_va_list __arg
) __THROW
35 return vfprintf (stdout
, __fmt
, __arg
);
38 /* Read a character from stdin. */
40 getchar (void) __THROW
42 return _IO_getc (stdin
);
46 # if defined __USE_POSIX || defined __USE_MISC
47 /* This is defined in POSIX.1:1996. */
49 getc_unlocked (FILE *__fp
) __THROW
51 return _IO_getc_unlocked (__fp
);
54 /* This is defined in POSIX.1:1996. */
56 getchar_unlocked (void) __THROW
58 return _IO_getc_unlocked (stdin
);
60 # endif /* POSIX || misc */
63 /* Write a character to stdout. */
65 putchar (int __c
) __THROW
67 return _IO_putc (__c
, stdout
);
72 /* Faster version when locking is not necessary. */
74 fputc_unlocked (int __c
, FILE *__stream
) __THROW
76 return _IO_putc_unlocked (__c
, __stream
);
81 # if defined __USE_POSIX || defined __USE_MISC
82 /* This is defined in POSIX.1:1996. */
84 putc_unlocked (int __c
, FILE *__stream
) __THROW
86 return _IO_putc_unlocked (__c
, __stream
);
89 /* This is defined in POSIX.1:1996. */
91 putchar_unlocked (int __c
) __THROW
93 return _IO_putc_unlocked (__c
, stdout
);
95 # endif /* POSIX || misc */
99 /* Like `getdelim', but reads up to a newline. */
100 __STDIO_INLINE _IO_ssize_t
101 getline (char **__lineptr
, size_t *__n
, FILE *__stream
) __THROW
103 return __getdelim (__lineptr
, __n
, '\n', __stream
);
109 /* Faster versions when locking is not required. */
111 feof_unlocked (FILE *__stream
) __THROW
113 return _IO_feof_unlocked (__stream
);
116 /* Faster versions when locking is not required. */
118 ferror_unlocked (FILE *__stream
) __THROW
120 return _IO_ferror_unlocked (__stream
);
124 #endif /* Use extern inlines. */
127 #if defined __USE_MISC && defined __GNUC__ && defined __OPTIMIZE__
128 /* Perform some simple optimizations. */
129 # define fread_unlocked(ptr, size, n, stream) \
130 (__extension__ ((((__builtin_constant_p (size) \
131 && ((size) == 0 || __builtin_constant_p (n))) \
132 || (__builtin_constant_p (n) && (n) == 0)) \
133 && (size_t) ((size) * (n)) <= 8) \
134 ? ({ char *__ptr = (char *) (ptr); \
135 FILE *__stream = (stream); \
136 size_t __size = (size); \
138 size_t __readres = __n; \
139 size_t __cnt = __size * __n + 1; \
140 while (--__cnt > 0) \
142 int __c = _IO_getc_unlocked (__stream); \
145 __readres = (__size * __n - __cnt) / __size; \
151 : fread_unlocked (ptr, size, n, stream)))
153 # define fwrite_unlocked(ptr, size, n, stream) \
154 (__extension__ ((((__builtin_constant_p (size) \
155 && ((size) == 0 || __builtin_constant_p (n))) \
156 || (__builtin_constant_p (n) && (n) == 0)) \
157 && (size_t) ((size) * (n)) <= 8) \
158 ? ({ const char *__ptr = (const char *) (ptr); \
159 FILE *__stream = (stream); \
160 size_t __size = (size); \
162 size_t __writeres = __n; \
163 size_t __cnt = __size * __n + 1; \
164 while (--__cnt > 0) \
165 if (_IO_putc_unlocked (*__ptr++, __stream) == EOF) \
167 __writeres = (__size * __n - __cnt) / __size; \
171 : fwrite_unlocked (ptr, size, n, stream)))
174 /* Define helper macro. */
175 #undef __STDIO_INLINE