1 /* A GNU-like <stdio.h>.
3 Copyright (C) 2004, 2007-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file 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.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
23 #if defined __need_FILE || defined __need___FILE || defined _GL_ALREADY_INCLUDING_STDIO_H
24 /* Special invocation convention:
25 - Inside glibc header files.
26 - On OSF/1 5.1 we have a sequence of nested includes
27 <stdio.h> -> <getopt.h> -> <ctype.h> -> <sys/localedef.h> ->
28 <sys/lc_core.h> -> <nl_types.h> -> <mesg.h> -> <stdio.h>.
29 In this situation, the functions are not yet declared, therefore we cannot
30 provide the C++ aliases. */
32 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
35 /* Normal invocation convention. */
37 #ifndef _@GUARD_PREFIX@_STDIO_H
39 /* Suppress macOS deprecation warnings for sprintf and vsprintf. */
40 #if (defined __APPLE__ && defined __MACH__) && !defined _POSIX_C_SOURCE
41 # ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
42 # include <AvailabilityMacros.h>
44 # if (defined MAC_OS_X_VERSION_MIN_REQUIRED \
45 && 130000 <= MAC_OS_X_VERSION_MIN_REQUIRED)
46 # define _POSIX_C_SOURCE 200809L
47 # define _GL_DEFINED__POSIX_C_SOURCE
51 #define _GL_ALREADY_INCLUDING_STDIO_H
53 /* The include_next requires a split double-inclusion guard. */
54 #@INCLUDE_NEXT@ @NEXT_STDIO_H@
56 #undef _GL_ALREADY_INCLUDING_STDIO_H
58 #ifdef _GL_DEFINED__POSIX_C_SOURCE
59 # undef _GL_DEFINED__POSIX_C_SOURCE
60 # undef _POSIX_C_SOURCE
63 #ifndef _@GUARD_PREFIX@_STDIO_H
64 #define _@GUARD_PREFIX@_STDIO_H
66 /* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_FORMAT,
67 _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOTHROW,
68 GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
69 #if !_GL_CONFIG_H_INCLUDED
70 #error "Please include config.h first."
73 /* Get va_list. Needed on many systems, including glibc 2.8. */
78 /* Get off_t and ssize_t. Needed on many systems, including glibc 2.8
80 May also define off_t to a 64-bit type on native Windows.
81 Also defines off64_t on macOS, NetBSD, OpenBSD, MSVC, Cygwin, Haiku. */
82 #include <sys/types.h>
84 /* Solaris 10 and NetBSD 7.0 declare renameat in <unistd.h>, not in <stdio.h>. */
85 /* But in any case avoid namespace pollution on glibc systems. */
86 #if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && (defined __sun || defined __NetBSD__) \
87 && ! defined __GLIBC__
91 /* Android 4.3 declares renameat in <sys/stat.h>, not in <stdio.h>. */
92 /* But in any case avoid namespace pollution on glibc systems. */
93 #if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
94 && ! defined __GLIBC__
95 # include <sys/stat.h>
98 /* MSVC declares 'perror' in <stdlib.h>, not in <stdio.h>. We must include
99 it before we #define perror rpl_perror. */
100 /* But in any case avoid namespace pollution on glibc systems. */
101 #if (@GNULIB_PERROR@ || defined GNULIB_POSIXCHECK) \
102 && (defined _WIN32 && ! defined __CYGWIN__) \
103 && ! defined __GLIBC__
107 /* MSVC declares 'remove' in <io.h>, not in <stdio.h>. We must include
108 it before we #define remove rpl_remove. */
109 /* MSVC declares 'rename' in <io.h>, not in <stdio.h>. We must include
110 it before we #define rename rpl_rename. */
111 /* But in any case avoid namespace pollution on glibc systems. */
112 #if (@GNULIB_REMOVE@ || @GNULIB_RENAME@ || defined GNULIB_POSIXCHECK) \
113 && (defined _WIN32 && ! defined __CYGWIN__) \
114 && ! defined __GLIBC__
119 /* _GL_ATTRIBUTE_DEALLOC (F, I) declares that the function returns pointers
120 that can be freed by passing them as the Ith argument to the
122 #ifndef _GL_ATTRIBUTE_DEALLOC
123 # if __GNUC__ >= 11 && !defined __clang__
124 # define _GL_ATTRIBUTE_DEALLOC(f, i) __attribute__ ((__malloc__ (f, i)))
126 # define _GL_ATTRIBUTE_DEALLOC(f, i)
130 /* The __attribute__ feature is available in gcc versions 2.5 and later.
131 The __-protected variants of the attributes 'format' and 'printf' are
132 accepted by gcc versions 2.6.4 (effectively 2.7) and later.
133 We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because
134 gnulib and libintl do '#define printf __printf__' when they override
135 the 'printf' function. */
136 #ifndef _GL_ATTRIBUTE_FORMAT
137 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__
138 # define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
140 # define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
144 /* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
146 #ifndef _GL_ATTRIBUTE_MALLOC
147 # if __GNUC__ >= 3 || defined __clang__
148 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
150 # define _GL_ATTRIBUTE_MALLOC
154 /* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
156 #ifndef _GL_ATTRIBUTE_NOTHROW
157 # if defined __cplusplus
158 # if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major__ >= 4
159 # if __cplusplus >= 201103L
160 # define _GL_ATTRIBUTE_NOTHROW noexcept (true)
162 # define _GL_ATTRIBUTE_NOTHROW throw ()
165 # define _GL_ATTRIBUTE_NOTHROW
168 # if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
169 # define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
171 # define _GL_ATTRIBUTE_NOTHROW
176 /* An __attribute__ __format__ specifier for a function that takes a format
177 string and arguments, where the format string directives are the ones
178 standardized by ISO C99 and POSIX.
179 _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */
180 /* __gnu_printf__ is supported in GCC >= 4.4. */
181 #if (__GNUC__ + (__GNUC_MINOR__ >= 4) > 4) && !defined __clang__
182 # define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__
184 # define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__
187 /* An __attribute__ __format__ specifier for a function that takes a format
188 string and arguments, where the format string directives are the ones of the
189 system printf(), rather than the ones standardized by ISO C99 and POSIX.
190 _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM */
191 /* On mingw, Gnulib sets __USE_MINGW_ANSI_STDIO in order to get closer to
192 the standards. The macro GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU indicates
193 whether this change is effective. On older mingw, it is not. */
194 #if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU
195 # define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD
197 # define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM __printf__
200 /* _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD
201 indicates to GCC that the function takes a format string and arguments,
202 where the format string directives are the ones standardized by ISO C99
204 #define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \
205 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, formatstring_parameter, first_argument))
207 /* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD,
208 except that it indicates to GCC that the supported format string directives
209 are the ones of the system printf(), rather than the ones standardized by
210 ISO C99 and POSIX. */
211 #define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \
212 _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, formatstring_parameter, first_argument))
214 /* _GL_ATTRIBUTE_FORMAT_SCANF
215 indicates to GCC that the function takes a format string and arguments,
216 where the format string directives are the ones standardized by ISO C99
218 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
219 # define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
220 _GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, first_argument))
222 # define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \
223 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
226 /* _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_SCANF,
227 except that it indicates to GCC that the supported format string directives
228 are the ones of the system scanf(), rather than the ones standardized by
229 ISO C99 and POSIX. */
230 #define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \
231 _GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument))
233 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
235 /* The definition of _GL_ARG_NONNULL is copied here. */
237 /* The definition of _GL_WARN_ON_USE is copied here. */
239 /* Macros for stringification. */
240 #define _GL_STDIO_STRINGIZE(token) #token
241 #define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token)
243 /* When also using extern inline, suppress the use of static inline in
244 standard headers of problematic Apple configurations, as Libc at
245 least through Libc-825.26 (2013-04-09) mishandles it; see, e.g.,
246 <https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>.
247 Perhaps Apple will fix this some day. */
248 #if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \
249 && defined __GNUC__ && defined __STDC__)
250 # undef putc_unlocked
254 /* Maximum number of characters produced by printing a NaN value. */
255 #ifndef _PRINTF_NAN_LEN_MAX
256 # if defined __FreeBSD__ || defined __DragonFly__ \
257 || defined __NetBSD__ \
258 || (defined __APPLE__ && defined __MACH__)
259 /* On BSD systems, a NaN value prints as just "nan", without a sign. */
260 # define _PRINTF_NAN_LEN_MAX 3
261 # elif (__GLIBC__ >= 2) || MUSL_LIBC || defined __OpenBSD__ || defined __sun || defined __CYGWIN__
262 /* glibc, musl libc, OpenBSD, Solaris libc, and Cygwin produce "[-]nan". */
263 # define _PRINTF_NAN_LEN_MAX 4
265 /* AIX produces "[-]NaNQ". */
266 # define _PRINTF_NAN_LEN_MAX 5
267 # elif defined _WIN32 && !defined __CYGWIN__
268 /* On native Windows, the output can be:
269 - with MSVC ucrt: "[-]nan" or "[-]nan(ind)" or "[-]nan(snan)",
270 - with mingw: "[-]1.#IND" or "[-]1.#QNAN". */
271 # define _PRINTF_NAN_LEN_MAX 10
273 /* On IRIX, the output typically is "[-]nan0xNNNNNNNN" with 8 hexadecimal
275 # define _PRINTF_NAN_LEN_MAX 14
277 /* We don't know, but 32 should be a safe maximum. */
278 # define _PRINTF_NAN_LEN_MAX 32
283 #if @GNULIB_DZPRINTF@
284 /* Prints formatted output to file descriptor FD.
285 Returns the number of bytes written to the file descriptor. Upon
286 failure, returns -1 with errno set.
287 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
288 Therefore, if the format string is valid and does not use %ls/%lc
289 directives nor widths, the only possible failure codes are ENOMEM
290 and the possible failure codes from write(), excluding EINTR. */
291 _GL_FUNCDECL_SYS (dzprintf
, off64_t
,
292 (int fd
, const char *restrict format
, ...),
293 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
294 _GL_ARG_NONNULL ((2)));
295 _GL_CXXALIAS_SYS (dzprintf
, off64_t
,
296 (int fd
, const char *restrict format
, ...));
300 /* Prints formatted output to file descriptor FD.
301 Returns the number of bytes written to the file descriptor. Upon
302 failure, returns a negative value. */
303 # if @REPLACE_DPRINTF@
304 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
305 # define dprintf rpl_dprintf
307 _GL_FUNCDECL_RPL (dprintf
, int, (int fd
, const char *restrict format
, ...),
308 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
309 _GL_ARG_NONNULL ((2)));
310 _GL_CXXALIAS_RPL (dprintf
, int, (int fd
, const char *restrict format
, ...));
313 _GL_FUNCDECL_SYS (dprintf
, int, (int fd
, const char *restrict format
, ...),
314 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
315 _GL_ARG_NONNULL ((2)));
317 _GL_CXXALIAS_SYS (dprintf
, int, (int fd
, const char *restrict format
, ...));
320 _GL_CXXALIASWARN (dprintf
);
322 #elif defined GNULIB_POSIXCHECK
324 # if HAVE_RAW_DECL_DPRINTF
325 _GL_WARN_ON_USE (dprintf
, "dprintf is unportable - "
326 "use gnulib module dprintf for portability");
331 /* Close STREAM and its underlying file descriptor. */
332 # if @REPLACE_FCLOSE@
333 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
334 # define fclose rpl_fclose
336 _GL_FUNCDECL_RPL (fclose
, int, (FILE *stream
), _GL_ARG_NONNULL ((1)));
337 _GL_CXXALIAS_RPL (fclose
, int, (FILE *stream
));
339 _GL_CXXALIAS_SYS (fclose
, int, (FILE *stream
));
342 _GL_CXXALIASWARN (fclose
);
344 #elif defined GNULIB_POSIXCHECK
346 /* Assume fclose is always declared. */
347 _GL_WARN_ON_USE (fclose
, "fclose is not always POSIX compliant - "
348 "use gnulib module fclose for portable POSIX compliance");
351 #if @GNULIB_MDA_FCLOSEALL@
352 /* On native Windows, map 'fcloseall' to '_fcloseall', so that -loldnames is
353 not required. In C++ with GNULIB_NAMESPACE, avoid differences between
354 platforms by defining GNULIB_NAMESPACE::fcloseall on all platforms that have
356 # if defined _WIN32 && !defined __CYGWIN__
357 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
359 # define fcloseall _fcloseall
361 _GL_CXXALIAS_MDA (fcloseall
, int, (void));
363 # if @HAVE_DECL_FCLOSEALL@
364 # if defined __FreeBSD__ || defined __DragonFly__
365 _GL_CXXALIAS_SYS (fcloseall
, void, (void));
367 _GL_CXXALIAS_SYS (fcloseall
, int, (void));
371 # if (defined _WIN32 && !defined __CYGWIN__) || @HAVE_DECL_FCLOSEALL@
372 _GL_CXXALIASWARN (fcloseall
);
377 # if @REPLACE_FDOPEN@
378 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
380 # define fdopen rpl_fdopen
382 _GL_FUNCDECL_RPL (fdopen
, FILE *,
383 (int fd
, const char *mode
),
384 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
386 _GL_ATTRIBUTE_NODISCARD
);
387 _GL_CXXALIAS_RPL (fdopen
, FILE *, (int fd
, const char *mode
));
388 # elif defined _WIN32 && !defined __CYGWIN__
389 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
391 # define fdopen _fdopen
393 _GL_CXXALIAS_MDA (fdopen
, FILE *, (int fd
, const char *mode
));
395 # if __GNUC__ >= 11 && !defined __clang__
396 /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
397 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
398 _GL_FUNCDECL_SYS (fdopen
, FILE *,
399 (int fd
, const char *mode
),
400 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
402 _GL_ATTRIBUTE_NODISCARD
)
403 _GL_ATTRIBUTE_NOTHROW
;
405 _GL_FUNCDECL_SYS (fdopen
, FILE *,
406 (int fd
, const char *mode
),
407 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
409 _GL_ATTRIBUTE_NODISCARD
);
412 _GL_CXXALIAS_SYS (fdopen
, FILE *, (int fd
, const char *mode
));
414 _GL_CXXALIASWARN (fdopen
);
416 # if @GNULIB_FCLOSE@ && (__GNUC__ >= 11 && !defined __clang__) && !defined fdopen
417 /* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
418 # if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
419 _GL_FUNCDECL_SYS (fdopen
, FILE *,
420 (int fd
, const char *mode
),
421 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
422 _GL_ATTRIBUTE_MALLOC
)
423 _GL_ATTRIBUTE_NOTHROW
;
425 _GL_FUNCDECL_SYS (fdopen
, FILE *,
426 (int fd
, const char *mode
),
427 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
428 _GL_ATTRIBUTE_MALLOC
);
431 # if defined GNULIB_POSIXCHECK
433 /* Assume fdopen is always declared. */
434 _GL_WARN_ON_USE (fdopen
, "fdopen on native Windows platforms is not POSIX compliant - "
435 "use gnulib module fdopen for portability");
436 # elif @GNULIB_MDA_FDOPEN@
437 /* On native Windows, map 'fdopen' to '_fdopen', so that -loldnames is not
438 required. In C++ with GNULIB_NAMESPACE, avoid differences between
439 platforms by defining GNULIB_NAMESPACE::fdopen always. */
440 # if defined _WIN32 && !defined __CYGWIN__
441 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
443 # define fdopen _fdopen
445 _GL_CXXALIAS_MDA (fdopen
, FILE *, (int fd
, const char *mode
));
447 _GL_CXXALIAS_SYS (fdopen
, FILE *, (int fd
, const char *mode
));
449 _GL_CXXALIASWARN (fdopen
);
454 /* Flush all pending data on STREAM according to POSIX rules. Both
455 output and seekable input streams are supported.
456 Note! LOSS OF DATA can occur if fflush is applied on an input stream
457 that is _not_seekable_ or on an update stream that is _not_seekable_
458 and in which the most recent operation was input. Seekability can
459 be tested with lseek(fileno(fp),0,SEEK_CUR). */
460 # if @REPLACE_FFLUSH@
461 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
462 # define fflush rpl_fflush
464 _GL_FUNCDECL_RPL (fflush
, int, (FILE *gl_stream
), );
465 _GL_CXXALIAS_RPL (fflush
, int, (FILE *gl_stream
));
467 _GL_CXXALIAS_SYS (fflush
, int, (FILE *gl_stream
));
470 _GL_CXXALIASWARN (fflush
);
472 #elif defined GNULIB_POSIXCHECK
474 /* Assume fflush is always declared. */
475 _GL_WARN_ON_USE (fflush
, "fflush is not always POSIX compliant - "
476 "use gnulib module fflush for portable POSIX compliance");
480 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
481 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
483 # define fgetc rpl_fgetc
485 _GL_FUNCDECL_RPL (fgetc
, int, (FILE *stream
), _GL_ARG_NONNULL ((1)));
486 _GL_CXXALIAS_RPL (fgetc
, int, (FILE *stream
));
488 _GL_CXXALIAS_SYS (fgetc
, int, (FILE *stream
));
491 _GL_CXXALIASWARN (fgetc
);
496 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
497 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
499 # define fgets rpl_fgets
501 _GL_FUNCDECL_RPL (fgets
, char *,
502 (char *restrict s
, int n
, FILE *restrict stream
),
503 _GL_ARG_NONNULL ((1, 3)) _GL_ATTRIBUTE_NODISCARD
);
504 _GL_CXXALIAS_RPL (fgets
, char *,
505 (char *restrict s
, int n
, FILE *restrict stream
));
507 _GL_CXXALIAS_SYS (fgets
, char *,
508 (char *restrict s
, int n
, FILE *restrict stream
));
511 _GL_CXXALIASWARN (fgets
);
515 #if @GNULIB_MDA_FILENO@
516 /* On native Windows, map 'fileno' to '_fileno', so that -loldnames is not
517 required. In C++ with GNULIB_NAMESPACE, avoid differences between
518 platforms by defining GNULIB_NAMESPACE::fileno always. */
519 # if defined _WIN32 && !defined __CYGWIN__
520 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
522 # define fileno _fileno
524 _GL_CXXALIAS_MDA (fileno
, int, (FILE *restrict stream
));
526 _GL_CXXALIAS_SYS (fileno
, int, (FILE *restrict stream
));
528 _GL_CXXALIASWARN (fileno
);
532 # if (@GNULIB_FOPEN@ && @REPLACE_FOPEN@) \
533 || (@GNULIB_FOPEN_GNU@ && @REPLACE_FOPEN_FOR_FOPEN_GNU@)
534 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
536 # define fopen rpl_fopen
538 _GL_FUNCDECL_RPL (fopen
, FILE *,
539 (const char *restrict filename
, const char *restrict mode
),
540 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
541 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_NODISCARD
);
542 _GL_CXXALIAS_RPL (fopen
, FILE *,
543 (const char *restrict filename
, const char *restrict mode
));
545 # if __GNUC__ >= 11 && !defined __clang__
546 /* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
547 _GL_FUNCDECL_SYS (fopen
, FILE *,
548 (const char *restrict filename
, const char *restrict mode
),
549 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
550 _GL_ATTRIBUTE_NODISCARD
);
552 _GL_CXXALIAS_SYS (fopen
, FILE *,
553 (const char *restrict filename
, const char *restrict mode
));
556 _GL_CXXALIASWARN (fopen
);
559 # if @GNULIB_FCLOSE@ && (__GNUC__ >= 11 && !defined __clang__) && !defined fopen
560 /* For -Wmismatched-dealloc: Associate fopen with fclose or rpl_fclose. */
561 _GL_FUNCDECL_SYS (fopen
, FILE *,
562 (const char *restrict filename
, const char *restrict mode
),
563 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose
, 1));
565 # if defined GNULIB_POSIXCHECK
567 /* Assume fopen is always declared. */
568 _GL_WARN_ON_USE (fopen
, "fopen on native Windows platforms is not POSIX compliant - "
569 "use gnulib module fopen for portability");
573 #if @GNULIB_FZPRINTF@
574 /* Prints formatted output to stream FP.
575 Returns the number of bytes written to the stream. Upon failure,
576 returns -1 with the stream's error indicator set.
577 Failure cause EOVERFLOW can only occur when a width > INT_MAX is used.
578 Therefore, if the format string is valid and does not use %ls/%lc
579 directives nor widths, the only possible failure causes are ENOMEM
580 and the possible failure causes from fwrite(). */
581 _GL_FUNCDECL_SYS (fzprintf
, off64_t
,
582 (FILE *restrict fp
, const char *restrict format
, ...),
583 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
584 _GL_ARG_NONNULL ((1, 2)));
585 _GL_CXXALIAS_SYS (fzprintf
, off64_t
,
586 (FILE *restrict fp
, const char *restrict format
, ...));
589 #if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@
590 /* Prints formatted output to stream FP.
591 Returns the number of bytes written to the stream. Upon failure,
592 returns a negative value with the stream's error indicator set. */
593 # if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \
594 || (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
595 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
596 # define fprintf rpl_fprintf
598 # define GNULIB_overrides_fprintf 1
599 # if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
600 _GL_FUNCDECL_RPL (fprintf
, int,
601 (FILE *restrict fp
, const char *restrict format
, ...),
602 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
603 _GL_ARG_NONNULL ((1, 2)));
605 _GL_FUNCDECL_RPL (fprintf
, int,
606 (FILE *restrict fp
, const char *restrict format
, ...),
607 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3)
608 _GL_ARG_NONNULL ((1, 2)));
610 _GL_CXXALIAS_RPL (fprintf
, int,
611 (FILE *restrict fp
, const char *restrict format
, ...));
613 _GL_CXXALIAS_SYS (fprintf
, int,
614 (FILE *restrict fp
, const char *restrict format
, ...));
617 _GL_CXXALIASWARN (fprintf
);
620 #if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
621 # if !GNULIB_overrides_fprintf
624 /* Assume fprintf is always declared. */
625 _GL_WARN_ON_USE (fprintf
, "fprintf is not always POSIX compliant - "
626 "use gnulib module fprintf-posix for portable "
631 /* Discard all pending buffered I/O data on STREAM.
632 STREAM must not be wide-character oriented.
633 When discarding pending output, the file position is set back to where it
634 was before the write calls. When discarding pending input, the file
635 position is advanced to match the end of the previously read input.
636 Return 0 if successful. Upon error, return -1 and set errno. */
637 # if @REPLACE_FPURGE@
638 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
639 # define fpurge rpl_fpurge
641 _GL_FUNCDECL_RPL (fpurge
, int, (FILE *gl_stream
), _GL_ARG_NONNULL ((1)));
642 _GL_CXXALIAS_RPL (fpurge
, int, (FILE *gl_stream
));
644 # if !@HAVE_DECL_FPURGE@
645 _GL_FUNCDECL_SYS (fpurge
, int, (FILE *gl_stream
), _GL_ARG_NONNULL ((1)));
647 _GL_CXXALIAS_SYS (fpurge
, int, (FILE *gl_stream
));
650 _GL_CXXALIASWARN (fpurge
);
652 #elif defined GNULIB_POSIXCHECK
654 # if HAVE_RAW_DECL_FPURGE
655 _GL_WARN_ON_USE (fpurge
, "fpurge is not always present - "
656 "use gnulib module fpurge for portability");
661 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
662 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
664 # define fputc rpl_fputc
666 _GL_FUNCDECL_RPL (fputc
, int, (int c
, FILE *stream
), _GL_ARG_NONNULL ((2)));
667 _GL_CXXALIAS_RPL (fputc
, int, (int c
, FILE *stream
));
669 _GL_CXXALIAS_SYS (fputc
, int, (int c
, FILE *stream
));
672 _GL_CXXALIASWARN (fputc
);
677 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
678 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
680 # define fputs rpl_fputs
682 _GL_FUNCDECL_RPL (fputs
, int,
683 (const char *restrict string
, FILE *restrict stream
),
684 _GL_ARG_NONNULL ((1, 2)));
685 _GL_CXXALIAS_RPL (fputs
, int,
686 (const char *restrict string
, FILE *restrict stream
));
688 _GL_CXXALIAS_SYS (fputs
, int,
689 (const char *restrict string
, FILE *restrict stream
));
692 _GL_CXXALIASWARN (fputs
);
697 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
698 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
700 # define fread rpl_fread
702 _GL_FUNCDECL_RPL (fread
, size_t,
703 (void *restrict ptr
, size_t s
, size_t n
,
704 FILE *restrict stream
),
705 _GL_ARG_NONNULL ((4)) _GL_ATTRIBUTE_NODISCARD
);
706 _GL_CXXALIAS_RPL (fread
, size_t,
707 (void *restrict ptr
, size_t s
, size_t n
,
708 FILE *restrict stream
));
710 _GL_CXXALIAS_SYS (fread
, size_t,
711 (void *restrict ptr
, size_t s
, size_t n
,
712 FILE *restrict stream
));
715 _GL_CXXALIASWARN (fread
);
720 # if @REPLACE_FREOPEN@
721 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
723 # define freopen rpl_freopen
725 _GL_FUNCDECL_RPL (freopen
, FILE *,
726 (const char *restrict filename
, const char *restrict mode
,
727 FILE *restrict stream
),
728 _GL_ARG_NONNULL ((2, 3)) _GL_ATTRIBUTE_NODISCARD
);
729 _GL_CXXALIAS_RPL (freopen
, FILE *,
730 (const char *restrict filename
, const char *restrict mode
,
731 FILE *restrict stream
));
733 _GL_CXXALIAS_SYS (freopen
, FILE *,
734 (const char *restrict filename
, const char *restrict mode
,
735 FILE *restrict stream
));
738 _GL_CXXALIASWARN (freopen
);
740 #elif defined GNULIB_POSIXCHECK
742 /* Assume freopen is always declared. */
743 _GL_WARN_ON_USE (freopen
,
744 "freopen on native Windows platforms is not POSIX compliant - "
745 "use gnulib module freopen for portability");
749 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
750 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
752 # define fscanf rpl_fscanf
754 _GL_FUNCDECL_RPL (fscanf
, int,
755 (FILE *restrict stream
, const char *restrict format
, ...),
756 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3)
757 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_NODISCARD
);
758 _GL_CXXALIAS_RPL (fscanf
, int,
759 (FILE *restrict stream
, const char *restrict format
, ...));
761 _GL_CXXALIAS_SYS (fscanf
, int,
762 (FILE *restrict stream
, const char *restrict format
, ...));
765 _GL_CXXALIASWARN (fscanf
);
770 /* Set up the following warnings, based on which modules are in use.
771 GNU Coding Standards discourage the use of fseek, since it imposes
772 an arbitrary limitation on some 32-bit hosts. Remember that the
773 fseek module depends on the fseeko module, so we only have three
776 1. The developer is not using either module. Issue a warning under
777 GNULIB_POSIXCHECK for both functions, to remind them that both
778 functions have bugs on some systems. _GL_NO_LARGE_FILES has no
779 impact on this warning.
781 2. The developer is using both modules. They may be unaware of the
782 arbitrary limitations of fseek, so issue a warning under
783 GNULIB_POSIXCHECK. On the other hand, they may be using both
784 modules intentionally, so the developer can define
785 _GL_NO_LARGE_FILES in the compilation units where the use of fseek
786 is safe, to silence the warning.
788 3. The developer is using the fseeko module, but not fseek. Gnulib
789 guarantees that fseek will still work around platform bugs in that
790 case, but we presume that the developer is aware of the pitfalls of
791 fseek and was trying to avoid it, so issue a warning even when
792 GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be
793 defined to silence the warning in particular compilation units.
794 In C++ compilations with GNULIB_NAMESPACE, in order to avoid that
795 fseek gets defined as a macro, it is recommended that the developer
796 uses the fseek module, even if he is not calling the fseek function.
798 Most gnulib clients that perform stream operations should fall into
802 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
803 # define _GL_FSEEK_WARN /* Category 2, above. */
807 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
809 # define fseek rpl_fseek
811 _GL_FUNCDECL_RPL (fseek
, int, (FILE *fp
, long offset
, int whence
),
812 _GL_ARG_NONNULL ((1)));
813 _GL_CXXALIAS_RPL (fseek
, int, (FILE *fp
, long offset
, int whence
));
815 _GL_CXXALIAS_SYS (fseek
, int, (FILE *fp
, long offset
, int whence
));
818 _GL_CXXALIASWARN (fseek
);
823 # if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES
824 # define _GL_FSEEK_WARN /* Category 3, above. */
827 # if @REPLACE_FSEEKO@
828 /* Provide an fseeko function that is aware of a preceding fflush(), and which
830 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
832 # define fseeko rpl_fseeko
834 _GL_FUNCDECL_RPL (fseeko
, int, (FILE *fp
, off_t offset
, int whence
),
835 _GL_ARG_NONNULL ((1)));
836 _GL_CXXALIAS_RPL (fseeko
, int, (FILE *fp
, off_t offset
, int whence
));
838 # if ! @HAVE_DECL_FSEEKO@
839 _GL_FUNCDECL_SYS (fseeko
, int, (FILE *fp
, off_t offset
, int whence
),
840 _GL_ARG_NONNULL ((1)));
842 _GL_CXXALIAS_SYS (fseeko
, int, (FILE *fp
, off_t offset
, int whence
));
844 _GL_CXXALIASWARN (fseeko
);
845 #elif defined GNULIB_POSIXCHECK
846 # define _GL_FSEEK_WARN /* Category 1, above. */
849 # if HAVE_RAW_DECL_FSEEKO
850 _GL_WARN_ON_USE (fseeko
, "fseeko is unportable - "
851 "use gnulib module fseeko for portability");
855 #ifdef _GL_FSEEK_WARN
856 # undef _GL_FSEEK_WARN
857 /* Here, either fseek is undefined (but C89 guarantees that it is
858 declared), or it is defined as rpl_fseek (declared above). */
859 _GL_WARN_ON_USE (fseek
, "fseek cannot handle files larger than 4 GB "
860 "on 32-bit platforms - "
861 "use fseeko function for handling of large files");
865 /* ftell, ftello. See the comments on fseek/fseeko. */
868 # if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES
869 # define _GL_FTELL_WARN /* Category 2, above. */
873 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
875 # define ftell rpl_ftell
877 _GL_FUNCDECL_RPL (ftell
, long, (FILE *fp
),
878 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
879 _GL_CXXALIAS_RPL (ftell
, long, (FILE *fp
));
881 _GL_CXXALIAS_SYS (ftell
, long, (FILE *fp
));
884 _GL_CXXALIASWARN (ftell
);
889 # if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES
890 # define _GL_FTELL_WARN /* Category 3, above. */
893 # if @REPLACE_FTELLO@
894 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
896 # define ftello rpl_ftello
898 _GL_FUNCDECL_RPL (ftello
, off_t
, (FILE *fp
),
899 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
900 _GL_CXXALIAS_RPL (ftello
, off_t
, (FILE *fp
));
902 # if ! @HAVE_DECL_FTELLO@
903 _GL_FUNCDECL_SYS (ftello
, off_t
, (FILE *fp
),
904 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
906 _GL_CXXALIAS_SYS (ftello
, off_t
, (FILE *fp
));
908 _GL_CXXALIASWARN (ftello
);
909 #elif defined GNULIB_POSIXCHECK
910 # define _GL_FTELL_WARN /* Category 1, above. */
913 # if HAVE_RAW_DECL_FTELLO
914 _GL_WARN_ON_USE (ftello
, "ftello is unportable - "
915 "use gnulib module ftello for portability");
919 #ifdef _GL_FTELL_WARN
920 # undef _GL_FTELL_WARN
921 /* Here, either ftell is undefined (but C89 guarantees that it is
922 declared), or it is defined as rpl_ftell (declared above). */
923 _GL_WARN_ON_USE (ftell
, "ftell cannot handle files larger than 4 GB "
924 "on 32-bit platforms - "
925 "use ftello function for handling of large files");
930 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
931 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
933 # define fwrite rpl_fwrite
935 _GL_FUNCDECL_RPL (fwrite
, size_t,
936 (const void *restrict ptr
, size_t s
, size_t n
,
937 FILE *restrict stream
),
938 _GL_ARG_NONNULL ((1, 4)));
939 _GL_CXXALIAS_RPL (fwrite
, size_t,
940 (const void *restrict ptr
, size_t s
, size_t n
,
941 FILE *restrict stream
));
943 _GL_CXXALIAS_SYS (fwrite
, size_t,
944 (const void *restrict ptr
, size_t s
, size_t n
,
945 FILE *restrict stream
));
947 /* Work around bug 11959 when fortifying glibc 2.4 through 2.15
948 <https://sourceware.org/bugzilla/show_bug.cgi?id=11959>,
949 which sometimes causes an unwanted diagnostic for fwrite calls.
950 This affects only function declaration attributes under certain
951 versions of gcc and clang, and is not needed for C++. */
952 # if (0 < __USE_FORTIFY_LEVEL \
953 && __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \
954 && (3 < __GNUC__ + (4 <= __GNUC_MINOR__) || defined __clang__) \
955 && !defined __cplusplus)
957 # undef fwrite_unlocked
958 _GL_EXTERN_C
size_t __REDIRECT (rpl_fwrite
,
959 (const void *__restrict
, size_t, size_t,
962 _GL_EXTERN_C
size_t __REDIRECT (rpl_fwrite_unlocked
,
963 (const void *__restrict
, size_t, size_t,
966 # define fwrite rpl_fwrite
967 # define fwrite_unlocked rpl_fwrite_unlocked
971 _GL_CXXALIASWARN (fwrite
);
976 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
977 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
979 # define getc rpl_fgetc
981 _GL_FUNCDECL_RPL (fgetc
, int, (FILE *stream
), _GL_ARG_NONNULL ((1)));
982 _GL_CXXALIAS_RPL_1 (getc
, rpl_fgetc
, int, (FILE *stream
));
984 _GL_CXXALIAS_SYS (getc
, int, (FILE *stream
));
987 _GL_CXXALIASWARN (getc
);
992 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
993 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
995 # define getchar rpl_getchar
997 _GL_FUNCDECL_RPL (getchar
, int, (void), );
998 _GL_CXXALIAS_RPL (getchar
, int, (void));
1000 _GL_CXXALIAS_SYS (getchar
, int, (void));
1003 _GL_CXXALIASWARN (getchar
);
1007 #if @GNULIB_GETDELIM@
1008 /* Read input, up to (and including) the next occurrence of DELIMITER, from
1009 STREAM, store it in *LINEPTR (and NUL-terminate it).
1010 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
1011 bytes of space. It is realloc'd as necessary.
1012 Return the number of bytes read and stored at *LINEPTR (not including the
1013 NUL terminator), or -1 on error or EOF. */
1014 # if @REPLACE_GETDELIM@
1015 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1017 # define getdelim rpl_getdelim
1019 _GL_FUNCDECL_RPL (getdelim
, ssize_t
,
1020 (char **restrict lineptr
, size_t *restrict linesize
,
1022 FILE *restrict stream
),
1023 _GL_ARG_NONNULL ((1, 2, 4)) _GL_ATTRIBUTE_NODISCARD
);
1024 _GL_CXXALIAS_RPL (getdelim
, ssize_t
,
1025 (char **restrict lineptr
, size_t *restrict linesize
,
1027 FILE *restrict stream
));
1029 # if !@HAVE_DECL_GETDELIM@
1030 _GL_FUNCDECL_SYS (getdelim
, ssize_t
,
1031 (char **restrict lineptr
, size_t *restrict linesize
,
1033 FILE *restrict stream
),
1034 _GL_ARG_NONNULL ((1, 2, 4)) _GL_ATTRIBUTE_NODISCARD
);
1036 _GL_CXXALIAS_SYS (getdelim
, ssize_t
,
1037 (char **restrict lineptr
, size_t *restrict linesize
,
1039 FILE *restrict stream
));
1042 _GL_CXXALIASWARN (getdelim
);
1044 #elif defined GNULIB_POSIXCHECK
1046 # if HAVE_RAW_DECL_GETDELIM
1047 _GL_WARN_ON_USE (getdelim
, "getdelim is unportable - "
1048 "use gnulib module getdelim for portability");
1052 #if @GNULIB_GETLINE@
1053 /* Read a line, up to (and including) the next newline, from STREAM, store it
1054 in *LINEPTR (and NUL-terminate it).
1055 *LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
1056 bytes of space. It is realloc'd as necessary.
1057 Return the number of bytes read and stored at *LINEPTR (not including the
1058 NUL terminator), or -1 on error or EOF. */
1059 # if @REPLACE_GETLINE@
1060 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1062 # define getline rpl_getline
1064 _GL_FUNCDECL_RPL (getline
, ssize_t
,
1065 (char **restrict lineptr
, size_t *restrict linesize
,
1066 FILE *restrict stream
),
1067 _GL_ARG_NONNULL ((1, 2, 3)) _GL_ATTRIBUTE_NODISCARD
);
1068 _GL_CXXALIAS_RPL (getline
, ssize_t
,
1069 (char **restrict lineptr
, size_t *restrict linesize
,
1070 FILE *restrict stream
));
1072 # if !@HAVE_DECL_GETLINE@
1073 _GL_FUNCDECL_SYS (getline
, ssize_t
,
1074 (char **restrict lineptr
, size_t *restrict linesize
,
1075 FILE *restrict stream
),
1076 _GL_ARG_NONNULL ((1, 2, 3)) _GL_ATTRIBUTE_NODISCARD
);
1078 _GL_CXXALIAS_SYS (getline
, ssize_t
,
1079 (char **restrict lineptr
, size_t *restrict linesize
,
1080 FILE *restrict stream
));
1082 # if __GLIBC__ >= 2 && @HAVE_DECL_GETLINE@
1083 _GL_CXXALIASWARN (getline
);
1085 #elif defined GNULIB_POSIXCHECK
1087 # if HAVE_RAW_DECL_GETLINE
1088 _GL_WARN_ON_USE (getline
, "getline is unportable - "
1089 "use gnulib module getline for portability");
1093 /* It is very rare that the developer ever has full control of stdin,
1094 so any use of gets warrants an unconditional warning; besides, C11
1097 #if HAVE_RAW_DECL_GETS && !defined __cplusplus
1098 _GL_WARN_ON_USE (gets
, "gets is a security hole - use fgets instead");
1101 #if @GNULIB_MDA_GETW@
1102 /* On native Windows, map 'getw' to '_getw', so that -loldnames is not
1103 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1104 platforms by defining GNULIB_NAMESPACE::getw always. */
1105 # if defined _WIN32 && !defined __CYGWIN__
1106 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1110 _GL_CXXALIAS_MDA (getw
, int, (FILE *restrict stream
));
1112 # if @HAVE_DECL_GETW@
1113 # if defined __APPLE__ && defined __MACH__
1114 /* The presence of the declaration depends on _POSIX_C_SOURCE. */
1115 _GL_FUNCDECL_SYS (getw
, int, (FILE *restrict stream
), );
1117 _GL_CXXALIAS_SYS (getw
, int, (FILE *restrict stream
));
1121 _GL_CXXALIASWARN (getw
);
1125 #if @GNULIB_OBSTACK_ZPRINTF@
1127 /* Grows an obstack with formatted output. Returns the number of
1128 bytes added to OBS. No trailing nul byte is added, and the
1129 object should be closed with obstack_finish before use.
1130 Upon memory allocation error, calls obstack_alloc_failed_handler.
1131 Upon other error, returns -1 with errno set.
1133 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
1134 Therefore, if the format string is valid and does not use %ls/%lc
1135 directives nor widths, the only possible failure code is through
1136 obstack_alloc_failed_handler. */
1137 _GL_FUNCDECL_SYS (obstack_zprintf
, ptrdiff_t,
1138 (struct obstack
*obs
, const char *format
, ...),
1139 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1140 _GL_ARG_NONNULL ((1, 2)));
1141 _GL_CXXALIAS_SYS (obstack_zprintf
, ptrdiff_t,
1142 (struct obstack
*obs
, const char *format
, ...));
1143 _GL_FUNCDECL_SYS (obstack_vzprintf
, ptrdiff_t,
1144 (struct obstack
*obs
, const char *format
, va_list args
),
1145 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1146 _GL_ARG_NONNULL ((1, 2)));
1147 _GL_CXXALIAS_SYS (obstack_vzprintf
, ptrdiff_t,
1148 (struct obstack
*obs
, const char *format
, va_list args
));
1151 #if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
1153 /* Grows an obstack with formatted output. Returns the number of
1154 bytes added to OBS. No trailing nul byte is added, and the
1155 object should be closed with obstack_finish before use.
1156 Upon memory allocation error, calls obstack_alloc_failed_handler.
1157 Upon other error, returns -1. */
1158 # if @REPLACE_OBSTACK_PRINTF@
1159 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1160 # define obstack_printf rpl_obstack_printf
1162 _GL_FUNCDECL_RPL (obstack_printf
, int,
1163 (struct obstack
*obs
, const char *format
, ...),
1164 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1165 _GL_ARG_NONNULL ((1, 2)));
1166 _GL_CXXALIAS_RPL (obstack_printf
, int,
1167 (struct obstack
*obs
, const char *format
, ...));
1169 # if !@HAVE_DECL_OBSTACK_PRINTF@
1170 _GL_FUNCDECL_SYS (obstack_printf
, int,
1171 (struct obstack
*obs
, const char *format
, ...),
1172 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1173 _GL_ARG_NONNULL ((1, 2)));
1175 _GL_CXXALIAS_SYS (obstack_printf
, int,
1176 (struct obstack
*obs
, const char *format
, ...));
1178 _GL_CXXALIASWARN (obstack_printf
);
1179 # if @REPLACE_OBSTACK_PRINTF@
1180 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1181 # define obstack_vprintf rpl_obstack_vprintf
1183 _GL_FUNCDECL_RPL (obstack_vprintf
, int,
1184 (struct obstack
*obs
, const char *format
, va_list args
),
1185 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1186 _GL_ARG_NONNULL ((1, 2)));
1187 _GL_CXXALIAS_RPL (obstack_vprintf
, int,
1188 (struct obstack
*obs
, const char *format
, va_list args
));
1190 # if !@HAVE_DECL_OBSTACK_PRINTF@
1191 _GL_FUNCDECL_SYS (obstack_vprintf
, int,
1192 (struct obstack
*obs
, const char *format
, va_list args
),
1193 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1194 _GL_ARG_NONNULL ((1, 2)));
1196 _GL_CXXALIAS_SYS (obstack_vprintf
, int,
1197 (struct obstack
*obs
, const char *format
, va_list args
));
1199 _GL_CXXALIASWARN (obstack_vprintf
);
1204 _GL_FUNCDECL_SYS (pclose
, int, (FILE *stream
), _GL_ARG_NONNULL ((1)));
1206 _GL_CXXALIAS_SYS (pclose
, int, (FILE *stream
));
1207 _GL_CXXALIASWARN (pclose
);
1208 #elif defined GNULIB_POSIXCHECK
1210 # if HAVE_RAW_DECL_PCLOSE
1211 _GL_WARN_ON_USE (pclose
, "pclose is unportable - "
1212 "use gnulib module pclose for more portability");
1217 /* Print a message to standard error, describing the value of ERRNO,
1218 (if STRING is not NULL and not empty) prefixed with STRING and ": ",
1219 and terminated with a newline. */
1220 # if @REPLACE_PERROR@
1221 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1222 # define perror rpl_perror
1224 _GL_FUNCDECL_RPL (perror
, void, (const char *string
), );
1225 _GL_CXXALIAS_RPL (perror
, void, (const char *string
));
1227 _GL_CXXALIAS_SYS (perror
, void, (const char *string
));
1230 _GL_CXXALIASWARN (perror
);
1232 #elif defined GNULIB_POSIXCHECK
1234 /* Assume perror is always declared. */
1235 _GL_WARN_ON_USE (perror
, "perror is not always POSIX compliant - "
1236 "use gnulib module perror for portability");
1240 # if @REPLACE_POPEN@
1241 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1243 # define popen rpl_popen
1245 _GL_FUNCDECL_RPL (popen
, FILE *,
1246 (const char *cmd
, const char *mode
),
1247 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose
, 1)
1248 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_NODISCARD
);
1249 _GL_CXXALIAS_RPL (popen
, FILE *, (const char *cmd
, const char *mode
));
1251 # if !@HAVE_POPEN@ || (__GNUC__ >= 11 && !defined __clang__)
1252 _GL_FUNCDECL_SYS (popen
, FILE *,
1253 (const char *cmd
, const char *mode
),
1254 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose
, 1)
1255 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_NODISCARD
);
1257 _GL_CXXALIAS_SYS (popen
, FILE *, (const char *cmd
, const char *mode
));
1259 _GL_CXXALIASWARN (popen
);
1261 # if @GNULIB_PCLOSE@ \
1262 && (__GNUC__ >= 11 && !defined __clang__) && !defined popen
1263 /* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */
1264 _GL_FUNCDECL_SYS (popen
, FILE *,
1265 (const char *cmd
, const char *mode
),
1266 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose
, 1)
1267 _GL_ATTRIBUTE_MALLOC
);
1269 # if defined GNULIB_POSIXCHECK
1271 # if HAVE_RAW_DECL_POPEN
1272 _GL_WARN_ON_USE (popen
, "popen is buggy on some platforms - "
1273 "use gnulib module popen or pipe for more portability");
1278 #if @GNULIB_ZPRINTF@
1279 /* Prints formatted output to standard output.
1280 Returns the number of bytes written to standard output. Upon failure,
1281 returns -1 with stdout's error indicator set.
1282 Failure cause EOVERFLOW can only occur when a width > INT_MAX is used.
1283 Therefore, if the format string is valid and does not use %ls/%lc
1284 directives nor widths, the only possible failure causes are ENOMEM
1285 and the possible failure causes from fwrite(). */
1286 _GL_FUNCDECL_SYS (zprintf
, off64_t
, (const char *restrict format
, ...),
1287 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
1288 _GL_ARG_NONNULL ((1)));
1289 _GL_CXXALIAS_SYS (zprintf
, off64_t
, (const char *restrict format
, ...));
1292 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
1293 /* Prints formatted output to standard output.
1294 Returns the number of bytes written to standard output. Upon failure,
1295 returns a negative value with stdout's error indicator set. */
1296 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
1297 || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
1298 # if defined __GNUC__ || defined __clang__
1299 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1300 /* Don't break __attribute__((format(printf,M,N))). */
1301 # define printf __printf__
1303 # if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
1304 _GL_FUNCDECL_RPL_1 (__printf__
, int,
1305 (const char *restrict format
, ...)
1306 __asm__ (@ASM_SYMBOL_PREFIX@
1307 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf
)),
1308 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
1309 _GL_ARG_NONNULL ((1)));
1311 _GL_FUNCDECL_RPL_1 (__printf__
, int,
1312 (const char *restrict format
, ...)
1313 __asm__ (@ASM_SYMBOL_PREFIX@
1314 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf
)),
1315 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2)
1316 _GL_ARG_NONNULL ((1)));
1318 _GL_CXXALIAS_RPL_1 (printf
, __printf__
, int, (const char *format
, ...));
1320 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1321 # define printf rpl_printf
1323 _GL_FUNCDECL_RPL (printf
, int,
1324 (const char *restrict format
, ...),
1325 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
1326 _GL_ARG_NONNULL ((1)));
1327 _GL_CXXALIAS_RPL (printf
, int, (const char *restrict format
, ...));
1329 # define GNULIB_overrides_printf 1
1331 _GL_CXXALIAS_SYS (printf
, int, (const char *restrict format
, ...));
1334 _GL_CXXALIASWARN (printf
);
1337 #if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1338 # if !GNULIB_overrides_printf
1341 /* Assume printf is always declared. */
1342 _GL_WARN_ON_USE (printf
, "printf is not always POSIX compliant - "
1343 "use gnulib module printf-posix for portable "
1344 "POSIX compliance");
1348 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
1349 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1351 # define putc rpl_fputc
1353 _GL_FUNCDECL_RPL (fputc
, int, (int c
, FILE *stream
), _GL_ARG_NONNULL ((2)));
1354 _GL_CXXALIAS_RPL_1 (putc
, rpl_fputc
, int, (int c
, FILE *stream
));
1356 _GL_CXXALIAS_SYS (putc
, int, (int c
, FILE *stream
));
1359 _GL_CXXALIASWARN (putc
);
1363 #if @GNULIB_PUTCHAR@
1364 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
1365 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1367 # define putchar rpl_putchar
1369 _GL_FUNCDECL_RPL (putchar
, int, (int c
), );
1370 _GL_CXXALIAS_RPL (putchar
, int, (int c
));
1372 _GL_CXXALIAS_SYS (putchar
, int, (int c
));
1375 _GL_CXXALIASWARN (putchar
);
1380 # if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)
1381 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1383 # define puts rpl_puts
1385 _GL_FUNCDECL_RPL (puts
, int, (const char *string
), _GL_ARG_NONNULL ((1)));
1386 _GL_CXXALIAS_RPL (puts
, int, (const char *string
));
1388 _GL_CXXALIAS_SYS (puts
, int, (const char *string
));
1391 _GL_CXXALIASWARN (puts
);
1395 #if @GNULIB_MDA_PUTW@
1396 /* On native Windows, map 'putw' to '_putw', so that -loldnames is not
1397 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1398 platforms by defining GNULIB_NAMESPACE::putw always. */
1399 # if defined _WIN32 && !defined __CYGWIN__
1400 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1404 _GL_CXXALIAS_MDA (putw
, int, (int w
, FILE *restrict stream
));
1406 # if @HAVE_DECL_PUTW@
1407 # if defined __APPLE__ && defined __MACH__
1408 /* The presence of the declaration depends on _POSIX_C_SOURCE. */
1409 _GL_FUNCDECL_SYS (putw
, int, (int w
, FILE *restrict stream
), );
1411 _GL_CXXALIAS_SYS (putw
, int, (int w
, FILE *restrict stream
));
1415 _GL_CXXALIASWARN (putw
);
1420 # if @REPLACE_REMOVE@
1421 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1423 # define remove rpl_remove
1425 _GL_FUNCDECL_RPL (remove
, int, (const char *name
), _GL_ARG_NONNULL ((1)));
1426 _GL_CXXALIAS_RPL (remove
, int, (const char *name
));
1428 _GL_CXXALIAS_SYS (remove
, int, (const char *name
));
1431 _GL_CXXALIASWARN (remove
);
1433 #elif defined GNULIB_POSIXCHECK
1435 /* Assume remove is always declared. */
1436 _GL_WARN_ON_USE (remove
, "remove cannot handle directories on some platforms - "
1437 "use gnulib module remove for more portability");
1441 # if @REPLACE_RENAME@
1442 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1444 # define rename rpl_rename
1446 _GL_FUNCDECL_RPL (rename
, int,
1447 (const char *old_filename
, const char *new_filename
),
1448 _GL_ARG_NONNULL ((1, 2)));
1449 _GL_CXXALIAS_RPL (rename
, int,
1450 (const char *old_filename
, const char *new_filename
));
1452 _GL_CXXALIAS_SYS (rename
, int,
1453 (const char *old_filename
, const char *new_filename
));
1456 _GL_CXXALIASWARN (rename
);
1458 #elif defined GNULIB_POSIXCHECK
1460 /* Assume rename is always declared. */
1461 _GL_WARN_ON_USE (rename
, "rename is buggy on some platforms - "
1462 "use gnulib module rename for more portability");
1465 #if @GNULIB_RENAMEAT@
1466 # if @REPLACE_RENAMEAT@
1467 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1469 # define renameat rpl_renameat
1471 _GL_FUNCDECL_RPL (renameat
, int,
1472 (int fd1
, char const *file1
, int fd2
, char const *file2
),
1473 _GL_ARG_NONNULL ((2, 4)));
1474 _GL_CXXALIAS_RPL (renameat
, int,
1475 (int fd1
, char const *file1
, int fd2
, char const *file2
));
1477 # if !@HAVE_RENAMEAT@
1478 _GL_FUNCDECL_SYS (renameat
, int,
1479 (int fd1
, char const *file1
, int fd2
, char const *file2
),
1480 _GL_ARG_NONNULL ((2, 4)));
1482 _GL_CXXALIAS_SYS (renameat
, int,
1483 (int fd1
, char const *file1
, int fd2
, char const *file2
));
1485 _GL_CXXALIASWARN (renameat
);
1486 #elif defined GNULIB_POSIXCHECK
1488 # if HAVE_RAW_DECL_RENAMEAT
1489 _GL_WARN_ON_USE (renameat
, "renameat is not portable - "
1490 "use gnulib module renameat for portability");
1495 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
1496 # if defined __GNUC__ || defined __clang__
1497 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1499 /* Don't break __attribute__((format(scanf,M,N))). */
1500 # define scanf __scanf__
1502 _GL_FUNCDECL_RPL_1 (__scanf__
, int,
1503 (const char *restrict format
, ...)
1504 __asm__ (@ASM_SYMBOL_PREFIX@
1505 _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf
)),
1506 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1507 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
1508 _GL_CXXALIAS_RPL_1 (scanf
, __scanf__
, int, (const char *restrict format
, ...));
1510 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1512 # define scanf rpl_scanf
1514 _GL_FUNCDECL_RPL (scanf
, int, (const char *restrict format
, ...),
1515 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2)
1516 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
1517 _GL_CXXALIAS_RPL (scanf
, int, (const char *restrict format
, ...));
1520 _GL_CXXALIAS_SYS (scanf
, int, (const char *restrict format
, ...));
1523 _GL_CXXALIASWARN (scanf
);
1527 #if @GNULIB_SNZPRINTF@
1528 /* Prints formatted output to string STR. Similar to sprintf, but the
1529 additional parameter SIZE limits how much is written into STR.
1530 STR may be NULL, in which case nothing will be written.
1531 Returns the string length of the formatted string (which may be larger
1532 than SIZE). Upon failure, returns -1 with errno set.
1533 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
1534 Therefore, if the format string is valid and does not use %ls/%lc
1535 directives nor widths, the only possible failure code is ENOMEM. */
1536 _GL_FUNCDECL_SYS (snzprintf
, ptrdiff_t,
1537 (char *restrict str
, size_t size
,
1538 const char *restrict format
, ...),
1539 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1540 _GL_ARG_NONNULL ((3)));
1541 _GL_CXXALIAS_SYS (snzprintf
, ptrdiff_t,
1542 (char *restrict str
, size_t size
,
1543 const char *restrict format
, ...));
1546 #if @GNULIB_SNPRINTF@
1547 /* Prints formatted output to string STR. Similar to sprintf, but the
1548 additional parameter SIZE limits how much is written into STR.
1549 STR may be NULL, in which case nothing will be written.
1550 Returns the string length of the formatted string (which may be larger
1551 than SIZE). Upon failure, returns a negative value. */
1552 # if @REPLACE_SNPRINTF@
1553 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1554 # define snprintf rpl_snprintf
1556 # define GNULIB_overrides_snprintf 1
1557 _GL_FUNCDECL_RPL (snprintf
, int,
1558 (char *restrict str
, size_t size
,
1559 const char *restrict format
, ...),
1560 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1561 _GL_ARG_NONNULL ((3)));
1562 _GL_CXXALIAS_RPL (snprintf
, int,
1563 (char *restrict str
, size_t size
,
1564 const char *restrict format
, ...));
1566 # if !@HAVE_DECL_SNPRINTF@
1567 _GL_FUNCDECL_SYS (snprintf
, int,
1568 (char *restrict str
, size_t size
,
1569 const char *restrict format
, ...),
1570 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4)
1571 _GL_ARG_NONNULL ((3)));
1573 _GL_CXXALIAS_SYS (snprintf
, int,
1574 (char *restrict str
, size_t size
,
1575 const char *restrict format
, ...));
1578 _GL_CXXALIASWARN (snprintf
);
1580 #elif defined GNULIB_POSIXCHECK
1582 # if HAVE_RAW_DECL_SNPRINTF
1583 _GL_WARN_ON_USE (snprintf
, "snprintf is unportable - "
1584 "use gnulib module snprintf for portability");
1588 #if @GNULIB_SZPRINTF@
1589 /* Prints formatted output to string STR.
1590 Returns the string length of the formatted string. Upon failure,
1591 returns -1 with errno set.
1592 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
1593 Therefore, if the format string is valid and does not use %ls/%lc
1594 directives nor widths, the only possible failure code is ENOMEM. */
1595 _GL_FUNCDECL_SYS (szprintf
, ptrdiff_t,
1596 (char *restrict str
,
1597 const char *restrict format
, ...),
1598 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1599 _GL_ARG_NONNULL ((1, 2)));
1600 _GL_CXXALIAS_SYS (szprintf
, ptrdiff_t,
1601 (char *restrict str
,
1602 const char *restrict format
, ...));
1605 /* Some people would argue that all sprintf uses should be warned about
1606 (for example, OpenBSD issues a link warning for it),
1607 since it can cause security holes due to buffer overruns.
1608 However, we believe that sprintf can be used safely, and is more
1609 efficient than snprintf in those safe cases; and as proof of our
1610 belief, we use sprintf in several gnulib modules. So this header
1611 intentionally avoids adding a warning to sprintf except when
1612 GNULIB_POSIXCHECK is defined. */
1614 #if @GNULIB_SPRINTF_POSIX@
1615 /* Prints formatted output to string STR.
1616 Returns the string length of the formatted string. Upon failure,
1617 returns a negative value. */
1618 # if @REPLACE_SPRINTF@
1619 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1620 # define sprintf rpl_sprintf
1622 # define GNULIB_overrides_sprintf 1
1623 _GL_FUNCDECL_RPL (sprintf
, int,
1624 (char *restrict str
, const char *restrict format
, ...),
1625 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1626 _GL_ARG_NONNULL ((1, 2)));
1627 _GL_CXXALIAS_RPL (sprintf
, int,
1628 (char *restrict str
, const char *restrict format
, ...));
1630 _GL_CXXALIAS_SYS (sprintf
, int,
1631 (char *restrict str
, const char *restrict format
, ...));
1634 _GL_CXXALIASWARN (sprintf
);
1636 #elif defined GNULIB_POSIXCHECK
1638 /* Assume sprintf is always declared. */
1639 _GL_WARN_ON_USE (sprintf
, "sprintf is not always POSIX compliant - "
1640 "use gnulib module sprintf-posix for portable "
1641 "POSIX compliance");
1644 #if @GNULIB_MDA_TEMPNAM@
1645 /* On native Windows, map 'tempnam' to '_tempnam', so that -loldnames is not
1646 required. In C++ with GNULIB_NAMESPACE, avoid differences between
1647 platforms by defining GNULIB_NAMESPACE::tempnam always. */
1648 # if defined _WIN32 && !defined __CYGWIN__
1649 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1651 # define tempnam _tempnam
1653 _GL_CXXALIAS_MDA (tempnam
, char *, (const char *dir
, const char *prefix
));
1655 _GL_CXXALIAS_SYS (tempnam
, char *, (const char *dir
, const char *prefix
));
1657 _GL_CXXALIASWARN (tempnam
);
1660 #if @GNULIB_TMPFILE@
1661 # if @REPLACE_TMPFILE@
1662 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1663 # define tmpfile rpl_tmpfile
1665 _GL_FUNCDECL_RPL (tmpfile
, FILE *, (void),
1666 _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
1667 _GL_ATTRIBUTE_MALLOC
1668 _GL_ATTRIBUTE_NODISCARD
);
1669 _GL_CXXALIAS_RPL (tmpfile
, FILE *, (void));
1671 # if __GNUC__ >= 11 && !defined __clang__
1672 /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1673 _GL_FUNCDECL_SYS (tmpfile
, FILE *, (void),
1674 _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
1675 _GL_ATTRIBUTE_MALLOC
1676 _GL_ATTRIBUTE_NODISCARD
);
1678 _GL_CXXALIAS_SYS (tmpfile
, FILE *, (void));
1681 _GL_CXXALIASWARN (tmpfile
);
1684 # if @GNULIB_FCLOSE@ \
1685 && (__GNUC__ >= 11 && !defined __clang__) && !defined tmpfile
1686 /* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1687 _GL_FUNCDECL_SYS (tmpfile
, FILE *, (void),
1688 _GL_ATTRIBUTE_DEALLOC (fclose
, 1)
1689 _GL_ATTRIBUTE_MALLOC
);
1691 # if defined GNULIB_POSIXCHECK
1693 # if HAVE_RAW_DECL_TMPFILE
1694 _GL_WARN_ON_USE (tmpfile
, "tmpfile is not usable on mingw - "
1695 "use gnulib module tmpfile for portability");
1700 #if @GNULIB_VASZPRINTF@
1701 /* Prints formatted output to a string dynamically allocated with malloc().
1702 If the memory allocation succeeds, it stores the address of the string in
1703 *RESULT and returns the number of resulting bytes, excluding the trailing
1704 NUL. Upon memory allocation error, or some other error, it returns -1
1706 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
1707 Therefore, if the format string is valid and does not use %ls/%lc
1708 directives nor widths, the only possible failure code is ENOMEM. */
1709 _GL_FUNCDECL_SYS (aszprintf
, ptrdiff_t,
1710 (char **result
, const char *format
, ...),
1711 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1712 _GL_ARG_NONNULL ((1, 2))
1713 _GL_ATTRIBUTE_NODISCARD
);
1714 _GL_CXXALIAS_SYS (aszprintf
, ptrdiff_t,
1715 (char **result
, const char *format
, ...));
1716 _GL_FUNCDECL_SYS (vaszprintf
, ptrdiff_t,
1717 (char **result
, const char *format
, va_list args
),
1718 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1719 _GL_ARG_NONNULL ((1, 2))
1720 _GL_ATTRIBUTE_NODISCARD
);
1721 _GL_CXXALIAS_SYS (vaszprintf
, ptrdiff_t,
1722 (char **result
, const char *format
, va_list args
));
1725 #if @GNULIB_VASPRINTF@
1726 /* Write formatted output to a string dynamically allocated with malloc().
1727 If the memory allocation succeeds, store the address of the string in
1728 *RESULT and return the number of resulting bytes, excluding the trailing
1729 NUL. Upon memory allocation error, or some other error, return -1. */
1730 # if @REPLACE_VASPRINTF@
1731 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1732 # define asprintf rpl_asprintf
1734 # define GNULIB_overrides_asprintf
1735 _GL_FUNCDECL_RPL (asprintf
, int,
1736 (char **result
, const char *format
, ...),
1737 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1738 _GL_ARG_NONNULL ((1, 2))
1739 _GL_ATTRIBUTE_NODISCARD
);
1740 _GL_CXXALIAS_RPL (asprintf
, int,
1741 (char **result
, const char *format
, ...));
1743 # if !@HAVE_VASPRINTF@
1744 _GL_FUNCDECL_SYS (asprintf
, int,
1745 (char **result
, const char *format
, ...),
1746 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
1747 _GL_ARG_NONNULL ((1, 2))
1748 _GL_ATTRIBUTE_NODISCARD
);
1750 _GL_CXXALIAS_SYS (asprintf
, int,
1751 (char **result
, const char *format
, ...));
1753 _GL_CXXALIASWARN (asprintf
);
1754 # if @REPLACE_VASPRINTF@
1755 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1756 # define vasprintf rpl_vasprintf
1758 # define GNULIB_overrides_vasprintf 1
1759 _GL_FUNCDECL_RPL (vasprintf
, int,
1760 (char **result
, const char *format
, va_list args
),
1761 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1762 _GL_ARG_NONNULL ((1, 2))
1763 _GL_ATTRIBUTE_NODISCARD
);
1764 _GL_CXXALIAS_RPL (vasprintf
, int,
1765 (char **result
, const char *format
, va_list args
));
1767 # if !@HAVE_VASPRINTF@
1768 _GL_FUNCDECL_SYS (vasprintf
, int,
1769 (char **result
, const char *format
, va_list args
),
1770 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1771 _GL_ARG_NONNULL ((1, 2))
1772 _GL_ATTRIBUTE_NODISCARD
);
1774 _GL_CXXALIAS_SYS (vasprintf
, int,
1775 (char **result
, const char *format
, va_list args
));
1777 _GL_CXXALIASWARN (vasprintf
);
1780 #if @GNULIB_VDZPRINTF@
1781 /* Prints formatted output to file descriptor FD.
1782 Returns the number of bytes written to the file descriptor. Upon
1783 failure, returns -1 with errno set.
1784 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
1785 Therefore, if the format string is valid and does not use %ls/%lc
1786 directives nor widths, the only possible failure codes are ENOMEM
1787 and the possible failure codes from write(), excluding EINTR. */
1788 _GL_FUNCDECL_SYS (vdzprintf
, off64_t
,
1789 (int fd
, const char *restrict format
, va_list args
),
1790 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1791 _GL_ARG_NONNULL ((2)));
1792 _GL_CXXALIAS_SYS (vdzprintf
, off64_t
,
1793 (int fd
, const char *restrict format
, va_list args
));
1796 #if @GNULIB_VDPRINTF@
1797 /* Prints formatted output to file descriptor FD.
1798 Returns the number of bytes written to the file descriptor. Upon
1799 failure, returns a negative value. */
1800 # if @REPLACE_VDPRINTF@
1801 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1802 # define vdprintf rpl_vdprintf
1804 _GL_FUNCDECL_RPL (vdprintf
, int,
1805 (int fd
, const char *restrict format
, va_list args
),
1806 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1807 _GL_ARG_NONNULL ((2)));
1808 _GL_CXXALIAS_RPL (vdprintf
, int,
1809 (int fd
, const char *restrict format
, va_list args
));
1811 # if !@HAVE_VDPRINTF@
1812 _GL_FUNCDECL_SYS (vdprintf
, int,
1813 (int fd
, const char *restrict format
, va_list args
),
1814 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1815 _GL_ARG_NONNULL ((2)));
1817 /* Need to cast, because on Solaris, the third parameter will likely be
1819 _GL_CXXALIAS_SYS_CAST (vdprintf
, int,
1820 (int fd
, const char *restrict format
, va_list args
));
1823 _GL_CXXALIASWARN (vdprintf
);
1825 #elif defined GNULIB_POSIXCHECK
1827 # if HAVE_RAW_DECL_VDPRINTF
1828 _GL_WARN_ON_USE (vdprintf
, "vdprintf is unportable - "
1829 "use gnulib module vdprintf for portability");
1833 #if @GNULIB_VFZPRINTF@
1834 /* Prints formatted output to stream FP.
1835 Returns the number of bytes written to the stream. Upon failure,
1836 returns -1 with the stream's error indicator set.
1837 Failure cause EOVERFLOW can only occur when a width > INT_MAX is used.
1838 Therefore, if the format string is valid and does not use %ls/%lc
1839 directives nor widths, the only possible failure causes are ENOMEM
1840 and the possible failure causes from fwrite(). */
1841 _GL_FUNCDECL_SYS (vfzprintf
, off64_t
,
1843 const char *restrict format
, va_list args
),
1844 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1845 _GL_ARG_NONNULL ((1, 2)));
1846 _GL_CXXALIAS_SYS (vfzprintf
, off64_t
,
1848 const char *restrict format
, va_list args
));
1851 #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@
1852 /* Prints formatted output to stream FP.
1853 Returns the number of bytes written to the stream. Upon failure,
1854 returns a negative value with the stream's error indicator set. */
1855 # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \
1856 || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
1857 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1858 # define vfprintf rpl_vfprintf
1860 # define GNULIB_overrides_vfprintf 1
1861 # if @GNULIB_VFPRINTF_POSIX@
1862 _GL_FUNCDECL_RPL (vfprintf
, int,
1864 const char *restrict format
, va_list args
),
1865 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
1866 _GL_ARG_NONNULL ((1, 2)));
1868 _GL_FUNCDECL_RPL (vfprintf
, int,
1870 const char *restrict format
, va_list args
),
1871 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0)
1872 _GL_ARG_NONNULL ((1, 2)));
1874 _GL_CXXALIAS_RPL (vfprintf
, int,
1876 const char *restrict format
, va_list args
));
1878 /* Need to cast, because on Solaris, the third parameter is
1880 and GCC's fixincludes did not change this to __gnuc_va_list. */
1881 _GL_CXXALIAS_SYS_CAST (vfprintf
, int,
1883 const char *restrict format
, va_list args
));
1886 _GL_CXXALIASWARN (vfprintf
);
1889 #if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1890 # if !GNULIB_overrides_vfprintf
1893 /* Assume vfprintf is always declared. */
1894 _GL_WARN_ON_USE (vfprintf
, "vfprintf is not always POSIX compliant - "
1895 "use gnulib module vfprintf-posix for portable "
1896 "POSIX compliance");
1899 #if @GNULIB_VFSCANF@
1900 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
1901 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1903 # define vfscanf rpl_vfscanf
1905 _GL_FUNCDECL_RPL (vfscanf
, int,
1906 (FILE *restrict stream
,
1907 const char *restrict format
, va_list args
),
1908 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0)
1909 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_NODISCARD
);
1910 _GL_CXXALIAS_RPL (vfscanf
, int,
1911 (FILE *restrict stream
,
1912 const char *restrict format
, va_list args
));
1914 _GL_CXXALIAS_SYS (vfscanf
, int,
1915 (FILE *restrict stream
,
1916 const char *restrict format
, va_list args
));
1919 _GL_CXXALIASWARN (vfscanf
);
1923 #if @GNULIB_VZPRINTF@
1924 /* Prints formatted output to standard output.
1925 Returns the number of bytes written to standard output. Upon failure,
1926 returns -1 with stdout's error indicator set.
1927 Failure cause EOVERFLOW can only occur when a width > INT_MAX is used.
1928 Therefore, if the format string is valid and does not use %ls/%lc
1929 directives nor widths, the only possible failure causes are ENOMEM
1930 and the possible failure causes from fwrite(). */
1931 _GL_FUNCDECL_SYS (vzprintf
, off64_t
,
1932 (const char *restrict format
, va_list args
),
1933 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0)
1934 _GL_ARG_NONNULL ((1)));
1935 _GL_CXXALIAS_SYS (vzprintf
, off64_t
,
1936 (const char *restrict format
, va_list args
));
1939 #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@
1940 /* Prints formatted output to standard output.
1941 Returns the number of bytes written to standard output. Upon failure,
1942 returns a negative value with stdout's error indicator set. */
1943 # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \
1944 || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
1945 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1946 # define vprintf rpl_vprintf
1948 # define GNULIB_overrides_vprintf 1
1949 # if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@
1950 _GL_FUNCDECL_RPL (vprintf
, int, (const char *restrict format
, va_list args
),
1951 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0)
1952 _GL_ARG_NONNULL ((1)));
1954 _GL_FUNCDECL_RPL (vprintf
, int, (const char *restrict format
, va_list args
),
1955 _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0)
1956 _GL_ARG_NONNULL ((1)));
1958 _GL_CXXALIAS_RPL (vprintf
, int, (const char *restrict format
, va_list args
));
1960 /* Need to cast, because on Solaris, the second parameter is
1962 and GCC's fixincludes did not change this to __gnuc_va_list. */
1963 _GL_CXXALIAS_SYS_CAST (vprintf
, int,
1964 (const char *restrict format
, va_list args
));
1967 _GL_CXXALIASWARN (vprintf
);
1970 #if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK
1971 # if !GNULIB_overrides_vprintf
1974 /* Assume vprintf is always declared. */
1975 _GL_WARN_ON_USE (vprintf
, "vprintf is not always POSIX compliant - "
1976 "use gnulib module vprintf-posix for portable "
1977 "POSIX compliance");
1981 # if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@
1982 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1984 # define vscanf rpl_vscanf
1986 _GL_FUNCDECL_RPL (vscanf
, int, (const char *restrict format
, va_list args
),
1987 _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0)
1988 _GL_ARG_NONNULL ((1)) _GL_ATTRIBUTE_NODISCARD
);
1989 _GL_CXXALIAS_RPL (vscanf
, int, (const char *restrict format
, va_list args
));
1991 _GL_CXXALIAS_SYS (vscanf
, int, (const char *restrict format
, va_list args
));
1994 _GL_CXXALIASWARN (vscanf
);
1998 #if @GNULIB_VSNZPRINTF@
1999 /* Prints formatted output to string STR. Similar to sprintf, but the
2000 additional parameter SIZE limits how much is written into STR.
2001 STR may be NULL, in which case nothing will be written.
2002 Returns the string length of the formatted string (which may be larger
2003 than SIZE). Upon failure, returns -1 with errno set.
2004 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
2005 Therefore, if the format string is valid and does not use %ls/%lc
2006 directives nor widths, the only possible failure code is ENOMEM. */
2007 _GL_FUNCDECL_SYS (vsnzprintf
, ptrdiff_t,
2008 (char *restrict str
, size_t size
,
2009 const char *restrict format
, va_list args
),
2010 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
2011 _GL_ARG_NONNULL ((3)));
2012 _GL_CXXALIAS_SYS (vsnzprintf
, ptrdiff_t,
2013 (char *restrict str
, size_t size
,
2014 const char *restrict format
, va_list args
));
2017 #if @GNULIB_VSNPRINTF@
2018 /* Prints formatted output to string STR. Similar to vsprintf, but the
2019 additional parameter SIZE limits how much is written into STR.
2020 STR may be NULL, in which case nothing will be written.
2021 Returns the string length of the formatted string (which may be larger
2022 than SIZE). Upon failure, returns a negative value. */
2023 # if @REPLACE_VSNPRINTF@
2024 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2025 # define vsnprintf rpl_vsnprintf
2027 # define GNULIB_overrides_vsnprintf 1
2028 _GL_FUNCDECL_RPL (vsnprintf
, int,
2029 (char *restrict str
, size_t size
,
2030 const char *restrict format
, va_list args
),
2031 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
2032 _GL_ARG_NONNULL ((3)));
2033 _GL_CXXALIAS_RPL (vsnprintf
, int,
2034 (char *restrict str
, size_t size
,
2035 const char *restrict format
, va_list args
));
2037 # if !@HAVE_DECL_VSNPRINTF@
2038 _GL_FUNCDECL_SYS (vsnprintf
, int,
2039 (char *restrict str
, size_t size
,
2040 const char *restrict format
, va_list args
),
2041 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0)
2042 _GL_ARG_NONNULL ((3)));
2044 _GL_CXXALIAS_SYS (vsnprintf
, int,
2045 (char *restrict str
, size_t size
,
2046 const char *restrict format
, va_list args
));
2049 _GL_CXXALIASWARN (vsnprintf
);
2051 #elif defined GNULIB_POSIXCHECK
2053 # if HAVE_RAW_DECL_VSNPRINTF
2054 _GL_WARN_ON_USE (vsnprintf
, "vsnprintf is unportable - "
2055 "use gnulib module vsnprintf for portability");
2059 #if @GNULIB_VSZPRINTF@
2060 /* Prints formatted output to string STR.
2061 Returns the string length of the formatted string. Upon failure,
2062 returns -1 with errno set.
2063 Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
2064 Therefore, if the format string is valid and does not use %ls/%lc
2065 directives nor widths, the only possible failure code is ENOMEM. */
2066 _GL_FUNCDECL_SYS (vszprintf
, ptrdiff_t,
2067 (char *restrict str
,
2068 const char *restrict format
, va_list args
),
2069 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
2070 _GL_ARG_NONNULL ((1, 2)));
2071 _GL_CXXALIAS_SYS (vszprintf
, ptrdiff_t,
2072 (char *restrict str
,
2073 const char *restrict format
, va_list args
));
2076 #if @GNULIB_VSPRINTF_POSIX@
2077 /* Prints formatted output to string STR.
2078 Returns the string length of the formatted string. Upon failure,
2079 returns a negative value. */
2080 # if @REPLACE_VSPRINTF@
2081 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
2082 # define vsprintf rpl_vsprintf
2084 # define GNULIB_overrides_vsprintf 1
2085 _GL_FUNCDECL_RPL (vsprintf
, int,
2086 (char *restrict str
,
2087 const char *restrict format
, va_list args
),
2088 _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
2089 _GL_ARG_NONNULL ((1, 2)));
2090 _GL_CXXALIAS_RPL (vsprintf
, int,
2091 (char *restrict str
,
2092 const char *restrict format
, va_list args
));
2094 /* Need to cast, because on Solaris, the third parameter is
2096 and GCC's fixincludes did not change this to __gnuc_va_list. */
2097 _GL_CXXALIAS_SYS_CAST (vsprintf
, int,
2098 (char *restrict str
,
2099 const char *restrict format
, va_list args
));
2102 _GL_CXXALIASWARN (vsprintf
);
2104 #elif defined GNULIB_POSIXCHECK
2106 /* Assume vsprintf is always declared. */
2107 _GL_WARN_ON_USE (vsprintf
, "vsprintf is not always POSIX compliant - "
2108 "use gnulib module vsprintf-posix for portable "
2109 "POSIX compliance");
2112 #endif /* _@GUARD_PREFIX@_STDIO_H */
2113 #endif /* _@GUARD_PREFIX@_STDIO_H */