summaryrefslogtreecommitdiffstats
path: root/gl/stdio.in.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/stdio.in.h')
-rw-r--r--gl/stdio.in.h172
1 files changed, 152 insertions, 20 deletions
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 59cbea3..35b9f74 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -1,6 +1,6 @@
1/* A GNU-like <stdio.h>. 1/* A GNU-like <stdio.h>.
2 2
3 Copyright (C) 2004, 2007-2023 Free Software Foundation, Inc. 3 Copyright (C) 2004, 2007-2024 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 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 6 it under the terms of the GNU Lesser General Public License as
@@ -36,6 +36,18 @@
36 36
37#ifndef _@GUARD_PREFIX@_STDIO_H 37#ifndef _@GUARD_PREFIX@_STDIO_H
38 38
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>
43# endif
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
48# endif
49#endif
50
39#define _GL_ALREADY_INCLUDING_STDIO_H 51#define _GL_ALREADY_INCLUDING_STDIO_H
40 52
41/* The include_next requires a split double-inclusion guard. */ 53/* The include_next requires a split double-inclusion guard. */
@@ -43,9 +55,21 @@
43 55
44#undef _GL_ALREADY_INCLUDING_STDIO_H 56#undef _GL_ALREADY_INCLUDING_STDIO_H
45 57
58#ifdef _GL_DEFINED__POSIX_C_SOURCE
59# undef _GL_DEFINED__POSIX_C_SOURCE
60# undef _POSIX_C_SOURCE
61#endif
62
46#ifndef _@GUARD_PREFIX@_STDIO_H 63#ifndef _@GUARD_PREFIX@_STDIO_H
47#define _@GUARD_PREFIX@_STDIO_H 64#define _@GUARD_PREFIX@_STDIO_H
48 65
66/* This file uses _GL_ATTRIBUTE_DEALLOC, _GL_ATTRIBUTE_FORMAT,
67 _GL_ATTRIBUTE_MALLOC, _GL_ATTRIBUTE_NOTHROW, GNULIB_POSIXCHECK,
68 HAVE_RAW_DECL_*. */
69#if !_GL_CONFIG_H_INCLUDED
70 #error "Please include config.h first."
71#endif
72
49/* Get va_list. Needed on many systems, including glibc 2.8. */ 73/* Get va_list. Needed on many systems, including glibc 2.8. */
50#include <stdarg.h> 74#include <stdarg.h>
51 75
@@ -116,6 +140,38 @@
116# endif 140# endif
117#endif 141#endif
118 142
143/* _GL_ATTRIBUTE_MALLOC declares that the function returns a pointer to freshly
144 allocated memory. */
145#ifndef _GL_ATTRIBUTE_MALLOC
146# if __GNUC__ >= 3 || defined __clang__
147# define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
148# else
149# define _GL_ATTRIBUTE_MALLOC
150# endif
151#endif
152
153/* _GL_ATTRIBUTE_NOTHROW declares that the function does not throw exceptions.
154 */
155#ifndef _GL_ATTRIBUTE_NOTHROW
156# if defined __cplusplus
157# if (__GNUC__ + (__GNUC_MINOR__ >= 8) > 2) || __clang_major >= 4
158# if __cplusplus >= 201103L
159# define _GL_ATTRIBUTE_NOTHROW noexcept (true)
160# else
161# define _GL_ATTRIBUTE_NOTHROW throw ()
162# endif
163# else
164# define _GL_ATTRIBUTE_NOTHROW
165# endif
166# else
167# if (__GNUC__ + (__GNUC_MINOR__ >= 3) > 3) || defined __clang__
168# define _GL_ATTRIBUTE_NOTHROW __attribute__ ((__nothrow__))
169# else
170# define _GL_ATTRIBUTE_NOTHROW
171# endif
172# endif
173#endif
174
119/* An __attribute__ __format__ specifier for a function that takes a format 175/* An __attribute__ __format__ specifier for a function that takes a format
120 string and arguments, where the format string directives are the ones 176 string and arguments, where the format string directives are the ones
121 standardized by ISO C99 and POSIX. 177 standardized by ISO C99 and POSIX.
@@ -193,6 +249,36 @@
193# undef putc_unlocked 249# undef putc_unlocked
194#endif 250#endif
195 251
252
253/* Maximum number of characters produced by printing a NaN value. */
254#ifndef _PRINTF_NAN_LEN_MAX
255# if defined __FreeBSD__ || defined __DragonFly__ \
256 || defined __NetBSD__ \
257 || (defined __APPLE__ && defined __MACH__)
258/* On BSD systems, a NaN value prints as just "nan", without a sign. */
259# define _PRINTF_NAN_LEN_MAX 3
260# elif (__GLIBC__ >= 2) || MUSL_LIBC || defined __OpenBSD__ || defined __sun || defined __CYGWIN__
261/* glibc, musl libc, OpenBSD, Solaris libc, and Cygwin produce "[-]nan". */
262# define _PRINTF_NAN_LEN_MAX 4
263# elif defined _AIX
264/* AIX produces "[-]NaNQ". */
265# define _PRINTF_NAN_LEN_MAX 5
266# elif defined _WIN32 && !defined __CYGWIN__
267/* On native Windows, the output can be:
268 - with MSVC ucrt: "[-]nan" or "[-]nan(ind)" or "[-]nan(snan)",
269 - with mingw: "[-]1.#IND" or "[-]1.#QNAN". */
270# define _PRINTF_NAN_LEN_MAX 10
271# elif defined __sgi
272/* On IRIX, the output typically is "[-]nan0xNNNNNNNN" with 8 hexadecimal
273 digits. */
274# define _PRINTF_NAN_LEN_MAX 14
275# else
276/* We don't know, but 32 should be a safe maximum. */
277# define _PRINTF_NAN_LEN_MAX 32
278# endif
279#endif
280
281
196#if @GNULIB_DPRINTF@ 282#if @GNULIB_DPRINTF@
197# if @REPLACE_DPRINTF@ 283# if @REPLACE_DPRINTF@
198# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 284# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -210,7 +296,9 @@ _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...)
210# endif 296# endif
211_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...)); 297_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...));
212# endif 298# endif
299# if __GLIBC__ >= 2
213_GL_CXXALIASWARN (dprintf); 300_GL_CXXALIASWARN (dprintf);
301# endif
214#elif defined GNULIB_POSIXCHECK 302#elif defined GNULIB_POSIXCHECK
215# undef dprintf 303# undef dprintf
216# if HAVE_RAW_DECL_DPRINTF 304# if HAVE_RAW_DECL_DPRINTF
@@ -273,7 +361,8 @@ _GL_CXXALIASWARN (fcloseall);
273# endif 361# endif
274_GL_FUNCDECL_RPL (fdopen, FILE *, 362_GL_FUNCDECL_RPL (fdopen, FILE *,
275 (int fd, const char *mode) 363 (int fd, const char *mode)
276 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 364 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
365 _GL_ATTRIBUTE_MALLOC);
277_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode)); 366_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
278# elif defined _WIN32 && !defined __CYGWIN__ 367# elif defined _WIN32 && !defined __CYGWIN__
279# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 368# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -284,9 +373,18 @@ _GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode));
284# else 373# else
285# if __GNUC__ >= 11 374# if __GNUC__ >= 11
286/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ 375/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
376# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
287_GL_FUNCDECL_SYS (fdopen, FILE *, 377_GL_FUNCDECL_SYS (fdopen, FILE *,
288 (int fd, const char *mode) 378 (int fd, const char *mode)
289 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 379 _GL_ATTRIBUTE_NOTHROW
380 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
381 _GL_ATTRIBUTE_MALLOC);
382# else
383_GL_FUNCDECL_SYS (fdopen, FILE *,
384 (int fd, const char *mode)
385 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
386 _GL_ATTRIBUTE_MALLOC);
387# endif
290# endif 388# endif
291_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); 389_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
292# endif 390# endif
@@ -294,9 +392,18 @@ _GL_CXXALIASWARN (fdopen);
294#else 392#else
295# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fdopen 393# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined fdopen
296/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */ 394/* For -Wmismatched-dealloc: Associate fdopen with fclose or rpl_fclose. */
395# if __GLIBC__ + (__GLIBC_MINOR__ >= 2) > 2
396_GL_FUNCDECL_SYS (fdopen, FILE *,
397 (int fd, const char *mode)
398 _GL_ATTRIBUTE_NOTHROW
399 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
400 _GL_ATTRIBUTE_MALLOC);
401# else
297_GL_FUNCDECL_SYS (fdopen, FILE *, 402_GL_FUNCDECL_SYS (fdopen, FILE *,
298 (int fd, const char *mode) 403 (int fd, const char *mode)
299 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 404 _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
405 _GL_ATTRIBUTE_MALLOC);
406# endif
300# endif 407# endif
301# if defined GNULIB_POSIXCHECK 408# if defined GNULIB_POSIXCHECK
302# undef fdopen 409# undef fdopen
@@ -407,7 +514,8 @@ _GL_CXXALIASWARN (fileno);
407# endif 514# endif
408_GL_FUNCDECL_RPL (fopen, FILE *, 515_GL_FUNCDECL_RPL (fopen, FILE *,
409 (const char *restrict filename, const char *restrict mode) 516 (const char *restrict filename, const char *restrict mode)
410 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 517 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1)
518 _GL_ATTRIBUTE_MALLOC);
411_GL_CXXALIAS_RPL (fopen, FILE *, 519_GL_CXXALIAS_RPL (fopen, FILE *,
412 (const char *restrict filename, const char *restrict mode)); 520 (const char *restrict filename, const char *restrict mode));
413# else 521# else
@@ -799,14 +907,14 @@ _GL_CXXALIAS_SYS (fwrite, size_t,
799 && !defined __cplusplus) 907 && !defined __cplusplus)
800# undef fwrite 908# undef fwrite
801# undef fwrite_unlocked 909# undef fwrite_unlocked
802extern size_t __REDIRECT (rpl_fwrite, 910_GL_EXTERN_C size_t __REDIRECT (rpl_fwrite,
803 (const void *__restrict, size_t, size_t, 911 (const void *__restrict, size_t, size_t,
804 FILE *__restrict), 912 FILE *__restrict),
805 fwrite); 913 fwrite);
806extern size_t __REDIRECT (rpl_fwrite_unlocked, 914_GL_EXTERN_C size_t __REDIRECT (rpl_fwrite_unlocked,
807 (const void *__restrict, size_t, size_t, 915 (const void *__restrict, size_t, size_t,
808 FILE *__restrict), 916 FILE *__restrict),
809 fwrite_unlocked); 917 fwrite_unlocked);
810# define fwrite rpl_fwrite 918# define fwrite rpl_fwrite
811# define fwrite_unlocked rpl_fwrite_unlocked 919# define fwrite_unlocked rpl_fwrite_unlocked
812# endif 920# endif
@@ -882,7 +990,9 @@ _GL_CXXALIAS_SYS (getdelim, ssize_t,
882 int delimiter, 990 int delimiter,
883 FILE *restrict stream)); 991 FILE *restrict stream));
884# endif 992# endif
993# if __GLIBC__ >= 2
885_GL_CXXALIASWARN (getdelim); 994_GL_CXXALIASWARN (getdelim);
995# endif
886#elif defined GNULIB_POSIXCHECK 996#elif defined GNULIB_POSIXCHECK
887# undef getdelim 997# undef getdelim
888# if HAVE_RAW_DECL_GETDELIM 998# if HAVE_RAW_DECL_GETDELIM
@@ -921,7 +1031,7 @@ _GL_CXXALIAS_SYS (getline, ssize_t,
921 (char **restrict lineptr, size_t *restrict linesize, 1031 (char **restrict lineptr, size_t *restrict linesize,
922 FILE *restrict stream)); 1032 FILE *restrict stream));
923# endif 1033# endif
924# if @HAVE_DECL_GETLINE@ 1034# if __GLIBC__ >= 2 && @HAVE_DECL_GETLINE@
925_GL_CXXALIASWARN (getline); 1035_GL_CXXALIASWARN (getline);
926# endif 1036# endif
927#elif defined GNULIB_POSIXCHECK 1037#elif defined GNULIB_POSIXCHECK
@@ -951,9 +1061,17 @@ _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
951# endif 1061# endif
952_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream)); 1062_GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
953# else 1063# else
1064# if @HAVE_DECL_GETW@
1065# if defined __APPLE__ && defined __MACH__
1066/* The presence of the declaration depends on _POSIX_C_SOURCE. */
1067_GL_FUNCDECL_SYS (getw, int, (FILE *restrict stream));
1068# endif
954_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream)); 1069_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
1070# endif
955# endif 1071# endif
1072# if __GLIBC__ >= 2
956_GL_CXXALIASWARN (getw); 1073_GL_CXXALIASWARN (getw);
1074# endif
957#endif 1075#endif
958 1076
959#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ 1077#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
@@ -1052,13 +1170,15 @@ _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
1052# endif 1170# endif
1053_GL_FUNCDECL_RPL (popen, FILE *, 1171_GL_FUNCDECL_RPL (popen, FILE *,
1054 (const char *cmd, const char *mode) 1172 (const char *cmd, const char *mode)
1055 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); 1173 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)
1174 _GL_ATTRIBUTE_MALLOC);
1056_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); 1175_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
1057# else 1176# else
1058# if !@HAVE_POPEN@ || __GNUC__ >= 11 1177# if !@HAVE_POPEN@ || __GNUC__ >= 11
1059_GL_FUNCDECL_SYS (popen, FILE *, 1178_GL_FUNCDECL_SYS (popen, FILE *,
1060 (const char *cmd, const char *mode) 1179 (const char *cmd, const char *mode)
1061 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); 1180 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)
1181 _GL_ATTRIBUTE_MALLOC);
1062# endif 1182# endif
1063_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); 1183_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
1064# endif 1184# endif
@@ -1068,7 +1188,8 @@ _GL_CXXALIASWARN (popen);
1068/* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */ 1188/* For -Wmismatched-dealloc: Associate popen with pclose or rpl_pclose. */
1069_GL_FUNCDECL_SYS (popen, FILE *, 1189_GL_FUNCDECL_SYS (popen, FILE *,
1070 (const char *cmd, const char *mode) 1190 (const char *cmd, const char *mode)
1071 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)); 1191 _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1)
1192 _GL_ATTRIBUTE_MALLOC);
1072# endif 1193# endif
1073# if defined GNULIB_POSIXCHECK 1194# if defined GNULIB_POSIXCHECK
1074# undef popen 1195# undef popen
@@ -1190,9 +1311,17 @@ _GL_CXXALIASWARN (puts);
1190# endif 1311# endif
1191_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream)); 1312_GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
1192# else 1313# else
1314# if @HAVE_DECL_PUTW@
1315# if defined __APPLE__ && defined __MACH__
1316/* The presence of the declaration depends on _POSIX_C_SOURCE. */
1317_GL_FUNCDECL_SYS (putw, int, (int w, FILE *restrict stream));
1318# endif
1193_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream)); 1319_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
1320# endif
1194# endif 1321# endif
1322# if __GLIBC__ >= 2
1195_GL_CXXALIASWARN (putw); 1323_GL_CXXALIASWARN (putw);
1324# endif
1196#endif 1325#endif
1197 1326
1198#if @GNULIB_REMOVE@ 1327#if @GNULIB_REMOVE@
@@ -1398,13 +1527,15 @@ _GL_CXXALIASWARN (tempnam);
1398# define tmpfile rpl_tmpfile 1527# define tmpfile rpl_tmpfile
1399# endif 1528# endif
1400_GL_FUNCDECL_RPL (tmpfile, FILE *, (void) 1529_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)
1401 _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 1530 _GL_ATTRIBUTE_DEALLOC (fclose, 1)
1531 _GL_ATTRIBUTE_MALLOC);
1402_GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); 1532_GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
1403# else 1533# else
1404# if __GNUC__ >= 11 1534# if __GNUC__ >= 11
1405/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */ 1535/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1406_GL_FUNCDECL_SYS (tmpfile, FILE *, (void) 1536_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1407 _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 1537 _GL_ATTRIBUTE_DEALLOC (fclose, 1)
1538 _GL_ATTRIBUTE_MALLOC);
1408# endif 1539# endif
1409_GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); 1540_GL_CXXALIAS_SYS (tmpfile, FILE *, (void));
1410# endif 1541# endif
@@ -1415,7 +1546,8 @@ _GL_CXXALIASWARN (tmpfile);
1415# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile 1546# if @GNULIB_FCLOSE@ && __GNUC__ >= 11 && !defined tmpfile
1416/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */ 1547/* For -Wmismatched-dealloc: Associate tmpfile with fclose or rpl_fclose. */
1417_GL_FUNCDECL_SYS (tmpfile, FILE *, (void) 1548_GL_FUNCDECL_SYS (tmpfile, FILE *, (void)
1418 _GL_ATTRIBUTE_DEALLOC (fclose, 1)); 1549 _GL_ATTRIBUTE_DEALLOC (fclose, 1)
1550 _GL_ATTRIBUTE_MALLOC);
1419# endif 1551# endif
1420# if defined GNULIB_POSIXCHECK 1552# if defined GNULIB_POSIXCHECK
1421# undef tmpfile 1553# undef tmpfile