diff options
Diffstat (limited to 'gl/time.in.h')
| -rw-r--r-- | gl/time.in.h | 142 |
1 files changed, 137 insertions, 5 deletions
diff --git a/gl/time.in.h b/gl/time.in.h index 50c9b30b..df99c8ab 100644 --- a/gl/time.in.h +++ b/gl/time.in.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* A more-standard <time.h>. | 1 | /* A more-standard <time.h>. |
| 2 | 2 | ||
| 3 | Copyright (C) 2007-2023 Free Software Foundation, Inc. | 3 | Copyright (C) 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 |
| @@ -20,6 +20,13 @@ | |||
| 20 | #endif | 20 | #endif |
| 21 | @PRAGMA_COLUMNS@ | 21 | @PRAGMA_COLUMNS@ |
| 22 | 22 | ||
| 23 | /* This file uses #include_next of a system file that defines time_t. | ||
| 24 | For the 'year2038' module to work right, <config.h> needs to have been | ||
| 25 | included before. */ | ||
| 26 | #if !_GL_CONFIG_H_INCLUDED | ||
| 27 | #error "Please include config.h first." | ||
| 28 | #endif | ||
| 29 | |||
| 23 | /* Don't get in the way of glibc when it includes time.h merely to | 30 | /* Don't get in the way of glibc when it includes time.h merely to |
| 24 | declare a few standard symbols, rather than to declare all the | 31 | declare a few standard symbols, rather than to declare all the |
| 25 | symbols. (However, skip this for MinGW as it treats __need_time_t | 32 | symbols. (However, skip this for MinGW as it treats __need_time_t |
| @@ -45,6 +52,12 @@ | |||
| 45 | 52 | ||
| 46 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ | 53 | # @INCLUDE_NEXT@ @NEXT_TIME_H@ |
| 47 | 54 | ||
| 55 | /* This file uses _GL_ATTRIBUTE_DEPRECATED, GNULIB_POSIXCHECK, | ||
| 56 | HAVE_RAW_DECL_*. */ | ||
| 57 | # if !_GL_CONFIG_H_INCLUDED | ||
| 58 | # error "Please include config.h first." | ||
| 59 | # endif | ||
| 60 | |||
| 48 | /* NetBSD 5.0 mis-defines NULL. */ | 61 | /* NetBSD 5.0 mis-defines NULL. */ |
| 49 | # include <stddef.h> | 62 | # include <stddef.h> |
| 50 | 63 | ||
| @@ -112,23 +125,79 @@ struct __time_t_must_be_integral { | |||
| 112 | /* Set *TS to the current time, and return BASE. | 125 | /* Set *TS to the current time, and return BASE. |
| 113 | Upon failure, return 0. */ | 126 | Upon failure, return 0. */ |
| 114 | # if @GNULIB_TIMESPEC_GET@ | 127 | # if @GNULIB_TIMESPEC_GET@ |
| 115 | # if ! @HAVE_TIMESPEC_GET@ | 128 | # if @REPLACE_TIMESPEC_GET@ |
| 129 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 130 | # undef timespec_get | ||
| 131 | # define timespec_get rpl_timespec_get | ||
| 132 | # endif | ||
| 133 | _GL_FUNCDECL_RPL (timespec_get, int, (struct timespec *ts, int base) | ||
| 134 | _GL_ARG_NONNULL ((1))); | ||
| 135 | _GL_CXXALIAS_RPL (timespec_get, int, (struct timespec *ts, int base)); | ||
| 136 | # else | ||
| 137 | # if !@HAVE_TIMESPEC_GET@ | ||
| 116 | _GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base) | 138 | _GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base) |
| 117 | _GL_ARG_NONNULL ((1))); | 139 | _GL_ARG_NONNULL ((1))); |
| 118 | # endif | 140 | # endif |
| 119 | _GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base)); | 141 | _GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base)); |
| 142 | # endif | ||
| 143 | # if __GLIBC__ >= 2 | ||
| 120 | _GL_CXXALIASWARN (timespec_get); | 144 | _GL_CXXALIASWARN (timespec_get); |
| 145 | # endif | ||
| 146 | # elif defined GNULIB_POSIXCHECK | ||
| 147 | # undef timespec_get | ||
| 148 | # if HAVE_RAW_DECL_TIMESPEC_GET | ||
| 149 | _GL_WARN_ON_USE (timespec_get, "timespec_get is unportable - " | ||
| 150 | "use gnulib module timespec_get for portability"); | ||
| 151 | # endif | ||
| 121 | # endif | 152 | # endif |
| 122 | 153 | ||
| 123 | /* Set *TS to the current time resolution, and return BASE. | 154 | /* Set *TS to the current time resolution, and return BASE. |
| 124 | Upon failure, return 0. */ | 155 | Upon failure, return 0. */ |
| 125 | # if @GNULIB_TIMESPEC_GETRES@ | 156 | # if @GNULIB_TIMESPEC_GETRES@ |
| 126 | # if ! @HAVE_TIMESPEC_GETRES@ | 157 | # if @REPLACE_TIMESPEC_GETRES@ |
| 158 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 159 | # undef timespec_getres | ||
| 160 | # define timespec_getres rpl_timespec_getres | ||
| 161 | # endif | ||
| 162 | _GL_FUNCDECL_RPL (timespec_getres, int, (struct timespec *ts, int base) | ||
| 163 | _GL_ARG_NONNULL ((1))); | ||
| 164 | _GL_CXXALIAS_RPL (timespec_getres, int, (struct timespec *ts, int base)); | ||
| 165 | # else | ||
| 166 | # if !@HAVE_TIMESPEC_GETRES@ | ||
| 127 | _GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base) | 167 | _GL_FUNCDECL_SYS (timespec_getres, int, (struct timespec *ts, int base) |
| 128 | _GL_ARG_NONNULL ((1))); | 168 | _GL_ARG_NONNULL ((1))); |
| 129 | # endif | 169 | # endif |
| 130 | _GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base)); | 170 | _GL_CXXALIAS_SYS (timespec_getres, int, (struct timespec *ts, int base)); |
| 171 | # endif | ||
| 131 | _GL_CXXALIASWARN (timespec_getres); | 172 | _GL_CXXALIASWARN (timespec_getres); |
| 173 | # elif defined GNULIB_POSIXCHECK | ||
| 174 | # undef timespec_getres | ||
| 175 | # if HAVE_RAW_DECL_TIMESPEC_GETRES | ||
| 176 | _GL_WARN_ON_USE (timespec_getres, "timespec_getres is unportable - " | ||
| 177 | "use gnulib module timespec_getres for portability"); | ||
| 178 | # endif | ||
| 179 | # endif | ||
| 180 | |||
| 181 | /* Return the number of seconds that have elapsed since the Epoch. */ | ||
| 182 | # if @GNULIB_TIME@ | ||
| 183 | # if @REPLACE_TIME@ | ||
| 184 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | ||
| 185 | # define time rpl_time | ||
| 186 | # endif | ||
| 187 | _GL_FUNCDECL_RPL (time, time_t, (time_t *__tp)); | ||
| 188 | _GL_CXXALIAS_RPL (time, time_t, (time_t *__tp)); | ||
| 189 | # else | ||
| 190 | _GL_CXXALIAS_SYS (time, time_t, (time_t *__tp)); | ||
| 191 | # endif | ||
| 192 | # if __GLIBC__ >= 2 | ||
| 193 | _GL_CXXALIASWARN (time); | ||
| 194 | # endif | ||
| 195 | # elif defined GNULIB_POSIXCHECK | ||
| 196 | # undef time | ||
| 197 | # if HAVE_RAW_DECL_TIME | ||
| 198 | _GL_WARN_ON_USE (time, "time has consistency problems - " | ||
| 199 | "use gnulib module time for portability"); | ||
| 200 | # endif | ||
| 132 | # endif | 201 | # endif |
| 133 | 202 | ||
| 134 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, | 203 | /* Sleep for at least RQTP seconds unless interrupted, If interrupted, |
| @@ -154,6 +223,12 @@ _GL_CXXALIAS_SYS (nanosleep, int, | |||
| 154 | (struct timespec const *__rqtp, struct timespec *__rmtp)); | 223 | (struct timespec const *__rqtp, struct timespec *__rmtp)); |
| 155 | # endif | 224 | # endif |
| 156 | _GL_CXXALIASWARN (nanosleep); | 225 | _GL_CXXALIASWARN (nanosleep); |
| 226 | # elif defined GNULIB_POSIXCHECK | ||
| 227 | # undef nanosleep | ||
| 228 | # if HAVE_RAW_DECL_NANOSLEEP | ||
| 229 | _GL_WARN_ON_USE (nanosleep, "nanosleep is unportable - " | ||
| 230 | "use gnulib module nanosleep for portability"); | ||
| 231 | # endif | ||
| 157 | # endif | 232 | # endif |
| 158 | 233 | ||
| 159 | /* Initialize time conversion information. */ | 234 | /* Initialize time conversion information. */ |
| @@ -189,6 +264,12 @@ _GL_CXXALIAS_MDA (tzset, void, (void)); | |||
| 189 | _GL_CXXALIAS_SYS (tzset, void, (void)); | 264 | _GL_CXXALIAS_SYS (tzset, void, (void)); |
| 190 | # endif | 265 | # endif |
| 191 | _GL_CXXALIASWARN (tzset); | 266 | _GL_CXXALIASWARN (tzset); |
| 267 | # elif defined GNULIB_POSIXCHECK | ||
| 268 | # undef tzset | ||
| 269 | # if HAVE_RAW_DECL_TZSET | ||
| 270 | _GL_WARN_ON_USE (tzset, "tzset has portability problems - " | ||
| 271 | "use gnulib module tzset for portability"); | ||
| 272 | # endif | ||
| 192 | # endif | 273 | # endif |
| 193 | 274 | ||
| 194 | /* Return the 'time_t' representation of TP and normalize TP. */ | 275 | /* Return the 'time_t' representation of TP and normalize TP. */ |
| @@ -205,6 +286,12 @@ _GL_CXXALIAS_SYS (mktime, time_t, (struct tm *__tp)); | |||
| 205 | # if __GLIBC__ >= 2 | 286 | # if __GLIBC__ >= 2 |
| 206 | _GL_CXXALIASWARN (mktime); | 287 | _GL_CXXALIASWARN (mktime); |
| 207 | # endif | 288 | # endif |
| 289 | # elif defined GNULIB_POSIXCHECK | ||
| 290 | # undef mktime | ||
| 291 | # if HAVE_RAW_DECL_MKTIME | ||
| 292 | _GL_WARN_ON_USE (mktime, "mktime has portability problems - " | ||
| 293 | "use gnulib module mktime for portability"); | ||
| 294 | # endif | ||
| 208 | # endif | 295 | # endif |
| 209 | 296 | ||
| 210 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See | 297 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See |
| @@ -255,6 +342,17 @@ _GL_CXXALIAS_SYS (gmtime_r, struct tm *, (time_t const *restrict __timer, | |||
| 255 | # if @HAVE_DECL_LOCALTIME_R@ | 342 | # if @HAVE_DECL_LOCALTIME_R@ |
| 256 | _GL_CXXALIASWARN (gmtime_r); | 343 | _GL_CXXALIASWARN (gmtime_r); |
| 257 | # endif | 344 | # endif |
| 345 | # elif defined GNULIB_POSIXCHECK | ||
| 346 | # undef localtime_r | ||
| 347 | # if HAVE_RAW_DECL_LOCALTIME_R | ||
| 348 | _GL_WARN_ON_USE (localtime_r, "localtime_r is unportable - " | ||
| 349 | "use gnulib module time_r for portability"); | ||
| 350 | # endif | ||
| 351 | # undef gmtime_r | ||
| 352 | # if HAVE_RAW_DECL_GMTIME_R | ||
| 353 | _GL_WARN_ON_USE (gmtime_r, "gmtime_r is unportable - " | ||
| 354 | "use gnulib module time_r for portability"); | ||
| 355 | # endif | ||
| 258 | # endif | 356 | # endif |
| 259 | 357 | ||
| 260 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See | 358 | /* Convert TIMER to RESULT, assuming local time and UTC respectively. See |
| @@ -275,6 +373,12 @@ _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer)); | |||
| 275 | # if __GLIBC__ >= 2 | 373 | # if __GLIBC__ >= 2 |
| 276 | _GL_CXXALIASWARN (localtime); | 374 | _GL_CXXALIASWARN (localtime); |
| 277 | # endif | 375 | # endif |
| 376 | # elif defined GNULIB_POSIXCHECK | ||
| 377 | # undef localtime | ||
| 378 | # if HAVE_RAW_DECL_LOCALTIME | ||
| 379 | _GL_WARN_ON_USE (localtime, "localtime has portability problems - " | ||
| 380 | "use gnulib module localtime for portability"); | ||
| 381 | # endif | ||
| 278 | # endif | 382 | # endif |
| 279 | 383 | ||
| 280 | # if 0 || @REPLACE_GMTIME@ | 384 | # if 0 || @REPLACE_GMTIME@ |
| @@ -306,6 +410,12 @@ _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf, | |||
| 306 | char const *restrict __format, | 410 | char const *restrict __format, |
| 307 | struct tm *restrict __tm)); | 411 | struct tm *restrict __tm)); |
| 308 | _GL_CXXALIASWARN (strptime); | 412 | _GL_CXXALIASWARN (strptime); |
| 413 | # elif defined GNULIB_POSIXCHECK | ||
| 414 | # undef strptime | ||
| 415 | # if HAVE_RAW_DECL_STRPTIME | ||
| 416 | _GL_WARN_ON_USE (strptime, "strptime is unportable - " | ||
| 417 | "use gnulib module strptime for portability"); | ||
| 418 | # endif | ||
| 309 | # endif | 419 | # endif |
| 310 | 420 | ||
| 311 | /* Convert *TP to a date and time string. See | 421 | /* Convert *TP to a date and time string. See |
| @@ -315,7 +425,9 @@ _GL_CXXALIASWARN (strptime); | |||
| 315 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | 425 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
| 316 | # define ctime rpl_ctime | 426 | # define ctime rpl_ctime |
| 317 | # endif | 427 | # endif |
| 428 | # ifndef __cplusplus | ||
| 318 | _GL_ATTRIBUTE_DEPRECATED | 429 | _GL_ATTRIBUTE_DEPRECATED |
| 430 | # endif | ||
| 319 | _GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp) | 431 | _GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp) |
| 320 | _GL_ARG_NONNULL ((1))); | 432 | _GL_ARG_NONNULL ((1))); |
| 321 | _GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp)); | 433 | _GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp)); |
| @@ -325,6 +437,8 @@ _GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp)); | |||
| 325 | # if __GLIBC__ >= 2 | 437 | # if __GLIBC__ >= 2 |
| 326 | _GL_CXXALIASWARN (ctime); | 438 | _GL_CXXALIASWARN (ctime); |
| 327 | # endif | 439 | # endif |
| 440 | # elif defined GNULIB_POSIXCHECK | ||
| 441 | /* No need to warn about portability, as a more serious warning is below. */ | ||
| 328 | # endif | 442 | # endif |
| 329 | 443 | ||
| 330 | /* Convert *TP to a date and time string. See | 444 | /* Convert *TP to a date and time string. See |
| @@ -349,6 +463,12 @@ _GL_CXXALIAS_SYS (strftime, size_t, | |||
| 349 | # if __GLIBC__ >= 2 | 463 | # if __GLIBC__ >= 2 |
| 350 | _GL_CXXALIASWARN (strftime); | 464 | _GL_CXXALIASWARN (strftime); |
| 351 | # endif | 465 | # endif |
| 466 | # elif defined GNULIB_POSIXCHECK | ||
| 467 | # undef strftime | ||
| 468 | # if HAVE_RAW_DECL_STRFTIME | ||
| 469 | _GL_WARN_ON_USE (strftime, "strftime has portability problems - " | ||
| 470 | "use gnulib module strftime-fixes for portability"); | ||
| 471 | # endif | ||
| 352 | # endif | 472 | # endif |
| 353 | 473 | ||
| 354 | # if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@ | 474 | # if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@ |
| @@ -423,7 +543,15 @@ _GL_FUNCDECL_SYS (timegm, time_t, (struct tm *__tm) _GL_ARG_NONNULL ((1))); | |||
| 423 | # endif | 543 | # endif |
| 424 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); | 544 | _GL_CXXALIAS_SYS (timegm, time_t, (struct tm *__tm)); |
| 425 | # endif | 545 | # endif |
| 546 | # if __GLIBC__ >= 2 | ||
| 426 | _GL_CXXALIASWARN (timegm); | 547 | _GL_CXXALIASWARN (timegm); |
| 548 | # endif | ||
| 549 | # elif defined GNULIB_POSIXCHECK | ||
| 550 | # undef timegm | ||
| 551 | # if HAVE_RAW_DECL_TIMEGM | ||
| 552 | _GL_WARN_ON_USE (timegm, "timegm is unportable - " | ||
| 553 | "use gnulib module timegm for portability"); | ||
| 554 | # endif | ||
| 427 | # endif | 555 | # endif |
| 428 | 556 | ||
| 429 | /* Encourage applications to avoid unsafe functions that can overrun | 557 | /* Encourage applications to avoid unsafe functions that can overrun |
| @@ -431,8 +559,10 @@ _GL_CXXALIASWARN (timegm); | |||
| 431 | applications should use strftime (or even sprintf) instead. */ | 559 | applications should use strftime (or even sprintf) instead. */ |
| 432 | # if defined GNULIB_POSIXCHECK | 560 | # if defined GNULIB_POSIXCHECK |
| 433 | # undef asctime | 561 | # undef asctime |
| 562 | # if HAVE_RAW_DECL_ASCTIME | ||
| 434 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " | 563 | _GL_WARN_ON_USE (asctime, "asctime can overrun buffers in some cases - " |
| 435 | "better use strftime (or even sprintf) instead"); | 564 | "better use strftime (or even sprintf) instead"); |
| 565 | # endif | ||
| 436 | # endif | 566 | # endif |
| 437 | # if defined GNULIB_POSIXCHECK | 567 | # if defined GNULIB_POSIXCHECK |
| 438 | # undef asctime_r | 568 | # undef asctime_r |
| @@ -443,8 +573,10 @@ _GL_WARN_ON_USE (asctime_r, "asctime_r can overrun buffers in some cases - " | |||
| 443 | # endif | 573 | # endif |
| 444 | # if defined GNULIB_POSIXCHECK | 574 | # if defined GNULIB_POSIXCHECK |
| 445 | # undef ctime | 575 | # undef ctime |
| 576 | # if HAVE_RAW_DECL_CTIME | ||
| 446 | _GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - " | 577 | _GL_WARN_ON_USE (ctime, "ctime can overrun buffers in some cases - " |
| 447 | "better use strftime (or even sprintf) instead"); | 578 | "better use strftime (or even sprintf) instead"); |
| 579 | # endif | ||
| 448 | # endif | 580 | # endif |
| 449 | # if defined GNULIB_POSIXCHECK | 581 | # if defined GNULIB_POSIXCHECK |
| 450 | # undef ctime_r | 582 | # undef ctime_r |
