| 1 |
/* A GNU-like <stdio.h>. |
| 2 |
|
| 3 |
Copyright (C) 2004, 2007-2020 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU General Public License as published by |
| 7 |
the Free Software Foundation; either version 3, or (at your option) |
| 8 |
any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with this program; if not, see <https://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
#if __GNUC__ >= 3 |
| 19 |
@PRAGMA_SYSTEM_HEADER@ |
| 20 |
#endif |
| 21 |
@PRAGMA_COLUMNS@ |
| 22 |
|
| 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. */ |
| 31 |
|
| 32 |
#@INCLUDE_NEXT@ @NEXT_STDIO_H@ |
| 33 |
|
| 34 |
#else |
| 35 |
/* Normal invocation convention. */ |
| 36 |
|
| 37 |
#ifndef _@GUARD_PREFIX@_STDIO_H |
| 38 |
|
| 39 |
#define _GL_ALREADY_INCLUDING_STDIO_H |
| 40 |
|
| 41 |
/* The include_next requires a split double-inclusion guard. */ |
| 42 |
#@INCLUDE_NEXT@ @NEXT_STDIO_H@ |
| 43 |
|
| 44 |
#undef _GL_ALREADY_INCLUDING_STDIO_H |
| 45 |
|
| 46 |
#ifndef _@GUARD_PREFIX@_STDIO_H |
| 47 |
#define _@GUARD_PREFIX@_STDIO_H |
| 48 |
|
| 49 |
/* Get va_list. Needed on many systems, including glibc 2.8. */ |
| 50 |
#include <stdarg.h> |
| 51 |
|
| 52 |
#include <stddef.h> |
| 53 |
|
| 54 |
/* Get off_t and ssize_t. Needed on many systems, including glibc 2.8 |
| 55 |
and eglibc 2.11.2. |
| 56 |
May also define off_t to a 64-bit type on native Windows. */ |
| 57 |
#include <sys/types.h> |
| 58 |
|
| 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. |
| 62 |
We enable _GL_ATTRIBUTE_FORMAT only if these are supported too, because |
| 63 |
gnulib and libintl do '#define printf __printf__' when they override |
| 64 |
the 'printf' function. */ |
| 65 |
#ifndef _GL_ATTRIBUTE_FORMAT |
| 66 |
# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || defined __clang__ |
| 67 |
# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec)) |
| 68 |
# else |
| 69 |
# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */ |
| 70 |
# endif |
| 71 |
#endif |
| 72 |
|
| 73 |
/* _GL_ATTRIBUTE_FORMAT_PRINTF |
| 74 |
indicates to GCC that the function takes a format string and arguments, |
| 75 |
where the format string directives are the ones standardized by ISO C99 |
| 76 |
and POSIX. */ |
| 77 |
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) |
| 78 |
# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ |
| 79 |
_GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) |
| 80 |
#else |
| 81 |
# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ |
| 82 |
_GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) |
| 83 |
#endif |
| 84 |
|
| 85 |
/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, |
| 86 |
except that it indicates to GCC that the supported format string directives |
| 87 |
are the ones of the system printf(), rather than the ones standardized by |
| 88 |
ISO C99 and POSIX. */ |
| 89 |
#if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU |
| 90 |
# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ |
| 91 |
_GL_ATTRIBUTE_FORMAT_PRINTF (formatstring_parameter, first_argument) |
| 92 |
#else |
| 93 |
# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ |
| 94 |
_GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) |
| 95 |
#endif |
| 96 |
|
| 97 |
/* _GL_ATTRIBUTE_FORMAT_SCANF |
| 98 |
indicates to GCC that the function takes a format string and arguments, |
| 99 |
where the format string directives are the ones standardized by ISO C99 |
| 100 |
and POSIX. */ |
| 101 |
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) |
| 102 |
# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ |
| 103 |
_GL_ATTRIBUTE_FORMAT ((__gnu_scanf__, formatstring_parameter, first_argument)) |
| 104 |
#else |
| 105 |
# define _GL_ATTRIBUTE_FORMAT_SCANF(formatstring_parameter, first_argument) \ |
| 106 |
_GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) |
| 107 |
#endif |
| 108 |
|
| 109 |
/* _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_SCANF, |
| 110 |
except that it indicates to GCC that the supported format string directives |
| 111 |
are the ones of the system scanf(), rather than the ones standardized by |
| 112 |
ISO C99 and POSIX. */ |
| 113 |
#define _GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM(formatstring_parameter, first_argument) \ |
| 114 |
_GL_ATTRIBUTE_FORMAT ((__scanf__, formatstring_parameter, first_argument)) |
| 115 |
|
| 116 |
/* Solaris 10 and NetBSD 7.0 declare renameat in <unistd.h>, not in <stdio.h>. */ |
| 117 |
/* But in any case avoid namespace pollution on glibc systems. */ |
| 118 |
#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && (defined __sun || defined __NetBSD__) \ |
| 119 |
&& ! defined __GLIBC__ |
| 120 |
# include <unistd.h> |
| 121 |
#endif |
| 122 |
|
| 123 |
/* Android 4.3 declares renameat in <sys/stat.h>, not in <stdio.h>. */ |
| 124 |
/* But in any case avoid namespace pollution on glibc systems. */ |
| 125 |
#if (@GNULIB_RENAMEAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \ |
| 126 |
&& ! defined __GLIBC__ |
| 127 |
# include <sys/stat.h> |
| 128 |
#endif |
| 129 |
|
| 130 |
/* MSVC declares 'perror' in <stdlib.h>, not in <stdio.h>. We must include |
| 131 |
it before we #define perror rpl_perror. */ |
| 132 |
/* But in any case avoid namespace pollution on glibc systems. */ |
| 133 |
#if (@GNULIB_PERROR@ || defined GNULIB_POSIXCHECK) \ |
| 134 |
&& (defined _WIN32 && ! defined __CYGWIN__) \ |
| 135 |
&& ! defined __GLIBC__ |
| 136 |
# include <stdlib.h> |
| 137 |
#endif |
| 138 |
|
| 139 |
/* MSVC declares 'remove' in <io.h>, not in <stdio.h>. We must include |
| 140 |
it before we #define remove rpl_remove. */ |
| 141 |
/* MSVC declares 'rename' in <io.h>, not in <stdio.h>. We must include |
| 142 |
it before we #define rename rpl_rename. */ |
| 143 |
/* But in any case avoid namespace pollution on glibc systems. */ |
| 144 |
#if (@GNULIB_REMOVE@ || @GNULIB_RENAME@ || defined GNULIB_POSIXCHECK) \ |
| 145 |
&& (defined _WIN32 && ! defined __CYGWIN__) \ |
| 146 |
&& ! defined __GLIBC__ |
| 147 |
# include <io.h> |
| 148 |
#endif |
| 149 |
|
| 150 |
|
| 151 |
/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
| 152 |
|
| 153 |
/* The definition of _GL_ARG_NONNULL is copied here. */ |
| 154 |
|
| 155 |
/* The definition of _GL_WARN_ON_USE is copied here. */ |
| 156 |
|
| 157 |
/* Macros for stringification. */ |
| 158 |
#define _GL_STDIO_STRINGIZE(token) #token |
| 159 |
#define _GL_STDIO_MACROEXPAND_AND_STRINGIZE(token) _GL_STDIO_STRINGIZE(token) |
| 160 |
|
| 161 |
/* When also using extern inline, suppress the use of static inline in |
| 162 |
standard headers of problematic Apple configurations, as Libc at |
| 163 |
least through Libc-825.26 (2013-04-09) mishandles it; see, e.g., |
| 164 |
<https://lists.gnu.org/r/bug-gnulib/2012-12/msg00023.html>. |
| 165 |
Perhaps Apple will fix this some day. */ |
| 166 |
#if (defined _GL_EXTERN_INLINE_IN_USE && defined __APPLE__ \ |
| 167 |
&& defined __GNUC__ && defined __STDC__) |
| 168 |
# undef putc_unlocked |
| 169 |
#endif |
| 170 |
|
| 171 |
#if @GNULIB_DPRINTF@ |
| 172 |
# if @REPLACE_DPRINTF@ |
| 173 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 174 |
# define dprintf rpl_dprintf |
| 175 |
# endif |
| 176 |
_GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...) |
| 177 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 178 |
_GL_ARG_NONNULL ((2))); |
| 179 |
_GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...)); |
| 180 |
# else |
| 181 |
# if !@HAVE_DPRINTF@ |
| 182 |
_GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...) |
| 183 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 184 |
_GL_ARG_NONNULL ((2))); |
| 185 |
# endif |
| 186 |
_GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...)); |
| 187 |
# endif |
| 188 |
_GL_CXXALIASWARN (dprintf); |
| 189 |
#elif defined GNULIB_POSIXCHECK |
| 190 |
# undef dprintf |
| 191 |
# if HAVE_RAW_DECL_DPRINTF |
| 192 |
_GL_WARN_ON_USE (dprintf, "dprintf is unportable - " |
| 193 |
"use gnulib module dprintf for portability"); |
| 194 |
# endif |
| 195 |
#endif |
| 196 |
|
| 197 |
#if @GNULIB_FCLOSE@ |
| 198 |
/* Close STREAM and its underlying file descriptor. */ |
| 199 |
# if @REPLACE_FCLOSE@ |
| 200 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 201 |
# define fclose rpl_fclose |
| 202 |
# endif |
| 203 |
_GL_FUNCDECL_RPL (fclose, int, (FILE *stream) _GL_ARG_NONNULL ((1))); |
| 204 |
_GL_CXXALIAS_RPL (fclose, int, (FILE *stream)); |
| 205 |
# else |
| 206 |
_GL_CXXALIAS_SYS (fclose, int, (FILE *stream)); |
| 207 |
# endif |
| 208 |
# if __GLIBC__ >= 2 |
| 209 |
_GL_CXXALIASWARN (fclose); |
| 210 |
# endif |
| 211 |
#elif defined GNULIB_POSIXCHECK |
| 212 |
# undef fclose |
| 213 |
/* Assume fclose is always declared. */ |
| 214 |
_GL_WARN_ON_USE (fclose, "fclose is not always POSIX compliant - " |
| 215 |
"use gnulib module fclose for portable POSIX compliance"); |
| 216 |
#endif |
| 217 |
|
| 218 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 219 |
# undef fcloseall |
| 220 |
# define fcloseall _fcloseall |
| 221 |
#endif |
| 222 |
|
| 223 |
#if @GNULIB_FDOPEN@ |
| 224 |
# if @REPLACE_FDOPEN@ |
| 225 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 226 |
# undef fdopen |
| 227 |
# define fdopen rpl_fdopen |
| 228 |
# endif |
| 229 |
_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode) |
| 230 |
_GL_ARG_NONNULL ((2))); |
| 231 |
_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode)); |
| 232 |
# elif defined _WIN32 && !defined __CYGWIN__ |
| 233 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 234 |
# undef fdopen |
| 235 |
# define fdopen _fdopen |
| 236 |
# endif |
| 237 |
_GL_CXXALIAS_MDA (fdopen, FILE *, (int fd, const char *mode)); |
| 238 |
# else |
| 239 |
_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode)); |
| 240 |
# endif |
| 241 |
_GL_CXXALIASWARN (fdopen); |
| 242 |
#elif defined GNULIB_POSIXCHECK |
| 243 |
# undef fdopen |
| 244 |
/* Assume fdopen is always declared. */ |
| 245 |
_GL_WARN_ON_USE (fdopen, "fdopen on native Windows platforms is not POSIX compliant - " |
| 246 |
"use gnulib module fdopen for portability"); |
| 247 |
#elif defined _WIN32 && !defined __CYGWIN__ |
| 248 |
# undef fdopen |
| 249 |
# define fdopen _fdopen |
| 250 |
#endif |
| 251 |
|
| 252 |
#if @GNULIB_FFLUSH@ |
| 253 |
/* Flush all pending data on STREAM according to POSIX rules. Both |
| 254 |
output and seekable input streams are supported. |
| 255 |
Note! LOSS OF DATA can occur if fflush is applied on an input stream |
| 256 |
that is _not_seekable_ or on an update stream that is _not_seekable_ |
| 257 |
and in which the most recent operation was input. Seekability can |
| 258 |
be tested with lseek(fileno(fp),0,SEEK_CUR). */ |
| 259 |
# if @REPLACE_FFLUSH@ |
| 260 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 261 |
# define fflush rpl_fflush |
| 262 |
# endif |
| 263 |
_GL_FUNCDECL_RPL (fflush, int, (FILE *gl_stream)); |
| 264 |
_GL_CXXALIAS_RPL (fflush, int, (FILE *gl_stream)); |
| 265 |
# else |
| 266 |
_GL_CXXALIAS_SYS (fflush, int, (FILE *gl_stream)); |
| 267 |
# endif |
| 268 |
# if __GLIBC__ >= 2 |
| 269 |
_GL_CXXALIASWARN (fflush); |
| 270 |
# endif |
| 271 |
#elif defined GNULIB_POSIXCHECK |
| 272 |
# undef fflush |
| 273 |
/* Assume fflush is always declared. */ |
| 274 |
_GL_WARN_ON_USE (fflush, "fflush is not always POSIX compliant - " |
| 275 |
"use gnulib module fflush for portable POSIX compliance"); |
| 276 |
#endif |
| 277 |
|
| 278 |
#if @GNULIB_FGETC@ |
| 279 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 280 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 281 |
# undef fgetc |
| 282 |
# define fgetc rpl_fgetc |
| 283 |
# endif |
| 284 |
_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1))); |
| 285 |
_GL_CXXALIAS_RPL (fgetc, int, (FILE *stream)); |
| 286 |
# else |
| 287 |
_GL_CXXALIAS_SYS (fgetc, int, (FILE *stream)); |
| 288 |
# endif |
| 289 |
# if __GLIBC__ >= 2 |
| 290 |
_GL_CXXALIASWARN (fgetc); |
| 291 |
# endif |
| 292 |
#endif |
| 293 |
|
| 294 |
#if @GNULIB_FGETS@ |
| 295 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 296 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 297 |
# undef fgets |
| 298 |
# define fgets rpl_fgets |
| 299 |
# endif |
| 300 |
_GL_FUNCDECL_RPL (fgets, char *, |
| 301 |
(char *restrict s, int n, FILE *restrict stream) |
| 302 |
_GL_ARG_NONNULL ((1, 3))); |
| 303 |
_GL_CXXALIAS_RPL (fgets, char *, |
| 304 |
(char *restrict s, int n, FILE *restrict stream)); |
| 305 |
# else |
| 306 |
_GL_CXXALIAS_SYS (fgets, char *, |
| 307 |
(char *restrict s, int n, FILE *restrict stream)); |
| 308 |
# endif |
| 309 |
# if __GLIBC__ >= 2 |
| 310 |
_GL_CXXALIASWARN (fgets); |
| 311 |
# endif |
| 312 |
#endif |
| 313 |
|
| 314 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 315 |
# undef fileno |
| 316 |
# define fileno _fileno |
| 317 |
#endif |
| 318 |
|
| 319 |
#if @GNULIB_FOPEN@ |
| 320 |
# if @REPLACE_FOPEN@ |
| 321 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 322 |
# undef fopen |
| 323 |
# define fopen rpl_fopen |
| 324 |
# endif |
| 325 |
_GL_FUNCDECL_RPL (fopen, FILE *, |
| 326 |
(const char *restrict filename, const char *restrict mode) |
| 327 |
_GL_ARG_NONNULL ((1, 2))); |
| 328 |
_GL_CXXALIAS_RPL (fopen, FILE *, |
| 329 |
(const char *restrict filename, const char *restrict mode)); |
| 330 |
# else |
| 331 |
_GL_CXXALIAS_SYS (fopen, FILE *, |
| 332 |
(const char *restrict filename, const char *restrict mode)); |
| 333 |
# endif |
| 334 |
# if __GLIBC__ >= 2 |
| 335 |
_GL_CXXALIASWARN (fopen); |
| 336 |
# endif |
| 337 |
#elif defined GNULIB_POSIXCHECK |
| 338 |
# undef fopen |
| 339 |
/* Assume fopen is always declared. */ |
| 340 |
_GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX compliant - " |
| 341 |
"use gnulib module fopen for portability"); |
| 342 |
#endif |
| 343 |
|
| 344 |
#if @GNULIB_FPRINTF_POSIX@ || @GNULIB_FPRINTF@ |
| 345 |
# if (@GNULIB_FPRINTF_POSIX@ && @REPLACE_FPRINTF@) \ |
| 346 |
|| (@GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) |
| 347 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 348 |
# define fprintf rpl_fprintf |
| 349 |
# endif |
| 350 |
# define GNULIB_overrides_fprintf 1 |
| 351 |
# if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ |
| 352 |
_GL_FUNCDECL_RPL (fprintf, int, |
| 353 |
(FILE *restrict fp, const char *restrict format, ...) |
| 354 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 355 |
_GL_ARG_NONNULL ((1, 2))); |
| 356 |
# else |
| 357 |
_GL_FUNCDECL_RPL (fprintf, int, |
| 358 |
(FILE *restrict fp, const char *restrict format, ...) |
| 359 |
_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 3) |
| 360 |
_GL_ARG_NONNULL ((1, 2))); |
| 361 |
# endif |
| 362 |
_GL_CXXALIAS_RPL (fprintf, int, |
| 363 |
(FILE *restrict fp, const char *restrict format, ...)); |
| 364 |
# else |
| 365 |
_GL_CXXALIAS_SYS (fprintf, int, |
| 366 |
(FILE *restrict fp, const char *restrict format, ...)); |
| 367 |
# endif |
| 368 |
# if __GLIBC__ >= 2 |
| 369 |
_GL_CXXALIASWARN (fprintf); |
| 370 |
# endif |
| 371 |
#endif |
| 372 |
#if !@GNULIB_FPRINTF_POSIX@ && defined GNULIB_POSIXCHECK |
| 373 |
# if !GNULIB_overrides_fprintf |
| 374 |
# undef fprintf |
| 375 |
# endif |
| 376 |
/* Assume fprintf is always declared. */ |
| 377 |
_GL_WARN_ON_USE (fprintf, "fprintf is not always POSIX compliant - " |
| 378 |
"use gnulib module fprintf-posix for portable " |
| 379 |
"POSIX compliance"); |
| 380 |
#endif |
| 381 |
|
| 382 |
#if @GNULIB_FPURGE@ |
| 383 |
/* Discard all pending buffered I/O data on STREAM. |
| 384 |
STREAM must not be wide-character oriented. |
| 385 |
When discarding pending output, the file position is set back to where it |
| 386 |
was before the write calls. When discarding pending input, the file |
| 387 |
position is advanced to match the end of the previously read input. |
| 388 |
Return 0 if successful. Upon error, return -1 and set errno. */ |
| 389 |
# if @REPLACE_FPURGE@ |
| 390 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 391 |
# define fpurge rpl_fpurge |
| 392 |
# endif |
| 393 |
_GL_FUNCDECL_RPL (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); |
| 394 |
_GL_CXXALIAS_RPL (fpurge, int, (FILE *gl_stream)); |
| 395 |
# else |
| 396 |
# if !@HAVE_DECL_FPURGE@ |
| 397 |
_GL_FUNCDECL_SYS (fpurge, int, (FILE *gl_stream) _GL_ARG_NONNULL ((1))); |
| 398 |
# endif |
| 399 |
_GL_CXXALIAS_SYS (fpurge, int, (FILE *gl_stream)); |
| 400 |
# endif |
| 401 |
_GL_CXXALIASWARN (fpurge); |
| 402 |
#elif defined GNULIB_POSIXCHECK |
| 403 |
# undef fpurge |
| 404 |
# if HAVE_RAW_DECL_FPURGE |
| 405 |
_GL_WARN_ON_USE (fpurge, "fpurge is not always present - " |
| 406 |
"use gnulib module fpurge for portability"); |
| 407 |
# endif |
| 408 |
#endif |
| 409 |
|
| 410 |
#if @GNULIB_FPUTC@ |
| 411 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 412 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 413 |
# undef fputc |
| 414 |
# define fputc rpl_fputc |
| 415 |
# endif |
| 416 |
_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); |
| 417 |
_GL_CXXALIAS_RPL (fputc, int, (int c, FILE *stream)); |
| 418 |
# else |
| 419 |
_GL_CXXALIAS_SYS (fputc, int, (int c, FILE *stream)); |
| 420 |
# endif |
| 421 |
# if __GLIBC__ >= 2 |
| 422 |
_GL_CXXALIASWARN (fputc); |
| 423 |
# endif |
| 424 |
#endif |
| 425 |
|
| 426 |
#if @GNULIB_FPUTS@ |
| 427 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 428 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 429 |
# undef fputs |
| 430 |
# define fputs rpl_fputs |
| 431 |
# endif |
| 432 |
_GL_FUNCDECL_RPL (fputs, int, |
| 433 |
(const char *restrict string, FILE *restrict stream) |
| 434 |
_GL_ARG_NONNULL ((1, 2))); |
| 435 |
_GL_CXXALIAS_RPL (fputs, int, |
| 436 |
(const char *restrict string, FILE *restrict stream)); |
| 437 |
# else |
| 438 |
_GL_CXXALIAS_SYS (fputs, int, |
| 439 |
(const char *restrict string, FILE *restrict stream)); |
| 440 |
# endif |
| 441 |
# if __GLIBC__ >= 2 |
| 442 |
_GL_CXXALIASWARN (fputs); |
| 443 |
# endif |
| 444 |
#endif |
| 445 |
|
| 446 |
#if @GNULIB_FREAD@ |
| 447 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 448 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 449 |
# undef fread |
| 450 |
# define fread rpl_fread |
| 451 |
# endif |
| 452 |
_GL_FUNCDECL_RPL (fread, size_t, |
| 453 |
(void *restrict ptr, size_t s, size_t n, |
| 454 |
FILE *restrict stream) |
| 455 |
_GL_ARG_NONNULL ((4))); |
| 456 |
_GL_CXXALIAS_RPL (fread, size_t, |
| 457 |
(void *restrict ptr, size_t s, size_t n, |
| 458 |
FILE *restrict stream)); |
| 459 |
# else |
| 460 |
_GL_CXXALIAS_SYS (fread, size_t, |
| 461 |
(void *restrict ptr, size_t s, size_t n, |
| 462 |
FILE *restrict stream)); |
| 463 |
# endif |
| 464 |
# if __GLIBC__ >= 2 |
| 465 |
_GL_CXXALIASWARN (fread); |
| 466 |
# endif |
| 467 |
#endif |
| 468 |
|
| 469 |
#if @GNULIB_FREOPEN@ |
| 470 |
# if @REPLACE_FREOPEN@ |
| 471 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 472 |
# undef freopen |
| 473 |
# define freopen rpl_freopen |
| 474 |
# endif |
| 475 |
_GL_FUNCDECL_RPL (freopen, FILE *, |
| 476 |
(const char *restrict filename, const char *restrict mode, |
| 477 |
FILE *restrict stream) |
| 478 |
_GL_ARG_NONNULL ((2, 3))); |
| 479 |
_GL_CXXALIAS_RPL (freopen, FILE *, |
| 480 |
(const char *restrict filename, const char *restrict mode, |
| 481 |
FILE *restrict stream)); |
| 482 |
# else |
| 483 |
_GL_CXXALIAS_SYS (freopen, FILE *, |
| 484 |
(const char *restrict filename, const char *restrict mode, |
| 485 |
FILE *restrict stream)); |
| 486 |
# endif |
| 487 |
# if __GLIBC__ >= 2 |
| 488 |
_GL_CXXALIASWARN (freopen); |
| 489 |
# endif |
| 490 |
#elif defined GNULIB_POSIXCHECK |
| 491 |
# undef freopen |
| 492 |
/* Assume freopen is always declared. */ |
| 493 |
_GL_WARN_ON_USE (freopen, |
| 494 |
"freopen on native Windows platforms is not POSIX compliant - " |
| 495 |
"use gnulib module freopen for portability"); |
| 496 |
#endif |
| 497 |
|
| 498 |
#if @GNULIB_FSCANF@ |
| 499 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 500 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 501 |
# undef fscanf |
| 502 |
# define fscanf rpl_fscanf |
| 503 |
# endif |
| 504 |
_GL_FUNCDECL_RPL (fscanf, int, |
| 505 |
(FILE *restrict stream, const char *restrict format, ...) |
| 506 |
_GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 3) |
| 507 |
_GL_ARG_NONNULL ((1, 2))); |
| 508 |
_GL_CXXALIAS_RPL (fscanf, int, |
| 509 |
(FILE *restrict stream, const char *restrict format, ...)); |
| 510 |
# else |
| 511 |
_GL_CXXALIAS_SYS (fscanf, int, |
| 512 |
(FILE *restrict stream, const char *restrict format, ...)); |
| 513 |
# endif |
| 514 |
# if __GLIBC__ >= 2 |
| 515 |
_GL_CXXALIASWARN (fscanf); |
| 516 |
# endif |
| 517 |
#endif |
| 518 |
|
| 519 |
|
| 520 |
/* Set up the following warnings, based on which modules are in use. |
| 521 |
GNU Coding Standards discourage the use of fseek, since it imposes |
| 522 |
an arbitrary limitation on some 32-bit hosts. Remember that the |
| 523 |
fseek module depends on the fseeko module, so we only have three |
| 524 |
cases to consider: |
| 525 |
|
| 526 |
1. The developer is not using either module. Issue a warning under |
| 527 |
GNULIB_POSIXCHECK for both functions, to remind them that both |
| 528 |
functions have bugs on some systems. _GL_NO_LARGE_FILES has no |
| 529 |
impact on this warning. |
| 530 |
|
| 531 |
2. The developer is using both modules. They may be unaware of the |
| 532 |
arbitrary limitations of fseek, so issue a warning under |
| 533 |
GNULIB_POSIXCHECK. On the other hand, they may be using both |
| 534 |
modules intentionally, so the developer can define |
| 535 |
_GL_NO_LARGE_FILES in the compilation units where the use of fseek |
| 536 |
is safe, to silence the warning. |
| 537 |
|
| 538 |
3. The developer is using the fseeko module, but not fseek. Gnulib |
| 539 |
guarantees that fseek will still work around platform bugs in that |
| 540 |
case, but we presume that the developer is aware of the pitfalls of |
| 541 |
fseek and was trying to avoid it, so issue a warning even when |
| 542 |
GNULIB_POSIXCHECK is undefined. Again, _GL_NO_LARGE_FILES can be |
| 543 |
defined to silence the warning in particular compilation units. |
| 544 |
In C++ compilations with GNULIB_NAMESPACE, in order to avoid that |
| 545 |
fseek gets defined as a macro, it is recommended that the developer |
| 546 |
uses the fseek module, even if he is not calling the fseek function. |
| 547 |
|
| 548 |
Most gnulib clients that perform stream operations should fall into |
| 549 |
category 3. */ |
| 550 |
|
| 551 |
#if @GNULIB_FSEEK@ |
| 552 |
# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES |
| 553 |
# define _GL_FSEEK_WARN /* Category 2, above. */ |
| 554 |
# undef fseek |
| 555 |
# endif |
| 556 |
# if @REPLACE_FSEEK@ |
| 557 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 558 |
# undef fseek |
| 559 |
# define fseek rpl_fseek |
| 560 |
# endif |
| 561 |
_GL_FUNCDECL_RPL (fseek, int, (FILE *fp, long offset, int whence) |
| 562 |
_GL_ARG_NONNULL ((1))); |
| 563 |
_GL_CXXALIAS_RPL (fseek, int, (FILE *fp, long offset, int whence)); |
| 564 |
# else |
| 565 |
_GL_CXXALIAS_SYS (fseek, int, (FILE *fp, long offset, int whence)); |
| 566 |
# endif |
| 567 |
# if __GLIBC__ >= 2 |
| 568 |
_GL_CXXALIASWARN (fseek); |
| 569 |
# endif |
| 570 |
#endif |
| 571 |
|
| 572 |
#if @GNULIB_FSEEKO@ |
| 573 |
# if !@GNULIB_FSEEK@ && !defined _GL_NO_LARGE_FILES |
| 574 |
# define _GL_FSEEK_WARN /* Category 3, above. */ |
| 575 |
# undef fseek |
| 576 |
# endif |
| 577 |
# if @REPLACE_FSEEKO@ |
| 578 |
/* Provide an fseeko function that is aware of a preceding fflush(), and which |
| 579 |
detects pipes. */ |
| 580 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 581 |
# undef fseeko |
| 582 |
# define fseeko rpl_fseeko |
| 583 |
# endif |
| 584 |
_GL_FUNCDECL_RPL (fseeko, int, (FILE *fp, off_t offset, int whence) |
| 585 |
_GL_ARG_NONNULL ((1))); |
| 586 |
_GL_CXXALIAS_RPL (fseeko, int, (FILE *fp, off_t offset, int whence)); |
| 587 |
# else |
| 588 |
# if ! @HAVE_DECL_FSEEKO@ |
| 589 |
_GL_FUNCDECL_SYS (fseeko, int, (FILE *fp, off_t offset, int whence) |
| 590 |
_GL_ARG_NONNULL ((1))); |
| 591 |
# endif |
| 592 |
_GL_CXXALIAS_SYS (fseeko, int, (FILE *fp, off_t offset, int whence)); |
| 593 |
# endif |
| 594 |
_GL_CXXALIASWARN (fseeko); |
| 595 |
#elif defined GNULIB_POSIXCHECK |
| 596 |
# define _GL_FSEEK_WARN /* Category 1, above. */ |
| 597 |
# undef fseek |
| 598 |
# undef fseeko |
| 599 |
# if HAVE_RAW_DECL_FSEEKO |
| 600 |
_GL_WARN_ON_USE (fseeko, "fseeko is unportable - " |
| 601 |
"use gnulib module fseeko for portability"); |
| 602 |
# endif |
| 603 |
#endif |
| 604 |
|
| 605 |
#ifdef _GL_FSEEK_WARN |
| 606 |
# undef _GL_FSEEK_WARN |
| 607 |
/* Here, either fseek is undefined (but C89 guarantees that it is |
| 608 |
declared), or it is defined as rpl_fseek (declared above). */ |
| 609 |
_GL_WARN_ON_USE (fseek, "fseek cannot handle files larger than 4 GB " |
| 610 |
"on 32-bit platforms - " |
| 611 |
"use fseeko function for handling of large files"); |
| 612 |
#endif |
| 613 |
|
| 614 |
|
| 615 |
/* ftell, ftello. See the comments on fseek/fseeko. */ |
| 616 |
|
| 617 |
#if @GNULIB_FTELL@ |
| 618 |
# if defined GNULIB_POSIXCHECK && !defined _GL_NO_LARGE_FILES |
| 619 |
# define _GL_FTELL_WARN /* Category 2, above. */ |
| 620 |
# undef ftell |
| 621 |
# endif |
| 622 |
# if @REPLACE_FTELL@ |
| 623 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 624 |
# undef ftell |
| 625 |
# define ftell rpl_ftell |
| 626 |
# endif |
| 627 |
_GL_FUNCDECL_RPL (ftell, long, (FILE *fp) _GL_ARG_NONNULL ((1))); |
| 628 |
_GL_CXXALIAS_RPL (ftell, long, (FILE *fp)); |
| 629 |
# else |
| 630 |
_GL_CXXALIAS_SYS (ftell, long, (FILE *fp)); |
| 631 |
# endif |
| 632 |
# if __GLIBC__ >= 2 |
| 633 |
_GL_CXXALIASWARN (ftell); |
| 634 |
# endif |
| 635 |
#endif |
| 636 |
|
| 637 |
#if @GNULIB_FTELLO@ |
| 638 |
# if !@GNULIB_FTELL@ && !defined _GL_NO_LARGE_FILES |
| 639 |
# define _GL_FTELL_WARN /* Category 3, above. */ |
| 640 |
# undef ftell |
| 641 |
# endif |
| 642 |
# if @REPLACE_FTELLO@ |
| 643 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 644 |
# undef ftello |
| 645 |
# define ftello rpl_ftello |
| 646 |
# endif |
| 647 |
_GL_FUNCDECL_RPL (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); |
| 648 |
_GL_CXXALIAS_RPL (ftello, off_t, (FILE *fp)); |
| 649 |
# else |
| 650 |
# if ! @HAVE_DECL_FTELLO@ |
| 651 |
_GL_FUNCDECL_SYS (ftello, off_t, (FILE *fp) _GL_ARG_NONNULL ((1))); |
| 652 |
# endif |
| 653 |
_GL_CXXALIAS_SYS (ftello, off_t, (FILE *fp)); |
| 654 |
# endif |
| 655 |
_GL_CXXALIASWARN (ftello); |
| 656 |
#elif defined GNULIB_POSIXCHECK |
| 657 |
# define _GL_FTELL_WARN /* Category 1, above. */ |
| 658 |
# undef ftell |
| 659 |
# undef ftello |
| 660 |
# if HAVE_RAW_DECL_FTELLO |
| 661 |
_GL_WARN_ON_USE (ftello, "ftello is unportable - " |
| 662 |
"use gnulib module ftello for portability"); |
| 663 |
# endif |
| 664 |
#endif |
| 665 |
|
| 666 |
#ifdef _GL_FTELL_WARN |
| 667 |
# undef _GL_FTELL_WARN |
| 668 |
/* Here, either ftell is undefined (but C89 guarantees that it is |
| 669 |
declared), or it is defined as rpl_ftell (declared above). */ |
| 670 |
_GL_WARN_ON_USE (ftell, "ftell cannot handle files larger than 4 GB " |
| 671 |
"on 32-bit platforms - " |
| 672 |
"use ftello function for handling of large files"); |
| 673 |
#endif |
| 674 |
|
| 675 |
|
| 676 |
#if @GNULIB_FWRITE@ |
| 677 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 678 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 679 |
# undef fwrite |
| 680 |
# define fwrite rpl_fwrite |
| 681 |
# endif |
| 682 |
_GL_FUNCDECL_RPL (fwrite, size_t, |
| 683 |
(const void *restrict ptr, size_t s, size_t n, |
| 684 |
FILE *restrict stream) |
| 685 |
_GL_ARG_NONNULL ((1, 4))); |
| 686 |
_GL_CXXALIAS_RPL (fwrite, size_t, |
| 687 |
(const void *restrict ptr, size_t s, size_t n, |
| 688 |
FILE *restrict stream)); |
| 689 |
# else |
| 690 |
_GL_CXXALIAS_SYS (fwrite, size_t, |
| 691 |
(const void *restrict ptr, size_t s, size_t n, |
| 692 |
FILE *restrict stream)); |
| 693 |
|
| 694 |
/* Work around bug 11959 when fortifying glibc 2.4 through 2.15 |
| 695 |
<https://sourceware.org/bugzilla/show_bug.cgi?id=11959>, |
| 696 |
which sometimes causes an unwanted diagnostic for fwrite calls. |
| 697 |
This affects only function declaration attributes under certain |
| 698 |
versions of gcc and clang, and is not needed for C++. */ |
| 699 |
# if (0 < __USE_FORTIFY_LEVEL \ |
| 700 |
&& __GLIBC__ == 2 && 4 <= __GLIBC_MINOR__ && __GLIBC_MINOR__ <= 15 \ |
| 701 |
&& 3 < __GNUC__ + (4 <= __GNUC_MINOR__) \ |
| 702 |
&& !defined __cplusplus) |
| 703 |
# undef fwrite |
| 704 |
# undef fwrite_unlocked |
| 705 |
extern size_t __REDIRECT (rpl_fwrite, |
| 706 |
(const void *__restrict, size_t, size_t, |
| 707 |
FILE *__restrict), |
| 708 |
fwrite); |
| 709 |
extern size_t __REDIRECT (rpl_fwrite_unlocked, |
| 710 |
(const void *__restrict, size_t, size_t, |
| 711 |
FILE *__restrict), |
| 712 |
fwrite_unlocked); |
| 713 |
# define fwrite rpl_fwrite |
| 714 |
# define fwrite_unlocked rpl_fwrite_unlocked |
| 715 |
# endif |
| 716 |
# endif |
| 717 |
# if __GLIBC__ >= 2 |
| 718 |
_GL_CXXALIASWARN (fwrite); |
| 719 |
# endif |
| 720 |
#endif |
| 721 |
|
| 722 |
#if @GNULIB_GETC@ |
| 723 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 724 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 725 |
# undef getc |
| 726 |
# define getc rpl_fgetc |
| 727 |
# endif |
| 728 |
_GL_FUNCDECL_RPL (fgetc, int, (FILE *stream) _GL_ARG_NONNULL ((1))); |
| 729 |
_GL_CXXALIAS_RPL_1 (getc, rpl_fgetc, int, (FILE *stream)); |
| 730 |
# else |
| 731 |
_GL_CXXALIAS_SYS (getc, int, (FILE *stream)); |
| 732 |
# endif |
| 733 |
# if __GLIBC__ >= 2 |
| 734 |
_GL_CXXALIASWARN (getc); |
| 735 |
# endif |
| 736 |
#endif |
| 737 |
|
| 738 |
#if @GNULIB_GETCHAR@ |
| 739 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 740 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 741 |
# undef getchar |
| 742 |
# define getchar rpl_getchar |
| 743 |
# endif |
| 744 |
_GL_FUNCDECL_RPL (getchar, int, (void)); |
| 745 |
_GL_CXXALIAS_RPL (getchar, int, (void)); |
| 746 |
# else |
| 747 |
_GL_CXXALIAS_SYS (getchar, int, (void)); |
| 748 |
# endif |
| 749 |
# if __GLIBC__ >= 2 |
| 750 |
_GL_CXXALIASWARN (getchar); |
| 751 |
# endif |
| 752 |
#endif |
| 753 |
|
| 754 |
#if @GNULIB_GETDELIM@ |
| 755 |
/* Read input, up to (and including) the next occurrence of DELIMITER, from |
| 756 |
STREAM, store it in *LINEPTR (and NUL-terminate it). |
| 757 |
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE |
| 758 |
bytes of space. It is realloc'd as necessary. |
| 759 |
Return the number of bytes read and stored at *LINEPTR (not including the |
| 760 |
NUL terminator), or -1 on error or EOF. */ |
| 761 |
# if @REPLACE_GETDELIM@ |
| 762 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 763 |
# undef getdelim |
| 764 |
# define getdelim rpl_getdelim |
| 765 |
# endif |
| 766 |
_GL_FUNCDECL_RPL (getdelim, ssize_t, |
| 767 |
(char **restrict lineptr, size_t *restrict linesize, |
| 768 |
int delimiter, |
| 769 |
FILE *restrict stream) |
| 770 |
_GL_ARG_NONNULL ((1, 2, 4))); |
| 771 |
_GL_CXXALIAS_RPL (getdelim, ssize_t, |
| 772 |
(char **restrict lineptr, size_t *restrict linesize, |
| 773 |
int delimiter, |
| 774 |
FILE *restrict stream)); |
| 775 |
# else |
| 776 |
# if !@HAVE_DECL_GETDELIM@ |
| 777 |
_GL_FUNCDECL_SYS (getdelim, ssize_t, |
| 778 |
(char **restrict lineptr, size_t *restrict linesize, |
| 779 |
int delimiter, |
| 780 |
FILE *restrict stream) |
| 781 |
_GL_ARG_NONNULL ((1, 2, 4))); |
| 782 |
# endif |
| 783 |
_GL_CXXALIAS_SYS (getdelim, ssize_t, |
| 784 |
(char **restrict lineptr, size_t *restrict linesize, |
| 785 |
int delimiter, |
| 786 |
FILE *restrict stream)); |
| 787 |
# endif |
| 788 |
_GL_CXXALIASWARN (getdelim); |
| 789 |
#elif defined GNULIB_POSIXCHECK |
| 790 |
# undef getdelim |
| 791 |
# if HAVE_RAW_DECL_GETDELIM |
| 792 |
_GL_WARN_ON_USE (getdelim, "getdelim is unportable - " |
| 793 |
"use gnulib module getdelim for portability"); |
| 794 |
# endif |
| 795 |
#endif |
| 796 |
|
| 797 |
#if @GNULIB_GETLINE@ |
| 798 |
/* Read a line, up to (and including) the next newline, from STREAM, store it |
| 799 |
in *LINEPTR (and NUL-terminate it). |
| 800 |
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE |
| 801 |
bytes of space. It is realloc'd as necessary. |
| 802 |
Return the number of bytes read and stored at *LINEPTR (not including the |
| 803 |
NUL terminator), or -1 on error or EOF. */ |
| 804 |
# if @REPLACE_GETLINE@ |
| 805 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 806 |
# undef getline |
| 807 |
# define getline rpl_getline |
| 808 |
# endif |
| 809 |
_GL_FUNCDECL_RPL (getline, ssize_t, |
| 810 |
(char **restrict lineptr, size_t *restrict linesize, |
| 811 |
FILE *restrict stream) |
| 812 |
_GL_ARG_NONNULL ((1, 2, 3))); |
| 813 |
_GL_CXXALIAS_RPL (getline, ssize_t, |
| 814 |
(char **restrict lineptr, size_t *restrict linesize, |
| 815 |
FILE *restrict stream)); |
| 816 |
# else |
| 817 |
# if !@HAVE_DECL_GETLINE@ |
| 818 |
_GL_FUNCDECL_SYS (getline, ssize_t, |
| 819 |
(char **restrict lineptr, size_t *restrict linesize, |
| 820 |
FILE *restrict stream) |
| 821 |
_GL_ARG_NONNULL ((1, 2, 3))); |
| 822 |
# endif |
| 823 |
_GL_CXXALIAS_SYS (getline, ssize_t, |
| 824 |
(char **restrict lineptr, size_t *restrict linesize, |
| 825 |
FILE *restrict stream)); |
| 826 |
# endif |
| 827 |
# if @HAVE_DECL_GETLINE@ |
| 828 |
_GL_CXXALIASWARN (getline); |
| 829 |
# endif |
| 830 |
#elif defined GNULIB_POSIXCHECK |
| 831 |
# undef getline |
| 832 |
# if HAVE_RAW_DECL_GETLINE |
| 833 |
_GL_WARN_ON_USE (getline, "getline is unportable - " |
| 834 |
"use gnulib module getline for portability"); |
| 835 |
# endif |
| 836 |
#endif |
| 837 |
|
| 838 |
/* It is very rare that the developer ever has full control of stdin, |
| 839 |
so any use of gets warrants an unconditional warning; besides, C11 |
| 840 |
removed it. */ |
| 841 |
#undef gets |
| 842 |
#if HAVE_RAW_DECL_GETS && !defined __cplusplus |
| 843 |
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); |
| 844 |
#endif |
| 845 |
|
| 846 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 847 |
# undef getw |
| 848 |
# define getw _getw |
| 849 |
#endif |
| 850 |
|
| 851 |
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@ |
| 852 |
struct obstack; |
| 853 |
/* Grow an obstack with formatted output. Return the number of |
| 854 |
bytes added to OBS. No trailing nul byte is added, and the |
| 855 |
object should be closed with obstack_finish before use. Upon |
| 856 |
memory allocation error, call obstack_alloc_failed_handler. Upon |
| 857 |
other error, return -1. */ |
| 858 |
# if @REPLACE_OBSTACK_PRINTF@ |
| 859 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 860 |
# define obstack_printf rpl_obstack_printf |
| 861 |
# endif |
| 862 |
_GL_FUNCDECL_RPL (obstack_printf, int, |
| 863 |
(struct obstack *obs, const char *format, ...) |
| 864 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 865 |
_GL_ARG_NONNULL ((1, 2))); |
| 866 |
_GL_CXXALIAS_RPL (obstack_printf, int, |
| 867 |
(struct obstack *obs, const char *format, ...)); |
| 868 |
# else |
| 869 |
# if !@HAVE_DECL_OBSTACK_PRINTF@ |
| 870 |
_GL_FUNCDECL_SYS (obstack_printf, int, |
| 871 |
(struct obstack *obs, const char *format, ...) |
| 872 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 873 |
_GL_ARG_NONNULL ((1, 2))); |
| 874 |
# endif |
| 875 |
_GL_CXXALIAS_SYS (obstack_printf, int, |
| 876 |
(struct obstack *obs, const char *format, ...)); |
| 877 |
# endif |
| 878 |
_GL_CXXALIASWARN (obstack_printf); |
| 879 |
# if @REPLACE_OBSTACK_PRINTF@ |
| 880 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 881 |
# define obstack_vprintf rpl_obstack_vprintf |
| 882 |
# endif |
| 883 |
_GL_FUNCDECL_RPL (obstack_vprintf, int, |
| 884 |
(struct obstack *obs, const char *format, va_list args) |
| 885 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 886 |
_GL_ARG_NONNULL ((1, 2))); |
| 887 |
_GL_CXXALIAS_RPL (obstack_vprintf, int, |
| 888 |
(struct obstack *obs, const char *format, va_list args)); |
| 889 |
# else |
| 890 |
# if !@HAVE_DECL_OBSTACK_PRINTF@ |
| 891 |
_GL_FUNCDECL_SYS (obstack_vprintf, int, |
| 892 |
(struct obstack *obs, const char *format, va_list args) |
| 893 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 894 |
_GL_ARG_NONNULL ((1, 2))); |
| 895 |
# endif |
| 896 |
_GL_CXXALIAS_SYS (obstack_vprintf, int, |
| 897 |
(struct obstack *obs, const char *format, va_list args)); |
| 898 |
# endif |
| 899 |
_GL_CXXALIASWARN (obstack_vprintf); |
| 900 |
#endif |
| 901 |
|
| 902 |
#if @GNULIB_PCLOSE@ |
| 903 |
# if !@HAVE_PCLOSE@ |
| 904 |
_GL_FUNCDECL_SYS (pclose, int, (FILE *stream) _GL_ARG_NONNULL ((1))); |
| 905 |
# endif |
| 906 |
_GL_CXXALIAS_SYS (pclose, int, (FILE *stream)); |
| 907 |
_GL_CXXALIASWARN (pclose); |
| 908 |
#elif defined GNULIB_POSIXCHECK |
| 909 |
# undef pclose |
| 910 |
# if HAVE_RAW_DECL_PCLOSE |
| 911 |
_GL_WARN_ON_USE (pclose, "pclose is unportable - " |
| 912 |
"use gnulib module pclose for more portability"); |
| 913 |
# endif |
| 914 |
#endif |
| 915 |
|
| 916 |
#if @GNULIB_PERROR@ |
| 917 |
/* Print a message to standard error, describing the value of ERRNO, |
| 918 |
(if STRING is not NULL and not empty) prefixed with STRING and ": ", |
| 919 |
and terminated with a newline. */ |
| 920 |
# if @REPLACE_PERROR@ |
| 921 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 922 |
# define perror rpl_perror |
| 923 |
# endif |
| 924 |
_GL_FUNCDECL_RPL (perror, void, (const char *string)); |
| 925 |
_GL_CXXALIAS_RPL (perror, void, (const char *string)); |
| 926 |
# else |
| 927 |
_GL_CXXALIAS_SYS (perror, void, (const char *string)); |
| 928 |
# endif |
| 929 |
# if __GLIBC__ >= 2 |
| 930 |
_GL_CXXALIASWARN (perror); |
| 931 |
# endif |
| 932 |
#elif defined GNULIB_POSIXCHECK |
| 933 |
# undef perror |
| 934 |
/* Assume perror is always declared. */ |
| 935 |
_GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - " |
| 936 |
"use gnulib module perror for portability"); |
| 937 |
#endif |
| 938 |
|
| 939 |
#if @GNULIB_POPEN@ |
| 940 |
# if @REPLACE_POPEN@ |
| 941 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 942 |
# undef popen |
| 943 |
# define popen rpl_popen |
| 944 |
# endif |
| 945 |
_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode) |
| 946 |
_GL_ARG_NONNULL ((1, 2))); |
| 947 |
_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode)); |
| 948 |
# else |
| 949 |
# if !@HAVE_POPEN@ |
| 950 |
_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode) |
| 951 |
_GL_ARG_NONNULL ((1, 2))); |
| 952 |
# endif |
| 953 |
_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode)); |
| 954 |
# endif |
| 955 |
_GL_CXXALIASWARN (popen); |
| 956 |
#elif defined GNULIB_POSIXCHECK |
| 957 |
# undef popen |
| 958 |
# if HAVE_RAW_DECL_POPEN |
| 959 |
_GL_WARN_ON_USE (popen, "popen is buggy on some platforms - " |
| 960 |
"use gnulib module popen or pipe for more portability"); |
| 961 |
# endif |
| 962 |
#endif |
| 963 |
|
| 964 |
#if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@ |
| 965 |
# if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \ |
| 966 |
|| (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) |
| 967 |
# if defined __GNUC__ || defined __clang__ |
| 968 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 969 |
/* Don't break __attribute__((format(printf,M,N))). */ |
| 970 |
# define printf __printf__ |
| 971 |
# endif |
| 972 |
# if @GNULIB_PRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ |
| 973 |
_GL_FUNCDECL_RPL_1 (__printf__, int, |
| 974 |
(const char *restrict format, ...) |
| 975 |
__asm__ (@ASM_SYMBOL_PREFIX@ |
| 976 |
_GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) |
| 977 |
_GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) |
| 978 |
_GL_ARG_NONNULL ((1))); |
| 979 |
# else |
| 980 |
_GL_FUNCDECL_RPL_1 (__printf__, int, |
| 981 |
(const char *restrict format, ...) |
| 982 |
__asm__ (@ASM_SYMBOL_PREFIX@ |
| 983 |
_GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) |
| 984 |
_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 2) |
| 985 |
_GL_ARG_NONNULL ((1))); |
| 986 |
# endif |
| 987 |
_GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); |
| 988 |
# else |
| 989 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 990 |
# define printf rpl_printf |
| 991 |
# endif |
| 992 |
_GL_FUNCDECL_RPL (printf, int, |
| 993 |
(const char *restrict format, ...) |
| 994 |
_GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) |
| 995 |
_GL_ARG_NONNULL ((1))); |
| 996 |
_GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...)); |
| 997 |
# endif |
| 998 |
# define GNULIB_overrides_printf 1 |
| 999 |
# else |
| 1000 |
_GL_CXXALIAS_SYS (printf, int, (const char *restrict format, ...)); |
| 1001 |
# endif |
| 1002 |
# if __GLIBC__ >= 2 |
| 1003 |
_GL_CXXALIASWARN (printf); |
| 1004 |
# endif |
| 1005 |
#endif |
| 1006 |
#if !@GNULIB_PRINTF_POSIX@ && defined GNULIB_POSIXCHECK |
| 1007 |
# if !GNULIB_overrides_printf |
| 1008 |
# undef printf |
| 1009 |
# endif |
| 1010 |
/* Assume printf is always declared. */ |
| 1011 |
_GL_WARN_ON_USE (printf, "printf is not always POSIX compliant - " |
| 1012 |
"use gnulib module printf-posix for portable " |
| 1013 |
"POSIX compliance"); |
| 1014 |
#endif |
| 1015 |
|
| 1016 |
#if @GNULIB_PUTC@ |
| 1017 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 1018 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1019 |
# undef putc |
| 1020 |
# define putc rpl_fputc |
| 1021 |
# endif |
| 1022 |
_GL_FUNCDECL_RPL (fputc, int, (int c, FILE *stream) _GL_ARG_NONNULL ((2))); |
| 1023 |
_GL_CXXALIAS_RPL_1 (putc, rpl_fputc, int, (int c, FILE *stream)); |
| 1024 |
# else |
| 1025 |
_GL_CXXALIAS_SYS (putc, int, (int c, FILE *stream)); |
| 1026 |
# endif |
| 1027 |
# if __GLIBC__ >= 2 |
| 1028 |
_GL_CXXALIASWARN (putc); |
| 1029 |
# endif |
| 1030 |
#endif |
| 1031 |
|
| 1032 |
#if @GNULIB_PUTCHAR@ |
| 1033 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 1034 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1035 |
# undef putchar |
| 1036 |
# define putchar rpl_putchar |
| 1037 |
# endif |
| 1038 |
_GL_FUNCDECL_RPL (putchar, int, (int c)); |
| 1039 |
_GL_CXXALIAS_RPL (putchar, int, (int c)); |
| 1040 |
# else |
| 1041 |
_GL_CXXALIAS_SYS (putchar, int, (int c)); |
| 1042 |
# endif |
| 1043 |
# if __GLIBC__ >= 2 |
| 1044 |
_GL_CXXALIASWARN (putchar); |
| 1045 |
# endif |
| 1046 |
#endif |
| 1047 |
|
| 1048 |
#if @GNULIB_PUTS@ |
| 1049 |
# if @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@) |
| 1050 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1051 |
# undef puts |
| 1052 |
# define puts rpl_puts |
| 1053 |
# endif |
| 1054 |
_GL_FUNCDECL_RPL (puts, int, (const char *string) _GL_ARG_NONNULL ((1))); |
| 1055 |
_GL_CXXALIAS_RPL (puts, int, (const char *string)); |
| 1056 |
# else |
| 1057 |
_GL_CXXALIAS_SYS (puts, int, (const char *string)); |
| 1058 |
# endif |
| 1059 |
# if __GLIBC__ >= 2 |
| 1060 |
_GL_CXXALIASWARN (puts); |
| 1061 |
# endif |
| 1062 |
#endif |
| 1063 |
|
| 1064 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 1065 |
# undef putw |
| 1066 |
# define putw _putw |
| 1067 |
#endif |
| 1068 |
|
| 1069 |
#if @GNULIB_REMOVE@ |
| 1070 |
# if @REPLACE_REMOVE@ |
| 1071 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1072 |
# undef remove |
| 1073 |
# define remove rpl_remove |
| 1074 |
# endif |
| 1075 |
_GL_FUNCDECL_RPL (remove, int, (const char *name) _GL_ARG_NONNULL ((1))); |
| 1076 |
_GL_CXXALIAS_RPL (remove, int, (const char *name)); |
| 1077 |
# else |
| 1078 |
_GL_CXXALIAS_SYS (remove, int, (const char *name)); |
| 1079 |
# endif |
| 1080 |
# if __GLIBC__ >= 2 |
| 1081 |
_GL_CXXALIASWARN (remove); |
| 1082 |
# endif |
| 1083 |
#elif defined GNULIB_POSIXCHECK |
| 1084 |
# undef remove |
| 1085 |
/* Assume remove is always declared. */ |
| 1086 |
_GL_WARN_ON_USE (remove, "remove cannot handle directories on some platforms - " |
| 1087 |
"use gnulib module remove for more portability"); |
| 1088 |
#endif |
| 1089 |
|
| 1090 |
#if @GNULIB_RENAME@ |
| 1091 |
# if @REPLACE_RENAME@ |
| 1092 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1093 |
# undef rename |
| 1094 |
# define rename rpl_rename |
| 1095 |
# endif |
| 1096 |
_GL_FUNCDECL_RPL (rename, int, |
| 1097 |
(const char *old_filename, const char *new_filename) |
| 1098 |
_GL_ARG_NONNULL ((1, 2))); |
| 1099 |
_GL_CXXALIAS_RPL (rename, int, |
| 1100 |
(const char *old_filename, const char *new_filename)); |
| 1101 |
# else |
| 1102 |
_GL_CXXALIAS_SYS (rename, int, |
| 1103 |
(const char *old_filename, const char *new_filename)); |
| 1104 |
# endif |
| 1105 |
# if __GLIBC__ >= 2 |
| 1106 |
_GL_CXXALIASWARN (rename); |
| 1107 |
# endif |
| 1108 |
#elif defined GNULIB_POSIXCHECK |
| 1109 |
# undef rename |
| 1110 |
/* Assume rename is always declared. */ |
| 1111 |
_GL_WARN_ON_USE (rename, "rename is buggy on some platforms - " |
| 1112 |
"use gnulib module rename for more portability"); |
| 1113 |
#endif |
| 1114 |
|
| 1115 |
#if @GNULIB_RENAMEAT@ |
| 1116 |
# if @REPLACE_RENAMEAT@ |
| 1117 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1118 |
# undef renameat |
| 1119 |
# define renameat rpl_renameat |
| 1120 |
# endif |
| 1121 |
_GL_FUNCDECL_RPL (renameat, int, |
| 1122 |
(int fd1, char const *file1, int fd2, char const *file2) |
| 1123 |
_GL_ARG_NONNULL ((2, 4))); |
| 1124 |
_GL_CXXALIAS_RPL (renameat, int, |
| 1125 |
(int fd1, char const *file1, int fd2, char const *file2)); |
| 1126 |
# else |
| 1127 |
# if !@HAVE_RENAMEAT@ |
| 1128 |
_GL_FUNCDECL_SYS (renameat, int, |
| 1129 |
(int fd1, char const *file1, int fd2, char const *file2) |
| 1130 |
_GL_ARG_NONNULL ((2, 4))); |
| 1131 |
# endif |
| 1132 |
_GL_CXXALIAS_SYS (renameat, int, |
| 1133 |
(int fd1, char const *file1, int fd2, char const *file2)); |
| 1134 |
# endif |
| 1135 |
_GL_CXXALIASWARN (renameat); |
| 1136 |
#elif defined GNULIB_POSIXCHECK |
| 1137 |
# undef renameat |
| 1138 |
# if HAVE_RAW_DECL_RENAMEAT |
| 1139 |
_GL_WARN_ON_USE (renameat, "renameat is not portable - " |
| 1140 |
"use gnulib module renameat for portability"); |
| 1141 |
# endif |
| 1142 |
#endif |
| 1143 |
|
| 1144 |
#if @GNULIB_SCANF@ |
| 1145 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 1146 |
# if defined __GNUC__ || defined __clang__ |
| 1147 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1148 |
# undef scanf |
| 1149 |
/* Don't break __attribute__((format(scanf,M,N))). */ |
| 1150 |
# define scanf __scanf__ |
| 1151 |
# endif |
| 1152 |
_GL_FUNCDECL_RPL_1 (__scanf__, int, |
| 1153 |
(const char *restrict format, ...) |
| 1154 |
__asm__ (@ASM_SYMBOL_PREFIX@ |
| 1155 |
_GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_scanf)) |
| 1156 |
_GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) |
| 1157 |
_GL_ARG_NONNULL ((1))); |
| 1158 |
_GL_CXXALIAS_RPL_1 (scanf, __scanf__, int, (const char *restrict format, ...)); |
| 1159 |
# else |
| 1160 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1161 |
# undef scanf |
| 1162 |
# define scanf rpl_scanf |
| 1163 |
# endif |
| 1164 |
_GL_FUNCDECL_RPL (scanf, int, (const char *restrict format, ...) |
| 1165 |
_GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 2) |
| 1166 |
_GL_ARG_NONNULL ((1))); |
| 1167 |
_GL_CXXALIAS_RPL (scanf, int, (const char *restrict format, ...)); |
| 1168 |
# endif |
| 1169 |
# else |
| 1170 |
_GL_CXXALIAS_SYS (scanf, int, (const char *restrict format, ...)); |
| 1171 |
# endif |
| 1172 |
# if __GLIBC__ >= 2 |
| 1173 |
_GL_CXXALIASWARN (scanf); |
| 1174 |
# endif |
| 1175 |
#endif |
| 1176 |
|
| 1177 |
#if @GNULIB_SNPRINTF@ |
| 1178 |
# if @REPLACE_SNPRINTF@ |
| 1179 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1180 |
# define snprintf rpl_snprintf |
| 1181 |
# endif |
| 1182 |
_GL_FUNCDECL_RPL (snprintf, int, |
| 1183 |
(char *restrict str, size_t size, |
| 1184 |
const char *restrict format, ...) |
| 1185 |
_GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) |
| 1186 |
_GL_ARG_NONNULL ((3))); |
| 1187 |
_GL_CXXALIAS_RPL (snprintf, int, |
| 1188 |
(char *restrict str, size_t size, |
| 1189 |
const char *restrict format, ...)); |
| 1190 |
# else |
| 1191 |
# if !@HAVE_DECL_SNPRINTF@ |
| 1192 |
_GL_FUNCDECL_SYS (snprintf, int, |
| 1193 |
(char *restrict str, size_t size, |
| 1194 |
const char *restrict format, ...) |
| 1195 |
_GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) |
| 1196 |
_GL_ARG_NONNULL ((3))); |
| 1197 |
# endif |
| 1198 |
_GL_CXXALIAS_SYS (snprintf, int, |
| 1199 |
(char *restrict str, size_t size, |
| 1200 |
const char *restrict format, ...)); |
| 1201 |
# endif |
| 1202 |
# if __GLIBC__ >= 2 |
| 1203 |
_GL_CXXALIASWARN (snprintf); |
| 1204 |
# endif |
| 1205 |
#elif defined GNULIB_POSIXCHECK |
| 1206 |
# undef snprintf |
| 1207 |
# if HAVE_RAW_DECL_SNPRINTF |
| 1208 |
_GL_WARN_ON_USE (snprintf, "snprintf is unportable - " |
| 1209 |
"use gnulib module snprintf for portability"); |
| 1210 |
# endif |
| 1211 |
#endif |
| 1212 |
|
| 1213 |
/* Some people would argue that all sprintf uses should be warned about |
| 1214 |
(for example, OpenBSD issues a link warning for it), |
| 1215 |
since it can cause security holes due to buffer overruns. |
| 1216 |
However, we believe that sprintf can be used safely, and is more |
| 1217 |
efficient than snprintf in those safe cases; and as proof of our |
| 1218 |
belief, we use sprintf in several gnulib modules. So this header |
| 1219 |
intentionally avoids adding a warning to sprintf except when |
| 1220 |
GNULIB_POSIXCHECK is defined. */ |
| 1221 |
|
| 1222 |
#if @GNULIB_SPRINTF_POSIX@ |
| 1223 |
# if @REPLACE_SPRINTF@ |
| 1224 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1225 |
# define sprintf rpl_sprintf |
| 1226 |
# endif |
| 1227 |
_GL_FUNCDECL_RPL (sprintf, int, |
| 1228 |
(char *restrict str, const char *restrict format, ...) |
| 1229 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 1230 |
_GL_ARG_NONNULL ((1, 2))); |
| 1231 |
_GL_CXXALIAS_RPL (sprintf, int, |
| 1232 |
(char *restrict str, const char *restrict format, ...)); |
| 1233 |
# else |
| 1234 |
_GL_CXXALIAS_SYS (sprintf, int, |
| 1235 |
(char *restrict str, const char *restrict format, ...)); |
| 1236 |
# endif |
| 1237 |
# if __GLIBC__ >= 2 |
| 1238 |
_GL_CXXALIASWARN (sprintf); |
| 1239 |
# endif |
| 1240 |
#elif defined GNULIB_POSIXCHECK |
| 1241 |
# undef sprintf |
| 1242 |
/* Assume sprintf is always declared. */ |
| 1243 |
_GL_WARN_ON_USE (sprintf, "sprintf is not always POSIX compliant - " |
| 1244 |
"use gnulib module sprintf-posix for portable " |
| 1245 |
"POSIX compliance"); |
| 1246 |
#endif |
| 1247 |
|
| 1248 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 1249 |
# undef tempnam |
| 1250 |
# define tempnam _tempnam |
| 1251 |
#endif |
| 1252 |
|
| 1253 |
#if @GNULIB_TMPFILE@ |
| 1254 |
# if @REPLACE_TMPFILE@ |
| 1255 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1256 |
# define tmpfile rpl_tmpfile |
| 1257 |
# endif |
| 1258 |
_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)); |
| 1259 |
_GL_CXXALIAS_RPL (tmpfile, FILE *, (void)); |
| 1260 |
# else |
| 1261 |
_GL_CXXALIAS_SYS (tmpfile, FILE *, (void)); |
| 1262 |
# endif |
| 1263 |
# if __GLIBC__ >= 2 |
| 1264 |
_GL_CXXALIASWARN (tmpfile); |
| 1265 |
# endif |
| 1266 |
#elif defined GNULIB_POSIXCHECK |
| 1267 |
# undef tmpfile |
| 1268 |
# if HAVE_RAW_DECL_TMPFILE |
| 1269 |
_GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " |
| 1270 |
"use gnulib module tmpfile for portability"); |
| 1271 |
# endif |
| 1272 |
#endif |
| 1273 |
|
| 1274 |
#if @GNULIB_VASPRINTF@ |
| 1275 |
/* Write formatted output to a string dynamically allocated with malloc(). |
| 1276 |
If the memory allocation succeeds, store the address of the string in |
| 1277 |
*RESULT and return the number of resulting bytes, excluding the trailing |
| 1278 |
NUL. Upon memory allocation error, or some other error, return -1. */ |
| 1279 |
# if @REPLACE_VASPRINTF@ |
| 1280 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1281 |
# define asprintf rpl_asprintf |
| 1282 |
# endif |
| 1283 |
_GL_FUNCDECL_RPL (asprintf, int, |
| 1284 |
(char **result, const char *format, ...) |
| 1285 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 1286 |
_GL_ARG_NONNULL ((1, 2))); |
| 1287 |
_GL_CXXALIAS_RPL (asprintf, int, |
| 1288 |
(char **result, const char *format, ...)); |
| 1289 |
# else |
| 1290 |
# if !@HAVE_VASPRINTF@ |
| 1291 |
_GL_FUNCDECL_SYS (asprintf, int, |
| 1292 |
(char **result, const char *format, ...) |
| 1293 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) |
| 1294 |
_GL_ARG_NONNULL ((1, 2))); |
| 1295 |
# endif |
| 1296 |
_GL_CXXALIAS_SYS (asprintf, int, |
| 1297 |
(char **result, const char *format, ...)); |
| 1298 |
# endif |
| 1299 |
_GL_CXXALIASWARN (asprintf); |
| 1300 |
# if @REPLACE_VASPRINTF@ |
| 1301 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1302 |
# define vasprintf rpl_vasprintf |
| 1303 |
# endif |
| 1304 |
_GL_FUNCDECL_RPL (vasprintf, int, |
| 1305 |
(char **result, const char *format, va_list args) |
| 1306 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1307 |
_GL_ARG_NONNULL ((1, 2))); |
| 1308 |
_GL_CXXALIAS_RPL (vasprintf, int, |
| 1309 |
(char **result, const char *format, va_list args)); |
| 1310 |
# else |
| 1311 |
# if !@HAVE_VASPRINTF@ |
| 1312 |
_GL_FUNCDECL_SYS (vasprintf, int, |
| 1313 |
(char **result, const char *format, va_list args) |
| 1314 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1315 |
_GL_ARG_NONNULL ((1, 2))); |
| 1316 |
# endif |
| 1317 |
_GL_CXXALIAS_SYS (vasprintf, int, |
| 1318 |
(char **result, const char *format, va_list args)); |
| 1319 |
# endif |
| 1320 |
_GL_CXXALIASWARN (vasprintf); |
| 1321 |
#endif |
| 1322 |
|
| 1323 |
#if @GNULIB_VDPRINTF@ |
| 1324 |
# if @REPLACE_VDPRINTF@ |
| 1325 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1326 |
# define vdprintf rpl_vdprintf |
| 1327 |
# endif |
| 1328 |
_GL_FUNCDECL_RPL (vdprintf, int, |
| 1329 |
(int fd, const char *restrict format, va_list args) |
| 1330 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1331 |
_GL_ARG_NONNULL ((2))); |
| 1332 |
_GL_CXXALIAS_RPL (vdprintf, int, |
| 1333 |
(int fd, const char *restrict format, va_list args)); |
| 1334 |
# else |
| 1335 |
# if !@HAVE_VDPRINTF@ |
| 1336 |
_GL_FUNCDECL_SYS (vdprintf, int, |
| 1337 |
(int fd, const char *restrict format, va_list args) |
| 1338 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1339 |
_GL_ARG_NONNULL ((2))); |
| 1340 |
# endif |
| 1341 |
/* Need to cast, because on Solaris, the third parameter will likely be |
| 1342 |
__va_list args. */ |
| 1343 |
_GL_CXXALIAS_SYS_CAST (vdprintf, int, |
| 1344 |
(int fd, const char *restrict format, va_list args)); |
| 1345 |
# endif |
| 1346 |
# if __GLIBC__ >= 2 |
| 1347 |
_GL_CXXALIASWARN (vdprintf); |
| 1348 |
# endif |
| 1349 |
#elif defined GNULIB_POSIXCHECK |
| 1350 |
# undef vdprintf |
| 1351 |
# if HAVE_RAW_DECL_VDPRINTF |
| 1352 |
_GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - " |
| 1353 |
"use gnulib module vdprintf for portability"); |
| 1354 |
# endif |
| 1355 |
#endif |
| 1356 |
|
| 1357 |
#if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@ |
| 1358 |
# if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \ |
| 1359 |
|| (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) |
| 1360 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1361 |
# define vfprintf rpl_vfprintf |
| 1362 |
# endif |
| 1363 |
# define GNULIB_overrides_vfprintf 1 |
| 1364 |
# if @GNULIB_VFPRINTF_POSIX@ |
| 1365 |
_GL_FUNCDECL_RPL (vfprintf, int, |
| 1366 |
(FILE *restrict fp, |
| 1367 |
const char *restrict format, va_list args) |
| 1368 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1369 |
_GL_ARG_NONNULL ((1, 2))); |
| 1370 |
# else |
| 1371 |
_GL_FUNCDECL_RPL (vfprintf, int, |
| 1372 |
(FILE *restrict fp, |
| 1373 |
const char *restrict format, va_list args) |
| 1374 |
_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (2, 0) |
| 1375 |
_GL_ARG_NONNULL ((1, 2))); |
| 1376 |
# endif |
| 1377 |
_GL_CXXALIAS_RPL (vfprintf, int, |
| 1378 |
(FILE *restrict fp, |
| 1379 |
const char *restrict format, va_list args)); |
| 1380 |
# else |
| 1381 |
/* Need to cast, because on Solaris, the third parameter is |
| 1382 |
__va_list args |
| 1383 |
and GCC's fixincludes did not change this to __gnuc_va_list. */ |
| 1384 |
_GL_CXXALIAS_SYS_CAST (vfprintf, int, |
| 1385 |
(FILE *restrict fp, |
| 1386 |
const char *restrict format, va_list args)); |
| 1387 |
# endif |
| 1388 |
# if __GLIBC__ >= 2 |
| 1389 |
_GL_CXXALIASWARN (vfprintf); |
| 1390 |
# endif |
| 1391 |
#endif |
| 1392 |
#if !@GNULIB_VFPRINTF_POSIX@ && defined GNULIB_POSIXCHECK |
| 1393 |
# if !GNULIB_overrides_vfprintf |
| 1394 |
# undef vfprintf |
| 1395 |
# endif |
| 1396 |
/* Assume vfprintf is always declared. */ |
| 1397 |
_GL_WARN_ON_USE (vfprintf, "vfprintf is not always POSIX compliant - " |
| 1398 |
"use gnulib module vfprintf-posix for portable " |
| 1399 |
"POSIX compliance"); |
| 1400 |
#endif |
| 1401 |
|
| 1402 |
#if @GNULIB_VFSCANF@ |
| 1403 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 1404 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1405 |
# undef vfscanf |
| 1406 |
# define vfscanf rpl_vfscanf |
| 1407 |
# endif |
| 1408 |
_GL_FUNCDECL_RPL (vfscanf, int, |
| 1409 |
(FILE *restrict stream, |
| 1410 |
const char *restrict format, va_list args) |
| 1411 |
_GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (2, 0) |
| 1412 |
_GL_ARG_NONNULL ((1, 2))); |
| 1413 |
_GL_CXXALIAS_RPL (vfscanf, int, |
| 1414 |
(FILE *restrict stream, |
| 1415 |
const char *restrict format, va_list args)); |
| 1416 |
# else |
| 1417 |
_GL_CXXALIAS_SYS (vfscanf, int, |
| 1418 |
(FILE *restrict stream, |
| 1419 |
const char *restrict format, va_list args)); |
| 1420 |
# endif |
| 1421 |
# if __GLIBC__ >= 2 |
| 1422 |
_GL_CXXALIASWARN (vfscanf); |
| 1423 |
# endif |
| 1424 |
#endif |
| 1425 |
|
| 1426 |
#if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ |
| 1427 |
# if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \ |
| 1428 |
|| (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) |
| 1429 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1430 |
# define vprintf rpl_vprintf |
| 1431 |
# endif |
| 1432 |
# define GNULIB_overrides_vprintf 1 |
| 1433 |
# if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ |
| 1434 |
_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) |
| 1435 |
_GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) |
| 1436 |
_GL_ARG_NONNULL ((1))); |
| 1437 |
# else |
| 1438 |
_GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) |
| 1439 |
_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM (1, 0) |
| 1440 |
_GL_ARG_NONNULL ((1))); |
| 1441 |
# endif |
| 1442 |
_GL_CXXALIAS_RPL (vprintf, int, (const char *restrict format, va_list args)); |
| 1443 |
# else |
| 1444 |
/* Need to cast, because on Solaris, the second parameter is |
| 1445 |
__va_list args |
| 1446 |
and GCC's fixincludes did not change this to __gnuc_va_list. */ |
| 1447 |
_GL_CXXALIAS_SYS_CAST (vprintf, int, |
| 1448 |
(const char *restrict format, va_list args)); |
| 1449 |
# endif |
| 1450 |
# if __GLIBC__ >= 2 |
| 1451 |
_GL_CXXALIASWARN (vprintf); |
| 1452 |
# endif |
| 1453 |
#endif |
| 1454 |
#if !@GNULIB_VPRINTF_POSIX@ && defined GNULIB_POSIXCHECK |
| 1455 |
# if !GNULIB_overrides_vprintf |
| 1456 |
# undef vprintf |
| 1457 |
# endif |
| 1458 |
/* Assume vprintf is always declared. */ |
| 1459 |
_GL_WARN_ON_USE (vprintf, "vprintf is not always POSIX compliant - " |
| 1460 |
"use gnulib module vprintf-posix for portable " |
| 1461 |
"POSIX compliance"); |
| 1462 |
#endif |
| 1463 |
|
| 1464 |
#if @GNULIB_VSCANF@ |
| 1465 |
# if @REPLACE_STDIO_READ_FUNCS@ && @GNULIB_STDIO_H_NONBLOCKING@ |
| 1466 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1467 |
# undef vscanf |
| 1468 |
# define vscanf rpl_vscanf |
| 1469 |
# endif |
| 1470 |
_GL_FUNCDECL_RPL (vscanf, int, (const char *restrict format, va_list args) |
| 1471 |
_GL_ATTRIBUTE_FORMAT_SCANF_SYSTEM (1, 0) |
| 1472 |
_GL_ARG_NONNULL ((1))); |
| 1473 |
_GL_CXXALIAS_RPL (vscanf, int, (const char *restrict format, va_list args)); |
| 1474 |
# else |
| 1475 |
_GL_CXXALIAS_SYS (vscanf, int, (const char *restrict format, va_list args)); |
| 1476 |
# endif |
| 1477 |
# if __GLIBC__ >= 2 |
| 1478 |
_GL_CXXALIASWARN (vscanf); |
| 1479 |
# endif |
| 1480 |
#endif |
| 1481 |
|
| 1482 |
#if @GNULIB_VSNPRINTF@ |
| 1483 |
# if @REPLACE_VSNPRINTF@ |
| 1484 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1485 |
# define vsnprintf rpl_vsnprintf |
| 1486 |
# endif |
| 1487 |
_GL_FUNCDECL_RPL (vsnprintf, int, |
| 1488 |
(char *restrict str, size_t size, |
| 1489 |
const char *restrict format, va_list args) |
| 1490 |
_GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) |
| 1491 |
_GL_ARG_NONNULL ((3))); |
| 1492 |
_GL_CXXALIAS_RPL (vsnprintf, int, |
| 1493 |
(char *restrict str, size_t size, |
| 1494 |
const char *restrict format, va_list args)); |
| 1495 |
# else |
| 1496 |
# if !@HAVE_DECL_VSNPRINTF@ |
| 1497 |
_GL_FUNCDECL_SYS (vsnprintf, int, |
| 1498 |
(char *restrict str, size_t size, |
| 1499 |
const char *restrict format, va_list args) |
| 1500 |
_GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) |
| 1501 |
_GL_ARG_NONNULL ((3))); |
| 1502 |
# endif |
| 1503 |
_GL_CXXALIAS_SYS (vsnprintf, int, |
| 1504 |
(char *restrict str, size_t size, |
| 1505 |
const char *restrict format, va_list args)); |
| 1506 |
# endif |
| 1507 |
# if __GLIBC__ >= 2 |
| 1508 |
_GL_CXXALIASWARN (vsnprintf); |
| 1509 |
# endif |
| 1510 |
#elif defined GNULIB_POSIXCHECK |
| 1511 |
# undef vsnprintf |
| 1512 |
# if HAVE_RAW_DECL_VSNPRINTF |
| 1513 |
_GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " |
| 1514 |
"use gnulib module vsnprintf for portability"); |
| 1515 |
# endif |
| 1516 |
#endif |
| 1517 |
|
| 1518 |
#if @GNULIB_VSPRINTF_POSIX@ |
| 1519 |
# if @REPLACE_VSPRINTF@ |
| 1520 |
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 1521 |
# define vsprintf rpl_vsprintf |
| 1522 |
# endif |
| 1523 |
_GL_FUNCDECL_RPL (vsprintf, int, |
| 1524 |
(char *restrict str, |
| 1525 |
const char *restrict format, va_list args) |
| 1526 |
_GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) |
| 1527 |
_GL_ARG_NONNULL ((1, 2))); |
| 1528 |
_GL_CXXALIAS_RPL (vsprintf, int, |
| 1529 |
(char *restrict str, |
| 1530 |
const char *restrict format, va_list args)); |
| 1531 |
# else |
| 1532 |
/* Need to cast, because on Solaris, the third parameter is |
| 1533 |
__va_list args |
| 1534 |
and GCC's fixincludes did not change this to __gnuc_va_list. */ |
| 1535 |
_GL_CXXALIAS_SYS_CAST (vsprintf, int, |
| 1536 |
(char *restrict str, |
| 1537 |
const char *restrict format, va_list args)); |
| 1538 |
# endif |
| 1539 |
# if __GLIBC__ >= 2 |
| 1540 |
_GL_CXXALIASWARN (vsprintf); |
| 1541 |
# endif |
| 1542 |
#elif defined GNULIB_POSIXCHECK |
| 1543 |
# undef vsprintf |
| 1544 |
/* Assume vsprintf is always declared. */ |
| 1545 |
_GL_WARN_ON_USE (vsprintf, "vsprintf is not always POSIX compliant - " |
| 1546 |
"use gnulib module vsprintf-posix for portable " |
| 1547 |
"POSIX compliance"); |
| 1548 |
#endif |
| 1549 |
|
| 1550 |
#endif /* _@GUARD_PREFIX@_STDIO_H */ |
| 1551 |
#endif /* _@GUARD_PREFIX@_STDIO_H */ |
| 1552 |
#endif |