Commit | Line | Data |
---|---|---|
c4b681fd LC |
1 | /* A GNU-like <stdio.h>. |
2 | ||
49114fd4 | 3 | Copyright (C) 2004, 2007-2011 Free Software Foundation, Inc. |
c4b681fd LC |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser 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 Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser 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 __GNUC__ >= 3 | |
20 | @PRAGMA_SYSTEM_HEADER@ | |
21 | #endif | |
0f00f2c3 | 22 | @PRAGMA_COLUMNS@ |
c4b681fd | 23 | |
ab4d62ad LC |
24 | #if defined __need_FILE || defined __need___FILE || defined _GL_ALREADY_INCLUDING_STDIO_H |
25 | /* Special invocation convention: | |
26 | - Inside glibc header files. | |
27 | - On OSF/1 5.1 we have a sequence of nested includes | |
28 | <stdio.h> -> <getopt.h> -> <ctype.h> -> <sys/localedef.h> -> | |
29 | <sys/lc_core.h> -> <nl_types.h> -> <mesg.h> -> <stdio.h>. | |
30 | In this situation, the functions are not yet declared, therefore we cannot | |
31 | provide the C++ aliases. */ | |
c4b681fd LC |
32 | |
33 | #@INCLUDE_NEXT@ @NEXT_STDIO_H@ | |
34 | ||
35 | #else | |
36 | /* Normal invocation convention. */ | |
37 | ||
38 | #ifndef _GL_STDIO_H | |
39 | ||
ab4d62ad LC |
40 | #define _GL_ALREADY_INCLUDING_STDIO_H |
41 | ||
c4b681fd LC |
42 | /* The include_next requires a split double-inclusion guard. */ |
43 | #@INCLUDE_NEXT@ @NEXT_STDIO_H@ | |
44 | ||
ab4d62ad LC |
45 | #undef _GL_ALREADY_INCLUDING_STDIO_H |
46 | ||
c4b681fd LC |
47 | #ifndef _GL_STDIO_H |
48 | #define _GL_STDIO_H | |
49 | ||
61cd9dc9 | 50 | /* Get va_list. Needed on many systems, including glibc 2.8. */ |
c4b681fd | 51 | #include <stdarg.h> |
61cd9dc9 | 52 | |
c4b681fd LC |
53 | #include <stddef.h> |
54 | ||
49114fd4 LC |
55 | /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8 |
56 | and eglibc 2.11.2. */ | |
61cd9dc9 | 57 | #include <sys/types.h> |
c4b681fd | 58 | |
61cd9dc9 LC |
59 | /* The __attribute__ feature is available in gcc versions 2.5 and later. |
60 | The __-protected variants of the attributes 'format' and 'printf' are | |
61 | accepted by gcc versions 2.6.4 (effectively 2.7) and later. | |
49114fd4 | 62 | We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because |
61cd9dc9 LC |
63 | gnulib and libintl do '#define printf __printf__' when they override |
64 | the 'printf' function. */ | |
49114fd4 LC |
65 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) |
66 | # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) | |
67 | #else | |
68 | # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ | |
c4b681fd | 69 | #endif |
49114fd4 LC |
70 | #define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ |
71 | _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) | |
c4b681fd | 72 | |
0f00f2c3 LC |
73 | /* Solaris 10 declares renameat in <unistd.h>, not in <stdio.h>. */ |
74 | /* But in any case avoid namespace pollution on glibc systems. */ | |
75 | #if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __sun \ | |
76 | && ! defined __GLIBC__ | |
77 | # include <unistd.h> | |
78 | #endif | |
79 | ||
c4b681fd | 80 | |
f4c79b3c LC |
81 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
82 | ||
1cd4fffc LC |
83 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
84 | ||
61cd9dc9 LC |
85 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
86 | ||
a927b6c1 LC |
87 | /* Macros for stringification. */ |
88 | #define _GL_STDIO_STRINGIZE(token) #token | |
89 | #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) | |
90 | ||
c4b681fd | 91 | |
c4b681fd LC |
92 | #if @GNULIB_DPRINTF@ |
93 | # if @REPLACE_DPRINTF@ | |
f4c79b3c LC |
94 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
95 | # define dprintf rpl_dprintf | |
96 | # endif | |
97 | _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *format, ...) | |
49114fd4 | 98 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
99 | _GL_ARG_NONNULL ((2))); |
100 | _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *format, ...)); | |
101 | # else | |
102 | # if !@HAVE_DPRINTF@ | |
103 | _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *format, ...) | |
49114fd4 | 104 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
105 | _GL_ARG_NONNULL ((2))); |
106 | # endif | |
107 | _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *format, ...)); | |
c4b681fd | 108 | # endif |
f4c79b3c | 109 | _GL_CXXALIASWARN (dprintf); |
c4b681fd LC |
110 | #elif defined GNULIB_POSIXCHECK |
111 | # undef dprintf | |
61cd9dc9 LC |
112 | # if HAVE_RAW_DECL_DPRINTF |
113 | _GL_WARN_ON_USE (dprintf, "dprintf is unportable - " | |
114 | "use gnulib module dprintf for portability"); | |
115 | # endif | |
c4b681fd LC |
116 | #endif |
117 | ||
8912421c | 118 | #if @GNULIB_FCLOSE@ |
f4c79b3c | 119 | /* Close STREAM and its underlying file descriptor. */ |
8912421c | 120 | # if @REPLACE_FCLOSE@ |
f4c79b3c LC |
121 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
122 | # define fclose rpl_fclose | |
123 | # endif | |
124 | _GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1))); | |
125 | _GL_CXXALIAS_RPL (fclose, int, (FILE *stream)); | |
126 | # else | |
127 | _GL_CXXALIAS_SYS (fclose, int, (FILE *stream)); | |
c4b681fd | 128 | # endif |
f4c79b3c | 129 | _GL_CXXALIASWARN (fclose); |
c4b681fd | 130 | #elif defined GNULIB_POSIXCHECK |
8912421c | 131 | # undef fclose |
61cd9dc9 LC |
132 | /* Assume fclose is always declared. */ |
133 | _GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - " | |
134 | "use gnulib module fclose for portable POSIX compliance"); | |
c4b681fd LC |
135 | #endif |
136 | ||
8912421c | 137 | #if @GNULIB_FFLUSH@ |
f4c79b3c LC |
138 | /* Flush all pending data on STREAM according to POSIX rules. Both |
139 | output and seekable input streams are supported. | |
140 | Note! LOSS OF DATA can occur if fflush is applied on an input stream | |
141 | that is _not_seekable_ or on an update stream that is _not_seekable_ | |
142 | and in which the most recent operation was input. Seekability can | |
143 | be tested with lseek(fileno(fp),0,SEEK_CUR). */ | |
8912421c | 144 | # if @REPLACE_FFLUSH@ |
f4c79b3c LC |
145 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
146 | # define fflush rpl_fflush | |
147 | # endif | |
148 | _GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream)); | |
149 | _GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream)); | |
150 | # else | |
151 | _GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream)); | |
c4b681fd | 152 | # endif |
f4c79b3c | 153 | _GL_CXXALIASWARN (fflush); |
8912421c LC |
154 | #elif defined GNULIB_POSIXCHECK |
155 | # undef fflush | |
61cd9dc9 LC |
156 | /* Assume fflush is always declared. */ |
157 | _GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - " | |
158 | "use gnulib module fflush for portable POSIX compliance"); | |
c4b681fd LC |
159 | #endif |
160 | ||
61cd9dc9 LC |
161 | /* It is very rare that the developer ever has full control of stdin, |
162 | so any use of gets warrants an unconditional warning. Assume it is | |
163 | always declared, since it is required by C89. */ | |
164 | #undef gets | |
165 | _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); | |
166 | ||
c4b681fd LC |
167 | #if @GNULIB_FOPEN@ |
168 | # if @REPLACE_FOPEN@ | |
f4c79b3c LC |
169 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
170 | # undef fopen | |
171 | # define fopen rpl_fopen | |
172 | # endif | |
173 | _GL_FUNCDECL_RPL (fopen, FILE *, (const char *filename, const char *mode) | |
174 | _GL_ARG_NONNULL ((1, 2))); | |
175 | _GL_CXXALIAS_RPL (fopen, FILE *, (const char *filename, const char *mode)); | |
176 | # else | |
177 | _GL_CXXALIAS_SYS (fopen, FILE *, (const char *filename, const char *mode)); | |
c4b681fd | 178 | # endif |
f4c79b3c | 179 | _GL_CXXALIASWARN (fopen); |
c4b681fd LC |
180 | #elif defined GNULIB_POSIXCHECK |
181 | # undef fopen | |
61cd9dc9 LC |
182 | /* Assume fopen is always declared. */ |
183 | _GL_WARN_ON_USE (fopen, "fopen on Win32 platforms is not POSIX compatible - " | |
184 | "use gnulib module fopen for portability"); | |
c4b681fd LC |
185 | #endif |
186 | ||
f4c79b3c LC |
187 | #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@ |
188 | # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \ | |
189 | || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) | |
190 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
191 | # define fprintf rpl_fprintf | |
192 | # endif | |
193 | # define GNULIB_overrides_fprintf 1 | |
194 | _GL_FUNCDECL_RPL (fprintf, int, (FILE *fp, const char *format, ...) | |
49114fd4 | 195 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
196 | _GL_ARG_NONNULL ((1, 2))); |
197 | _GL_CXXALIAS_RPL (fprintf, int, (FILE *fp, const char *format, ...)); | |
198 | # else | |
199 | _GL_CXXALIAS_SYS (fprintf, int, (FILE *fp, const char *format, ...)); | |
200 | # endif | |
201 | _GL_CXXALIASWARN (fprintf); | |
202 | #endif | |
203 | #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK | |
204 | # if !GNULIB_overrides_fprintf | |
205 | # undef fprintf | |
8912421c | 206 | # endif |
61cd9dc9 LC |
207 | /* Assume fprintf is always declared. */ |
208 | _GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - " | |
209 | "use gnulib module fprintf-posix for portable " | |
210 | "POSIX compliance"); | |
8912421c LC |
211 | #endif |
212 | ||
213 | #if @GNULIB_FPURGE@ | |
f4c79b3c LC |
214 | /* Discard all pending buffered I/O data on STREAM. |
215 | STREAM must not be wide-character oriented. | |
216 | When discarding pending output, the file position is set back to where it | |
217 | was before the write calls. When discarding pending input, the file | |
218 | position is advanced to match the end of the previously read input. | |
219 | Return 0 if successful. Upon error, return -1 and set errno. */ | |
8912421c | 220 | # if @REPLACE_FPURGE@ |
f4c79b3c LC |
221 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
222 | # define fpurge rpl_fpurge | |
223 | # endif | |
224 | _GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); | |
225 | _GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream)); | |
226 | # else | |
227 | # if !@HAVE_DECL_FPURGE@ | |
228 | _GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); | |
229 | # endif | |
230 | _GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream)); | |
8912421c | 231 | # endif |
f4c79b3c | 232 | _GL_CXXALIASWARN (fpurge); |
8912421c LC |
233 | #elif defined GNULIB_POSIXCHECK |
234 | # undef fpurge | |
61cd9dc9 LC |
235 | # if HAVE_RAW_DECL_FPURGE |
236 | _GL_WARN_ON_USE (fpurge, "fpurge is not always present - " | |
237 | "use gnulib module fpurge for portability"); | |
238 | # endif | |
8912421c LC |
239 | #endif |
240 | ||
f4c79b3c LC |
241 | #if @GNULIB_FPUTC@ |
242 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
243 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
244 | # undef fputc | |
245 | # define fputc rpl_fputc | |
246 | # endif | |
247 | _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); | |
248 | _GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream)); | |
249 | # else | |
250 | _GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream)); | |
251 | # endif | |
252 | _GL_CXXALIASWARN (fputc); | |
8912421c LC |
253 | #endif |
254 | ||
f4c79b3c LC |
255 | #if @GNULIB_FPUTS@ |
256 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
257 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
258 | # undef fputs | |
259 | # define fputs rpl_fputs | |
260 | # endif | |
261 | _GL_FUNCDECL_RPL (fputs, int, (const char *string, FILE *stream) | |
262 | _GL_ARG_NONNULL ((1, 2))); | |
263 | _GL_CXXALIAS_RPL (fputs, int, (const char *string, FILE *stream)); | |
264 | # else | |
265 | _GL_CXXALIAS_SYS (fputs, int, (const char *string, FILE *stream)); | |
266 | # endif | |
267 | _GL_CXXALIASWARN (fputs); | |
8912421c LC |
268 | #endif |
269 | ||
c4b681fd LC |
270 | #if @GNULIB_FREOPEN@ |
271 | # if @REPLACE_FREOPEN@ | |
f4c79b3c LC |
272 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
273 | # undef freopen | |
274 | # define freopen rpl_freopen | |
275 | # endif | |
276 | _GL_FUNCDECL_RPL (freopen, FILE *, | |
277 | (const char *filename, const char *mode, FILE *stream) | |
278 | _GL_ARG_NONNULL ((2, 3))); | |
279 | _GL_CXXALIAS_RPL (freopen, FILE *, | |
280 | (const char *filename, const char *mode, FILE *stream)); | |
281 | # else | |
282 | _GL_CXXALIAS_SYS (freopen, FILE *, | |
283 | (const char *filename, const char *mode, FILE *stream)); | |
284 | # endif | |
285 | _GL_CXXALIASWARN (freopen); | |
c4b681fd LC |
286 | #elif defined GNULIB_POSIXCHECK |
287 | # undef freopen | |
61cd9dc9 | 288 | /* Assume freopen is always declared. */ |
0f00f2c3 LC |
289 | _GL_WARN_ON_USE (freopen, |
290 | "freopen on Win32 platforms is not POSIX compatible - " | |
61cd9dc9 LC |
291 | "use gnulib module freopen for portability"); |
292 | #endif | |
293 | ||
f4c79b3c | 294 | |
61cd9dc9 LC |
295 | /* Set up the following warnings, based on which modules are in use. |
296 | GNU Coding Standards discourage the use of fseek, since it imposes | |
297 | an arbitrary limitation on some 32-bit hosts. Remember that the | |
298 | fseek module depends on the fseeko module, so we only have three | |
299 | cases to consider: | |
300 | ||
301 | 1. The developer is not using either module. Issue a warning under | |
302 | GNULIB_POSIXCHECK for both functions, to remind them that both | |
303 | functions have bugs on some systems. _GL_NO_LARGE_FILES has no | |
304 | impact on this warning. | |
305 | ||
306 | 2. The developer is using both modules. They may be unaware of the | |
307 | arbitrary limitations of fseek, so issue a warning under | |
308 | GNULIB_POSIXCHECK. On the other hand, they may be using both | |
309 | modules intentionally, so the developer can define | |
310 | _GL_NO_LARGE_FILES in the compilation units where the use of fseek | |
311 | is safe, to silence the warning. | |
312 | ||
313 | 3. The developer is using the fseeko module, but not fseek. Gnulib | |
314 | guarantees that fseek will still work around platform bugs in that | |
315 | case, but we presume that the developer is aware of the pitfalls of | |
316 | fseek and was trying to avoid it, so issue a warning even when | |
317 | GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be | |
318 | defined to silence the warning in particular compilation units. | |
f4c79b3c LC |
319 | In C++ compilations with GNULIB_NAMESPACE, in order to avoid that |
320 | fseek gets defined as a macro, it is recommended that the developer | |
321 | uses the fseek module, even if he is not calling the fseek function. | |
61cd9dc9 LC |
322 | |
323 | Most gnulib clients that perform stream operations should fall into | |
f4c79b3c | 324 | category 3. */ |
61cd9dc9 LC |
325 | |
326 | #if @GNULIB_FSEEK@ | |
327 | # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES | |
328 | # define _GL_FSEEK_WARN /* Category 2, above. */ | |
329 | # undef fseek | |
330 | # endif | |
331 | # if @REPLACE_FSEEK@ | |
f4c79b3c LC |
332 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
333 | # undef fseek | |
334 | # define fseek rpl_fseek | |
335 | # endif | |
336 | _GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence) | |
337 | _GL_ARG_NONNULL ((1))); | |
338 | _GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence)); | |
339 | # else | |
340 | _GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence)); | |
c4b681fd | 341 | # endif |
f4c79b3c | 342 | _GL_CXXALIASWARN (fseek); |
c4b681fd LC |
343 | #endif |
344 | ||
8912421c | 345 | #if @GNULIB_FSEEKO@ |
61cd9dc9 LC |
346 | # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES |
347 | # define _GL_FSEEK_WARN /* Category 3, above. */ | |
348 | # undef fseek | |
349 | # endif | |
8912421c | 350 | # if @REPLACE_FSEEKO@ |
a927b6c1 LC |
351 | /* Provide an fseeko function that is aware of a preceding fflush(), and which |
352 | detects pipes. */ | |
f4c79b3c LC |
353 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
354 | # undef fseeko | |
355 | # define fseeko rpl_fseeko | |
356 | # endif | |
357 | _GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence) | |
358 | _GL_ARG_NONNULL ((1))); | |
a927b6c1 LC |
359 | _GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)); |
360 | # else | |
ab4d62ad | 361 | # if ! @HAVE_DECL_FSEEKO@ |
a927b6c1 LC |
362 | _GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence) |
363 | _GL_ARG_NONNULL ((1))); | |
364 | # endif | |
365 | _GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)); | |
366 | # endif | |
367 | _GL_CXXALIASWARN (fseeko); | |
368 | # if (@REPLACE_FSEEKO@ || !@HAVE_FSEEKO@) && !@GNULIB_FSEEK@ | |
369 | /* Provide an fseek function that is consistent with fseeko. */ | |
370 | /* In order to avoid that fseek gets defined as a macro here, the | |
371 | developer can request the 'fseek' module. */ | |
49114fd4 LC |
372 | # if !GNULIB_defined_fseek_function |
373 | # undef fseek | |
374 | # define fseek rpl_fseek | |
61cd9dc9 LC |
375 | static inline int _GL_ARG_NONNULL ((1)) |
376 | rpl_fseek (FILE *fp, long offset, int whence) | |
377 | { | |
49114fd4 | 378 | # if @REPLACE_FSEEKO@ |
a927b6c1 | 379 | return rpl_fseeko (fp, offset, whence); |
49114fd4 | 380 | # else |
61cd9dc9 | 381 | return fseeko (fp, offset, whence); |
49114fd4 | 382 | # endif |
a927b6c1 | 383 | } |
49114fd4 LC |
384 | # define GNULIB_defined_fseek_function 1 |
385 | # endif | |
c4b681fd LC |
386 | # endif |
387 | #elif defined GNULIB_POSIXCHECK | |
61cd9dc9 LC |
388 | # define _GL_FSEEK_WARN /* Category 1, above. */ |
389 | # undef fseek | |
8912421c | 390 | # undef fseeko |
61cd9dc9 LC |
391 | # if HAVE_RAW_DECL_FSEEKO |
392 | _GL_WARN_ON_USE (fseeko, "fseeko is unportable - " | |
393 | "use gnulib module fseeko for portability"); | |
394 | # endif | |
c4b681fd LC |
395 | #endif |
396 | ||
61cd9dc9 LC |
397 | #ifdef _GL_FSEEK_WARN |
398 | # undef _GL_FSEEK_WARN | |
399 | /* Here, either fseek is undefined (but C89 guarantees that it is | |
400 | declared), or it is defined as rpl_fseek (declared above). */ | |
401 | _GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB " | |
402 | "on 32-bit platforms - " | |
403 | "use fseeko function for handling of large files"); | |
404 | #endif | |
405 | ||
f4c79b3c LC |
406 | |
407 | /* ftell, ftello. See the comments on fseek/fseeko. */ | |
61cd9dc9 LC |
408 | |
409 | #if @GNULIB_FTELL@ | |
410 | # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES | |
411 | # define _GL_FTELL_WARN /* Category 2, above. */ | |
412 | # undef ftell | |
8912421c | 413 | # endif |
61cd9dc9 | 414 | # if @REPLACE_FTELL@ |
f4c79b3c LC |
415 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
416 | # undef ftell | |
417 | # define ftell rpl_ftell | |
418 | # endif | |
419 | _GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1))); | |
420 | _GL_CXXALIAS_RPL (ftell, long, (FILE *fp)); | |
421 | # else | |
422 | _GL_CXXALIAS_SYS (ftell, long, (FILE *fp)); | |
8912421c | 423 | # endif |
f4c79b3c | 424 | _GL_CXXALIASWARN (ftell); |
8912421c LC |
425 | #endif |
426 | ||
427 | #if @GNULIB_FTELLO@ | |
61cd9dc9 LC |
428 | # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES |
429 | # define _GL_FTELL_WARN /* Category 3, above. */ | |
430 | # undef ftell | |
431 | # endif | |
8912421c | 432 | # if @REPLACE_FTELLO@ |
f4c79b3c LC |
433 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
434 | # undef ftello | |
435 | # define ftello rpl_ftello | |
436 | # endif | |
437 | _GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); | |
a927b6c1 LC |
438 | _GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp)); |
439 | # else | |
ab4d62ad | 440 | # if ! @HAVE_DECL_FTELLO@ |
a927b6c1 LC |
441 | _GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); |
442 | # endif | |
443 | _GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp)); | |
444 | # endif | |
445 | _GL_CXXALIASWARN (ftello); | |
446 | # if (@REPLACE_FTELLO@ || !@HAVE_FTELLO@) && !@GNULIB_FTELL@ | |
447 | /* Provide an ftell function that is consistent with ftello. */ | |
448 | /* In order to avoid that ftell gets defined as a macro here, the | |
449 | developer can request the 'ftell' module. */ | |
49114fd4 LC |
450 | # if !GNULIB_defined_ftell_function |
451 | # undef ftell | |
452 | # define ftell rpl_ftell | |
61cd9dc9 LC |
453 | static inline long _GL_ARG_NONNULL ((1)) |
454 | rpl_ftell (FILE *f) | |
455 | { | |
49114fd4 | 456 | # if @REPLACE_FTELLO@ |
a927b6c1 | 457 | return rpl_ftello (f); |
49114fd4 | 458 | # else |
61cd9dc9 | 459 | return ftello (f); |
49114fd4 | 460 | # endif |
a927b6c1 | 461 | } |
49114fd4 LC |
462 | # define GNULIB_defined_ftell_function 1 |
463 | # endif | |
8912421c LC |
464 | # endif |
465 | #elif defined GNULIB_POSIXCHECK | |
61cd9dc9 LC |
466 | # define _GL_FTELL_WARN /* Category 1, above. */ |
467 | # undef ftell | |
8912421c | 468 | # undef ftello |
61cd9dc9 LC |
469 | # if HAVE_RAW_DECL_FTELLO |
470 | _GL_WARN_ON_USE (ftello, "ftello is unportable - " | |
471 | "use gnulib module ftello for portability"); | |
472 | # endif | |
473 | #endif | |
474 | ||
475 | #ifdef _GL_FTELL_WARN | |
476 | # undef _GL_FTELL_WARN | |
477 | /* Here, either ftell is undefined (but C89 guarantees that it is | |
478 | declared), or it is defined as rpl_ftell (declared above). */ | |
479 | _GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB " | |
480 | "on 32-bit platforms - " | |
481 | "use ftello function for handling of large files"); | |
c4b681fd LC |
482 | #endif |
483 | ||
f4c79b3c LC |
484 | |
485 | #if @GNULIB_FWRITE@ | |
486 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
487 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
488 | # undef fwrite | |
489 | # define fwrite rpl_fwrite | |
490 | # endif | |
491 | _GL_FUNCDECL_RPL (fwrite, size_t, | |
492 | (const void *ptr, size_t s, size_t n, FILE *stream) | |
493 | _GL_ARG_NONNULL ((1, 4))); | |
494 | _GL_CXXALIAS_RPL (fwrite, size_t, | |
495 | (const void *ptr, size_t s, size_t n, FILE *stream)); | |
496 | # else | |
497 | _GL_CXXALIAS_SYS (fwrite, size_t, | |
498 | (const void *ptr, size_t s, size_t n, FILE *stream)); | |
499 | # endif | |
500 | _GL_CXXALIASWARN (fwrite); | |
c4b681fd LC |
501 | #endif |
502 | ||
503 | #if @GNULIB_GETDELIM@ | |
c4b681fd LC |
504 | /* Read input, up to (and including) the next occurrence of DELIMITER, from |
505 | STREAM, store it in *LINEPTR (and NUL-terminate it). | |
506 | *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE | |
507 | bytes of space. It is realloc'd as necessary. | |
508 | Return the number of bytes read and stored at *LINEPTR (not including the | |
509 | NUL terminator), or -1 on error or EOF. */ | |
f4c79b3c LC |
510 | # if @REPLACE_GETDELIM@ |
511 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
512 | # undef getdelim | |
513 | # define getdelim rpl_getdelim | |
514 | # endif | |
515 | _GL_FUNCDECL_RPL (getdelim, ssize_t, | |
516 | (char **lineptr, size_t *linesize, int delimiter, | |
517 | FILE *stream) | |
518 | _GL_ARG_NONNULL ((1, 2, 4))); | |
519 | _GL_CXXALIAS_RPL (getdelim, ssize_t, | |
520 | (char **lineptr, size_t *linesize, int delimiter, | |
521 | FILE *stream)); | |
522 | # else | |
523 | # if !@HAVE_DECL_GETDELIM@ | |
524 | _GL_FUNCDECL_SYS (getdelim, ssize_t, | |
525 | (char **lineptr, size_t *linesize, int delimiter, | |
526 | FILE *stream) | |
527 | _GL_ARG_NONNULL ((1, 2, 4))); | |
528 | # endif | |
529 | _GL_CXXALIAS_SYS (getdelim, ssize_t, | |
530 | (char **lineptr, size_t *linesize, int delimiter, | |
531 | FILE *stream)); | |
c4b681fd | 532 | # endif |
f4c79b3c | 533 | _GL_CXXALIASWARN (getdelim); |
c4b681fd LC |
534 | #elif defined GNULIB_POSIXCHECK |
535 | # undef getdelim | |
61cd9dc9 LC |
536 | # if HAVE_RAW_DECL_GETDELIM |
537 | _GL_WARN_ON_USE (getdelim, "getdelim is unportable - " | |
538 | "use gnulib module getdelim for portability"); | |
539 | # endif | |
c4b681fd LC |
540 | #endif |
541 | ||
542 | #if @GNULIB_GETLINE@ | |
c4b681fd LC |
543 | /* Read a line, up to (and including) the next newline, from STREAM, store it |
544 | in *LINEPTR (and NUL-terminate it). | |
545 | *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE | |
546 | bytes of space. It is realloc'd as necessary. | |
547 | Return the number of bytes read and stored at *LINEPTR (not including the | |
548 | NUL terminator), or -1 on error or EOF. */ | |
f4c79b3c LC |
549 | # if @REPLACE_GETLINE@ |
550 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
551 | # undef getline | |
552 | # define getline rpl_getline | |
553 | # endif | |
554 | _GL_FUNCDECL_RPL (getline, ssize_t, | |
555 | (char **lineptr, size_t *linesize, FILE *stream) | |
556 | _GL_ARG_NONNULL ((1, 2, 3))); | |
557 | _GL_CXXALIAS_RPL (getline, ssize_t, | |
558 | (char **lineptr, size_t *linesize, FILE *stream)); | |
559 | # else | |
560 | # if !@HAVE_DECL_GETLINE@ | |
561 | _GL_FUNCDECL_SYS (getline, ssize_t, | |
562 | (char **lineptr, size_t *linesize, FILE *stream) | |
563 | _GL_ARG_NONNULL ((1, 2, 3))); | |
564 | # endif | |
565 | _GL_CXXALIAS_SYS (getline, ssize_t, | |
566 | (char **lineptr, size_t *linesize, FILE *stream)); | |
c4b681fd | 567 | # endif |
a927b6c1 | 568 | # if @HAVE_DECL_GETLINE@ |
f4c79b3c | 569 | _GL_CXXALIASWARN (getline); |
a927b6c1 | 570 | # endif |
c4b681fd LC |
571 | #elif defined GNULIB_POSIXCHECK |
572 | # undef getline | |
61cd9dc9 LC |
573 | # if HAVE_RAW_DECL_GETLINE |
574 | _GL_WARN_ON_USE (getline, "getline is unportable - " | |
575 | "use gnulib module getline for portability"); | |
576 | # endif | |
c4b681fd LC |
577 | #endif |
578 | ||
61cd9dc9 | 579 | #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ |
f4c79b3c LC |
580 | struct obstack; |
581 | /* Grow an obstack with formatted output. Return the number of | |
582 | bytes added to OBS. No trailing nul byte is added, and the | |
583 | object should be closed with obstack_finish before use. Upon | |
584 | memory allocation error, call obstack_alloc_failed_handler. Upon | |
585 | other error, return -1. */ | |
8912421c | 586 | # if @REPLACE_OBSTACK_PRINTF@ |
f4c79b3c LC |
587 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
588 | # define obstack_printf rpl_obstack_printf | |
589 | # endif | |
590 | _GL_FUNCDECL_RPL (obstack_printf, int, | |
591 | (struct obstack *obs, const char *format, ...) | |
49114fd4 | 592 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
593 | _GL_ARG_NONNULL ((1, 2))); |
594 | _GL_CXXALIAS_RPL (obstack_printf, int, | |
595 | (struct obstack *obs, const char *format, ...)); | |
596 | # else | |
597 | # if !@HAVE_DECL_OBSTACK_PRINTF@ | |
598 | _GL_FUNCDECL_SYS (obstack_printf, int, | |
599 | (struct obstack *obs, const char *format, ...) | |
49114fd4 | 600 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
601 | _GL_ARG_NONNULL ((1, 2))); |
602 | # endif | |
603 | _GL_CXXALIAS_SYS (obstack_printf, int, | |
604 | (struct obstack *obs, const char *format, ...)); | |
8912421c | 605 | # endif |
f4c79b3c LC |
606 | _GL_CXXALIASWARN (obstack_printf); |
607 | # if @REPLACE_OBSTACK_PRINTF@ | |
608 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
609 | # define obstack_vprintf rpl_obstack_vprintf | |
610 | # endif | |
611 | _GL_FUNCDECL_RPL (obstack_vprintf, int, | |
612 | (struct obstack *obs, const char *format, va_list args) | |
49114fd4 | 613 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
614 | _GL_ARG_NONNULL ((1, 2))); |
615 | _GL_CXXALIAS_RPL (obstack_vprintf, int, | |
616 | (struct obstack *obs, const char *format, va_list args)); | |
617 | # else | |
618 | # if !@HAVE_DECL_OBSTACK_PRINTF@ | |
619 | _GL_FUNCDECL_SYS (obstack_vprintf, int, | |
620 | (struct obstack *obs, const char *format, va_list args) | |
49114fd4 | 621 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
622 | _GL_ARG_NONNULL ((1, 2))); |
623 | # endif | |
624 | _GL_CXXALIAS_SYS (obstack_vprintf, int, | |
625 | (struct obstack *obs, const char *format, va_list args)); | |
8912421c | 626 | # endif |
f4c79b3c | 627 | _GL_CXXALIASWARN (obstack_vprintf); |
8912421c LC |
628 | #endif |
629 | ||
c4b681fd | 630 | #if @GNULIB_PERROR@ |
c4b681fd LC |
631 | /* Print a message to standard error, describing the value of ERRNO, |
632 | (if STRING is not NULL and not empty) prefixed with STRING and ": ", | |
633 | and terminated with a newline. */ | |
f4c79b3c LC |
634 | # if @REPLACE_PERROR@ |
635 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
636 | # define perror rpl_perror | |
637 | # endif | |
638 | _GL_FUNCDECL_RPL (perror, void, (const char *string)); | |
639 | _GL_CXXALIAS_RPL (perror, void, (const char *string)); | |
640 | # else | |
641 | _GL_CXXALIAS_SYS (perror, void, (const char *string)); | |
c4b681fd | 642 | # endif |
f4c79b3c | 643 | _GL_CXXALIASWARN (perror); |
c4b681fd LC |
644 | #elif defined GNULIB_POSIXCHECK |
645 | # undef perror | |
61cd9dc9 LC |
646 | /* Assume perror is always declared. */ |
647 | _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - " | |
648 | "use gnulib module perror for portability"); | |
c4b681fd LC |
649 | #endif |
650 | ||
8912421c LC |
651 | #if @GNULIB_POPEN@ |
652 | # if @REPLACE_POPEN@ | |
f4c79b3c LC |
653 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
654 | # undef popen | |
655 | # define popen rpl_popen | |
656 | # endif | |
657 | _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) | |
658 | _GL_ARG_NONNULL ((1, 2))); | |
659 | _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); | |
660 | # else | |
661 | _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); | |
8912421c | 662 | # endif |
f4c79b3c | 663 | _GL_CXXALIASWARN (popen); |
8912421c LC |
664 | #elif defined GNULIB_POSIXCHECK |
665 | # undef popen | |
61cd9dc9 LC |
666 | # if HAVE_RAW_DECL_POPEN |
667 | _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " | |
668 | "use gnulib module popen or pipe for more portability"); | |
669 | # endif | |
8912421c LC |
670 | #endif |
671 | ||
f4c79b3c LC |
672 | #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ |
673 | # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ | |
674 | || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) | |
a927b6c1 LC |
675 | # if defined __GNUC__ |
676 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
8912421c | 677 | /* Don't break __attribute__((format(printf,M,N))). */ |
a927b6c1 LC |
678 | # define printf __printf__ |
679 | # endif | |
f4c79b3c LC |
680 | _GL_FUNCDECL_RPL_1 (__printf__, int, |
681 | (const char *format, ...) | |
a927b6c1 LC |
682 | __asm__ (@ASM_SYMBOL_PREFIX@ |
683 | _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) | |
49114fd4 | 684 | _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) |
f4c79b3c LC |
685 | _GL_ARG_NONNULL ((1))); |
686 | _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); | |
a927b6c1 | 687 | # else |
49114fd4 LC |
688 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
689 | # define printf rpl_printf | |
690 | # endif | |
a927b6c1 LC |
691 | _GL_FUNCDECL_RPL (printf, int, |
692 | (const char *format, ...) | |
49114fd4 | 693 | _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) |
a927b6c1 | 694 | _GL_ARG_NONNULL ((1))); |
9157d901 | 695 | _GL_CXXALIAS_RPL (printf, int, (const char *format, ...)); |
a927b6c1 LC |
696 | # endif |
697 | # define GNULIB_overrides_printf 1 | |
f4c79b3c LC |
698 | # else |
699 | _GL_CXXALIAS_SYS (printf, int, (const char *format, ...)); | |
700 | # endif | |
701 | _GL_CXXALIASWARN (printf); | |
702 | #endif | |
703 | #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK | |
704 | # if !GNULIB_overrides_printf | |
705 | # undef printf | |
8912421c | 706 | # endif |
61cd9dc9 LC |
707 | /* Assume printf is always declared. */ |
708 | _GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - " | |
709 | "use gnulib module printf-posix for portable " | |
710 | "POSIX compliance"); | |
8912421c LC |
711 | #endif |
712 | ||
f4c79b3c LC |
713 | #if @GNULIB_PUTC@ |
714 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
715 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
716 | # undef putc | |
717 | # define putc rpl_fputc | |
718 | # endif | |
719 | _GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); | |
720 | _GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream)); | |
721 | # else | |
722 | _GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream)); | |
723 | # endif | |
724 | _GL_CXXALIASWARN (putc); | |
8912421c LC |
725 | #endif |
726 | ||
f4c79b3c LC |
727 | #if @GNULIB_PUTCHAR@ |
728 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
729 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
730 | # undef putchar | |
731 | # define putchar rpl_putchar | |
732 | # endif | |
733 | _GL_FUNCDECL_RPL (putchar, int, (int c)); | |
734 | _GL_CXXALIAS_RPL (putchar, int, (int c)); | |
735 | # else | |
736 | _GL_CXXALIAS_SYS (putchar, int, (int c)); | |
737 | # endif | |
738 | _GL_CXXALIASWARN (putchar); | |
8912421c LC |
739 | #endif |
740 | ||
f4c79b3c LC |
741 | #if @GNULIB_PUTS@ |
742 | # if @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@ | |
743 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
744 | # undef puts | |
745 | # define puts rpl_puts | |
746 | # endif | |
747 | _GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1))); | |
748 | _GL_CXXALIAS_RPL (puts, int, (const char *string)); | |
749 | # else | |
750 | _GL_CXXALIAS_SYS (puts, int, (const char *string)); | |
751 | # endif | |
752 | _GL_CXXALIASWARN (puts); | |
8912421c LC |
753 | #endif |
754 | ||
755 | #if @GNULIB_REMOVE@ | |
756 | # if @REPLACE_REMOVE@ | |
f4c79b3c LC |
757 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
758 | # undef remove | |
759 | # define remove rpl_remove | |
760 | # endif | |
761 | _GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1))); | |
762 | _GL_CXXALIAS_RPL (remove, int, (const char *name)); | |
763 | # else | |
764 | _GL_CXXALIAS_SYS (remove, int, (const char *name)); | |
8912421c | 765 | # endif |
f4c79b3c | 766 | _GL_CXXALIASWARN (remove); |
8912421c LC |
767 | #elif defined GNULIB_POSIXCHECK |
768 | # undef remove | |
61cd9dc9 LC |
769 | /* Assume remove is always declared. */ |
770 | _GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - " | |
771 | "use gnulib module remove for more portability"); | |
8912421c LC |
772 | #endif |
773 | ||
774 | #if @GNULIB_RENAME@ | |
775 | # if @REPLACE_RENAME@ | |
f4c79b3c LC |
776 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
777 | # undef rename | |
778 | # define rename rpl_rename | |
779 | # endif | |
780 | _GL_FUNCDECL_RPL (rename, int, | |
781 | (const char *old_filename, const char *new_filename) | |
782 | _GL_ARG_NONNULL ((1, 2))); | |
783 | _GL_CXXALIAS_RPL (rename, int, | |
784 | (const char *old_filename, const char *new_filename)); | |
785 | # else | |
786 | _GL_CXXALIAS_SYS (rename, int, | |
787 | (const char *old_filename, const char *new_filename)); | |
788 | # endif | |
789 | _GL_CXXALIASWARN (rename); | |
8912421c LC |
790 | #elif defined GNULIB_POSIXCHECK |
791 | # undef rename | |
61cd9dc9 LC |
792 | /* Assume rename is always declared. */ |
793 | _GL_WARN_ON_USE (rename, "rename is buggy on some platforms - " | |
794 | "use gnulib module rename for more portability"); | |
8912421c LC |
795 | #endif |
796 | ||
797 | #if @GNULIB_RENAMEAT@ | |
798 | # if @REPLACE_RENAMEAT@ | |
f4c79b3c LC |
799 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
800 | # undef renameat | |
801 | # define renameat rpl_renameat | |
802 | # endif | |
803 | _GL_FUNCDECL_RPL (renameat, int, | |
804 | (int fd1, char const *file1, int fd2, char const *file2) | |
805 | _GL_ARG_NONNULL ((2, 4))); | |
806 | _GL_CXXALIAS_RPL (renameat, int, | |
807 | (int fd1, char const *file1, int fd2, char const *file2)); | |
808 | # else | |
809 | # if !@HAVE_RENAMEAT@ | |
810 | _GL_FUNCDECL_SYS (renameat, int, | |
811 | (int fd1, char const *file1, int fd2, char const *file2) | |
812 | _GL_ARG_NONNULL ((2, 4))); | |
813 | # endif | |
814 | _GL_CXXALIAS_SYS (renameat, int, | |
815 | (int fd1, char const *file1, int fd2, char const *file2)); | |
8912421c | 816 | # endif |
f4c79b3c | 817 | _GL_CXXALIASWARN (renameat); |
8912421c LC |
818 | #elif defined GNULIB_POSIXCHECK |
819 | # undef renameat | |
61cd9dc9 LC |
820 | # if HAVE_RAW_DECL_RENAMEAT |
821 | _GL_WARN_ON_USE (renameat, "renameat is not portable - " | |
822 | "use gnulib module renameat for portability"); | |
823 | # endif | |
8912421c LC |
824 | #endif |
825 | ||
826 | #if @GNULIB_SNPRINTF@ | |
827 | # if @REPLACE_SNPRINTF@ | |
f4c79b3c LC |
828 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
829 | # define snprintf rpl_snprintf | |
830 | # endif | |
831 | _GL_FUNCDECL_RPL (snprintf, int, | |
832 | (char *str, size_t size, const char *format, ...) | |
49114fd4 | 833 | _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) |
f4c79b3c LC |
834 | _GL_ARG_NONNULL ((3))); |
835 | _GL_CXXALIAS_RPL (snprintf, int, | |
836 | (char *str, size_t size, const char *format, ...)); | |
837 | # else | |
838 | # if !@HAVE_DECL_SNPRINTF@ | |
839 | _GL_FUNCDECL_SYS (snprintf, int, | |
840 | (char *str, size_t size, const char *format, ...) | |
49114fd4 | 841 | _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) |
f4c79b3c LC |
842 | _GL_ARG_NONNULL ((3))); |
843 | # endif | |
844 | _GL_CXXALIAS_SYS (snprintf, int, | |
845 | (char *str, size_t size, const char *format, ...)); | |
8912421c | 846 | # endif |
f4c79b3c | 847 | _GL_CXXALIASWARN (snprintf); |
8912421c LC |
848 | #elif defined GNULIB_POSIXCHECK |
849 | # undef snprintf | |
61cd9dc9 LC |
850 | # if HAVE_RAW_DECL_SNPRINTF |
851 | _GL_WARN_ON_USE (snprintf, "snprintf is unportable - " | |
852 | "use gnulib module snprintf for portability"); | |
853 | # endif | |
8912421c LC |
854 | #endif |
855 | ||
61cd9dc9 LC |
856 | /* Some people would argue that sprintf should be handled like gets |
857 | (for example, OpenBSD issues a link warning for both functions), | |
858 | since both can cause security holes due to buffer overruns. | |
859 | However, we believe that sprintf can be used safely, and is more | |
860 | efficient than snprintf in those safe cases; and as proof of our | |
861 | belief, we use sprintf in several gnulib modules. So this header | |
862 | intentionally avoids adding a warning to sprintf except when | |
863 | GNULIB_POSIXCHECK is defined. */ | |
864 | ||
8912421c LC |
865 | #if @GNULIB_SPRINTF_POSIX@ |
866 | # if @REPLACE_SPRINTF@ | |
f4c79b3c LC |
867 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
868 | # define sprintf rpl_sprintf | |
869 | # endif | |
870 | _GL_FUNCDECL_RPL (sprintf, int, (char *str, const char *format, ...) | |
49114fd4 | 871 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
872 | _GL_ARG_NONNULL ((1, 2))); |
873 | _GL_CXXALIAS_RPL (sprintf, int, (char *str, const char *format, ...)); | |
874 | # else | |
875 | _GL_CXXALIAS_SYS (sprintf, int, (char *str, const char *format, ...)); | |
876 | # endif | |
877 | _GL_CXXALIASWARN (sprintf); | |
8912421c LC |
878 | #elif defined GNULIB_POSIXCHECK |
879 | # undef sprintf | |
61cd9dc9 LC |
880 | /* Assume sprintf is always declared. */ |
881 | _GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - " | |
882 | "use gnulib module sprintf-posix for portable " | |
883 | "POSIX compliance"); | |
8912421c LC |
884 | #endif |
885 | ||
a927b6c1 LC |
886 | #if @GNULIB_TMPFILE@ |
887 | # if @REPLACE_TMPFILE@ | |
888 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
889 | # define tmpfile rpl_tmpfile | |
890 | # endif | |
891 | _GL_FUNCDECL_RPL (tmpfile, FILE *, (void)); | |
892 | _GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); | |
893 | # else | |
894 | _GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); | |
895 | # endif | |
896 | _GL_CXXALIASWARN (tmpfile); | |
897 | #elif defined GNULIB_POSIXCHECK | |
898 | # undef tmpfile | |
899 | # if HAVE_RAW_DECL_TMPFILE | |
900 | _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " | |
901 | "use gnulib module tmpfile for portability"); | |
902 | # endif | |
903 | #endif | |
904 | ||
8912421c | 905 | #if @GNULIB_VASPRINTF@ |
f4c79b3c LC |
906 | /* Write formatted output to a string dynamically allocated with malloc(). |
907 | If the memory allocation succeeds, store the address of the string in | |
908 | *RESULT and return the number of resulting bytes, excluding the trailing | |
909 | NUL. Upon memory allocation error, or some other error, return -1. */ | |
8912421c | 910 | # if @REPLACE_VASPRINTF@ |
f4c79b3c LC |
911 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
912 | # define asprintf rpl_asprintf | |
913 | # endif | |
914 | _GL_FUNCDECL_RPL (asprintf, int, | |
915 | (char **result, const char *format, ...) | |
49114fd4 | 916 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
917 | _GL_ARG_NONNULL ((1, 2))); |
918 | _GL_CXXALIAS_RPL (asprintf, int, | |
919 | (char **result, const char *format, ...)); | |
920 | # else | |
921 | # if !@HAVE_VASPRINTF@ | |
922 | _GL_FUNCDECL_SYS (asprintf, int, | |
923 | (char **result, const char *format, ...) | |
49114fd4 | 924 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
f4c79b3c LC |
925 | _GL_ARG_NONNULL ((1, 2))); |
926 | # endif | |
927 | _GL_CXXALIAS_SYS (asprintf, int, | |
928 | (char **result, const char *format, ...)); | |
8912421c | 929 | # endif |
f4c79b3c LC |
930 | _GL_CXXALIASWARN (asprintf); |
931 | # if @REPLACE_VASPRINTF@ | |
932 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
933 | # define vasprintf rpl_vasprintf | |
934 | # endif | |
935 | _GL_FUNCDECL_RPL (vasprintf, int, | |
936 | (char **result, const char *format, va_list args) | |
49114fd4 | 937 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
938 | _GL_ARG_NONNULL ((1, 2))); |
939 | _GL_CXXALIAS_RPL (vasprintf, int, | |
940 | (char **result, const char *format, va_list args)); | |
941 | # else | |
942 | # if !@HAVE_VASPRINTF@ | |
943 | _GL_FUNCDECL_SYS (vasprintf, int, | |
944 | (char **result, const char *format, va_list args) | |
49114fd4 | 945 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
946 | _GL_ARG_NONNULL ((1, 2))); |
947 | # endif | |
948 | _GL_CXXALIAS_SYS (vasprintf, int, | |
949 | (char **result, const char *format, va_list args)); | |
8912421c | 950 | # endif |
f4c79b3c | 951 | _GL_CXXALIASWARN (vasprintf); |
8912421c LC |
952 | #endif |
953 | ||
954 | #if @GNULIB_VDPRINTF@ | |
955 | # if @REPLACE_VDPRINTF@ | |
f4c79b3c LC |
956 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
957 | # define vdprintf rpl_vdprintf | |
958 | # endif | |
959 | _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *format, va_list args) | |
49114fd4 | 960 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
961 | _GL_ARG_NONNULL ((2))); |
962 | _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *format, va_list args)); | |
963 | # else | |
964 | # if !@HAVE_VDPRINTF@ | |
965 | _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *format, va_list args) | |
49114fd4 | 966 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
967 | _GL_ARG_NONNULL ((2))); |
968 | # endif | |
a927b6c1 LC |
969 | /* Need to cast, because on Solaris, the third parameter will likely be |
970 | __va_list args. */ | |
971 | _GL_CXXALIAS_SYS_CAST (vdprintf, int, | |
972 | (int fd, const char *format, va_list args)); | |
8912421c | 973 | # endif |
f4c79b3c | 974 | _GL_CXXALIASWARN (vdprintf); |
8912421c LC |
975 | #elif defined GNULIB_POSIXCHECK |
976 | # undef vdprintf | |
61cd9dc9 LC |
977 | # if HAVE_RAW_DECL_VDPRINTF |
978 | _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - " | |
979 | "use gnulib module vdprintf for portability"); | |
980 | # endif | |
8912421c LC |
981 | #endif |
982 | ||
f4c79b3c LC |
983 | #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@ |
984 | # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \ | |
985 | || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) | |
986 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
987 | # define vfprintf rpl_vfprintf | |
988 | # endif | |
989 | # define GNULIB_overrides_vfprintf 1 | |
990 | _GL_FUNCDECL_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args) | |
49114fd4 | 991 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
992 | _GL_ARG_NONNULL ((1, 2))); |
993 | _GL_CXXALIAS_RPL (vfprintf, int, (FILE *fp, const char *format, va_list args)); | |
994 | # else | |
a927b6c1 LC |
995 | /* Need to cast, because on Solaris, the third parameter is |
996 | __va_list args | |
997 | and GCC's fixincludes did not change this to __gnuc_va_list. */ | |
998 | _GL_CXXALIAS_SYS_CAST (vfprintf, int, | |
999 | (FILE *fp, const char *format, va_list args)); | |
f4c79b3c LC |
1000 | # endif |
1001 | _GL_CXXALIASWARN (vfprintf); | |
1002 | #endif | |
1003 | #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK | |
1004 | # if !GNULIB_overrides_vfprintf | |
1005 | # undef vfprintf | |
8912421c | 1006 | # endif |
61cd9dc9 LC |
1007 | /* Assume vfprintf is always declared. */ |
1008 | _GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - " | |
1009 | "use gnulib module vfprintf-posix for portable " | |
1010 | "POSIX compliance"); | |
8912421c LC |
1011 | #endif |
1012 | ||
f4c79b3c LC |
1013 | #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ |
1014 | # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \ | |
1015 | || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@) | |
1016 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
1017 | # define vprintf rpl_vprintf | |
1018 | # endif | |
1019 | # define GNULIB_overrides_vprintf 1 | |
1020 | _GL_FUNCDECL_RPL (vprintf, int, (const char *format, va_list args) | |
49114fd4 | 1021 | _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) |
f4c79b3c LC |
1022 | _GL_ARG_NONNULL ((1))); |
1023 | _GL_CXXALIAS_RPL (vprintf, int, (const char *format, va_list args)); | |
1024 | # else | |
a927b6c1 LC |
1025 | /* Need to cast, because on Solaris, the second parameter is |
1026 | __va_list args | |
1027 | and GCC's fixincludes did not change this to __gnuc_va_list. */ | |
1028 | _GL_CXXALIAS_SYS_CAST (vprintf, int, (const char *format, va_list args)); | |
f4c79b3c LC |
1029 | # endif |
1030 | _GL_CXXALIASWARN (vprintf); | |
1031 | #endif | |
1032 | #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK | |
1033 | # if !GNULIB_overrides_vprintf | |
1034 | # undef vprintf | |
8912421c | 1035 | # endif |
61cd9dc9 LC |
1036 | /* Assume vprintf is always declared. */ |
1037 | _GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - " | |
1038 | "use gnulib module vprintf-posix for portable " | |
1039 | "POSIX compliance"); | |
8912421c LC |
1040 | #endif |
1041 | ||
1042 | #if @GNULIB_VSNPRINTF@ | |
1043 | # if @REPLACE_VSNPRINTF@ | |
f4c79b3c LC |
1044 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
1045 | # define vsnprintf rpl_vsnprintf | |
1046 | # endif | |
1047 | _GL_FUNCDECL_RPL (vsnprintf, int, | |
1048 | (char *str, size_t size, const char *format, va_list args) | |
49114fd4 | 1049 | _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) |
f4c79b3c LC |
1050 | _GL_ARG_NONNULL ((3))); |
1051 | _GL_CXXALIAS_RPL (vsnprintf, int, | |
1052 | (char *str, size_t size, const char *format, va_list args)); | |
1053 | # else | |
1054 | # if !@HAVE_DECL_VSNPRINTF@ | |
1055 | _GL_FUNCDECL_SYS (vsnprintf, int, | |
1056 | (char *str, size_t size, const char *format, va_list args) | |
49114fd4 | 1057 | _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) |
f4c79b3c LC |
1058 | _GL_ARG_NONNULL ((3))); |
1059 | # endif | |
1060 | _GL_CXXALIAS_SYS (vsnprintf, int, | |
1061 | (char *str, size_t size, const char *format, va_list args)); | |
8912421c | 1062 | # endif |
f4c79b3c | 1063 | _GL_CXXALIASWARN (vsnprintf); |
8912421c LC |
1064 | #elif defined GNULIB_POSIXCHECK |
1065 | # undef vsnprintf | |
61cd9dc9 LC |
1066 | # if HAVE_RAW_DECL_VSNPRINTF |
1067 | _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " | |
1068 | "use gnulib module vsnprintf for portability"); | |
1069 | # endif | |
8912421c LC |
1070 | #endif |
1071 | ||
1072 | #if @GNULIB_VSPRINTF_POSIX@ | |
1073 | # if @REPLACE_VSPRINTF@ | |
f4c79b3c LC |
1074 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
1075 | # define vsprintf rpl_vsprintf | |
1076 | # endif | |
1077 | _GL_FUNCDECL_RPL (vsprintf, int, | |
1078 | (char *str, const char *format, va_list args) | |
49114fd4 | 1079 | _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
f4c79b3c LC |
1080 | _GL_ARG_NONNULL ((1, 2))); |
1081 | _GL_CXXALIAS_RPL (vsprintf, int, | |
1082 | (char *str, const char *format, va_list args)); | |
1083 | # else | |
a927b6c1 LC |
1084 | /* Need to cast, because on Solaris, the third parameter is |
1085 | __va_list args | |
1086 | and GCC's fixincludes did not change this to __gnuc_va_list. */ | |
1087 | _GL_CXXALIAS_SYS_CAST (vsprintf, int, | |
1088 | (char *str, const char *format, va_list args)); | |
f4c79b3c LC |
1089 | # endif |
1090 | _GL_CXXALIASWARN (vsprintf); | |
8912421c LC |
1091 | #elif defined GNULIB_POSIXCHECK |
1092 | # undef vsprintf | |
61cd9dc9 LC |
1093 | /* Assume vsprintf is always declared. */ |
1094 | _GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - " | |
1095 | "use gnulib module vsprintf-posix for portable " | |
1096 | "POSIX compliance"); | |
8912421c LC |
1097 | #endif |
1098 | ||
c4b681fd LC |
1099 | |
1100 | #endif /* _GL_STDIO_H */ | |
1101 | #endif /* _GL_STDIO_H */ | |
1102 | #endif |