2a5a253c66482da66519fd5f241ad2c08c0236e0
[gnulib.git] / lib / stdio_.h
1 /* A GNU-like <stdio.h>.
2
3    Copyright (C) 2004, 2007 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2, or (at your option)
8    any later version.
9
10    This program 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
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #if defined __need_FILE || defined __need___FILE
20 /* Special invocation convention inside glibc header files.  */
21
22 #include @ABSOLUTE_STDIO_H@
23
24 #else
25 /* Normal invocation convention.  */
26
27 #ifdef __DECC
28 # include_next <stdio.h>
29 #endif
30
31 #ifndef _GL_STDIO_H
32 #define _GL_STDIO_H
33
34 #ifndef __DECC
35 # include @ABSOLUTE_STDIO_H@
36 #endif
37
38 #include <stdarg.h>
39 #include <stddef.h>
40
41 #ifndef __attribute__
42 /* This feature is available in gcc versions 2.5 and later.  */
43 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
44 #  define __attribute__(Spec) /* empty */
45 # endif
46 /* The __-protected variants of `format' and `printf' attributes
47    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
48 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
49 #  define __format__ format
50 #  define __printf__ printf
51 # endif
52 #endif
53
54
55 /* The definition of GL_LINK_WARNING is copied here.  */
56
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62
63 #if @GNULIB_FPRINTF_POSIX@
64 # if @REPLACE_FPRINTF@
65 #  define fprintf rpl_fprintf
66 extern int fprintf (FILE *fp, const char *format, ...)
67        __attribute__ ((__format__ (__printf__, 2, 3)));
68 # endif
69 #elif defined GNULIB_POSIXCHECK
70 # undef fprintf
71 # define fprintf \
72     (GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
73                       "use gnulib module fprintf-posix for portable " \
74                       "POSIX compliance"), \
75      fprintf)
76 #endif
77
78 #if @GNULIB_VFPRINTF_POSIX@
79 # if @REPLACE_VFPRINTF@
80 #  define vfprintf rpl_vfprintf
81 extern int vfprintf (FILE *fp, const char *format, va_list args)
82        __attribute__ ((__format__ (__printf__, 2, 0)));
83 # endif
84 #elif defined GNULIB_POSIXCHECK
85 # undef vfprintf
86 # define vfprintf(s,f,a) \
87     (GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
88                       "use gnulib module vfprintf-posix for portable " \
89                       "POSIX compliance"), \
90      vfprintf (s, f, a))
91 #endif
92
93 #if @GNULIB_PRINTF_POSIX@
94 # if @REPLACE_PRINTF@
95 /* Don't break __attribute__((format(printf,M,N))).  */
96 #  define printf __printf__
97 extern int printf (const char *format, ...)
98        __attribute__ ((__format__ (__printf__, 1, 2)));
99 # endif
100 #elif defined GNULIB_POSIXCHECK
101 # undef printf
102 # define printf \
103     (GL_LINK_WARNING ("printf is not always POSIX compliant - " \
104                       "use gnulib module printf-posix for portable " \
105                       "POSIX compliance"), \
106      printf)
107 /* Don't break __attribute__((format(printf,M,N))).  */
108 # define format(kind,m,n) format (__##kind##__, m, n)
109 # define __format__(kind,m,n) __format__ (__##kind##__, m, n)
110 # define ____printf____ __printf__
111 # define ____scanf____ __scanf__
112 # define ____strftime____ __strftime__
113 # define ____strfmon____ __strfmon__
114 #endif
115
116 #if @GNULIB_VPRINTF_POSIX@
117 # if @REPLACE_VPRINTF@
118 #  define vprintf rpl_vprintf
119 extern int vprintf (const char *format, va_list args)
120        __attribute__ ((__format__ (__printf__, 1, 0)));
121 # endif
122 #elif defined GNULIB_POSIXCHECK
123 # undef vprintf
124 # define vprintf(f,a) \
125     (GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
126                       "use gnulib module vprintf-posix for portable " \
127                       "POSIX compliance"), \
128      vprintf (f, a))
129 #endif
130
131 #if @GNULIB_SNPRINTF@
132 # if @REPLACE_SNPRINTF@
133 #  define snprintf rpl_snprintf
134 # endif
135 # if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
136 extern int snprintf (char *str, size_t size, const char *format, ...)
137        __attribute__ ((__format__ (__printf__, 3, 4)));
138 # endif
139 #elif defined GNULIB_POSIXCHECK
140 # undef snprintf
141 # define snprintf \
142     (GL_LINK_WARNING ("snprintf is unportable - " \
143                       "use gnulib module snprintf for portability"), \
144      snprintf)
145 #endif
146
147 #if @GNULIB_VSNPRINTF@
148 # if @REPLACE_VSNPRINTF@
149 #  define vsnprintf rpl_vsnprintf
150 # endif
151 # if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
152 extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
153        __attribute__ ((__format__ (__printf__, 3, 0)));
154 # endif
155 #elif defined GNULIB_POSIXCHECK
156 # undef vsnprintf
157 # define vsnprintf(b,s,f,a) \
158     (GL_LINK_WARNING ("vsnprintf is unportable - " \
159                       "use gnulib module vsnprintf for portability"), \
160      vsnprintf (b, s, f, a))
161 #endif
162
163 #if @GNULIB_SPRINTF_POSIX@
164 # if @REPLACE_SPRINTF@
165 #  define sprintf rpl_sprintf
166 extern int sprintf (char *str, const char *format, ...)
167        __attribute__ ((__format__ (__printf__, 2, 3)));
168 # endif
169 #elif defined GNULIB_POSIXCHECK
170 # undef sprintf
171 # define sprintf \
172     (GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
173                       "use gnulib module sprintf-posix for portable " \
174                       "POSIX compliance"), \
175      sprintf)
176 #endif
177
178 #if @GNULIB_VSPRINTF_POSIX@
179 # if @REPLACE_VSPRINTF@
180 #  define vsprintf rpl_vsprintf
181 extern int vsprintf (char *str, const char *format, va_list args)
182        __attribute__ ((__format__ (__printf__, 2, 0)));
183 # endif
184 #elif defined GNULIB_POSIXCHECK
185 # undef vsprintf
186 # define vsprintf(b,f,a) \
187     (GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
188                       "use gnulib module vsprintf-posix for portable " \
189                       "POSIX compliance"), \
190      vsprintf (b, f, a))
191 #endif
192
193 #if @GNULIB_VASPRINTF@
194 # if @REPLACE_VASPRINTF@
195 #  define asprintf rpl_asprintf
196 #  define vasprintf rpl_vasprintf
197 # endif
198 # if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
199   /* Write formatted output to a string dynamically allocated with malloc().
200      If the memory allocation succeeds, store the address of the string in
201      *RESULT and return the number of resulting bytes, excluding the trailing
202      NUL.  Upon memory allocation error, or some other error, return -1.  */
203   extern int asprintf (char **result, const char *format, ...)
204     __attribute__ ((__format__ (__printf__, 2, 3)));
205   extern int vasprintf (char **result, const char *format, va_list args)
206     __attribute__ ((__format__ (__printf__, 2, 0)));
207 # endif
208 #endif
209
210 #if @GNULIB_FFLUSH@
211 # if @REPLACE_FFLUSH@
212 #  define fflush rpl_fflush
213   /* Flush all pending data on STREAM according to POSIX rules.  Both
214      output and seekable input streams are supported.  */
215   extern int fflush (FILE *gl_stream);
216 # endif
217 #elif defined GNULIB_POSIXCHECK
218 # undef fflush
219 # define fflush(f) \
220    (GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
221                      "use gnulib module fflush for portable " \
222                      "POSIX compliance"), \
223     fflush (f))
224 #endif
225
226 #ifdef __cplusplus
227 }
228 #endif
229
230 #endif /* _GL_STDIO_H */
231 #endif