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) && __builtin_constant_p (n) \
131 && (size_t) ((size) * (n)) <= 8 && (size) != 0) \
132 ? ({ char *__ptr = (char *) (ptr); \
133 FILE *__stream = (stream); \
135 for (__cnt = (size) * (n); __cnt > 0; --__cnt) \
137 int __c = _IO_getc_unlocked (__stream); \
142 ((size_t) ((size) * (n)) - __cnt) / (size); }) \
143 : (((__builtin_constant_p (size) && (size) == 0) \
144 || (__builtin_constant_p (n) && (n) == 0)) \
145 /* Evaluate all parameters once. */ \
146 ? ((void) (ptr), (void) (stream), (void) (size), \
148 : fread_unlocked (ptr, size, n, stream))))
150 # define fwrite_unlocked(ptr, size, n, stream) \
151 (__extension__ ((__builtin_constant_p (size) && __builtin_constant_p (n) \
152 && (size_t) ((size) * (n)) <= 8 && (size) != 0) \
153 ? ({ const char *__ptr = (const char *) (ptr); \
154 FILE *__stream = (stream); \
156 for (__cnt = (size) * (n); __cnt > 0; --__cnt) \
157 if (_IO_putc_unlocked (*__ptr++, __stream) == EOF) \
159 ((size_t) ((size) * (n)) - __cnt) / (size); }) \
160 : (((__builtin_constant_p (size) && (size) == 0) \
161 || (__builtin_constant_p (n) && (n) == 0)) \
162 /* Evaluate all parameters once. */ \
163 ? ((void) (ptr), (void) (stream), (void) (size), n) \
164 : fwrite_unlocked (ptr, size, n, stream))))
167 /* Define helper macro. */
168 #undef __STDIO_INLINE