Skip to content

Commit

Permalink
time_r.h: Remove gmtime_r() and localtime_r() wrappers.
Browse files Browse the repository at this point in the history
It seems these were only ever used in librpbase/TextOut_text.cpp.
The UI frontends use functions specific to the UI framework in use.

libfmt's <fmt/chrono.h> header has its own fmt::gmtime() and
fmt::localtime() wrappers, which do basically the same thing as
time_r.h did: _r() if available, or _s() on Windows; and fall
back to the non-reentrant version as a last resort.

CMakeLists.txt: Remove the gmtime_r() and localtime_r() checks.
  • Loading branch information
GerbilSoft committed Jan 24, 2025
1 parent f9ec7d2 commit 137a7c0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 65 deletions.
12 changes: 1 addition & 11 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ CHECK_INCLUDE_FILE("dirent.h" HAVE_DIRENT_H)
# Windows Universal CRT has this; older versions of MSVCRT do not.
CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)

# Check for reentrant time functions.
# Check for timegm() or equivalent function.
# NOTE: May be _gmtime32_s() or _gmtime64_s() on MSVC 2005+.
# The "inline" part will detect that.
INCLUDE(CheckSymbolExistsOrInline)
CHECK_SYMBOL_EXISTS_OR_INLINE(gmtime_r "time.h" "time_t tm; gmtime_r(&tm, NULL);" HAVE_GMTIME_R)
IF(NOT HAVE_GMTIME_R)
CHECK_SYMBOL_EXISTS_OR_INLINE(gmtime_s "time.h" "time_t tm; gmtime_s(NULL, &tm);" HAVE_GMTIME_S)
ENDIF(NOT HAVE_GMTIME_R)
CHECK_SYMBOL_EXISTS_OR_INLINE(localtime_r "time.h" "time_t tm; localtime_r(&tm, NULL);" HAVE_LOCALTIME_R)
IF(NOT HAVE_LOCALTIME_R)
CHECK_SYMBOL_EXISTS_OR_INLINE(localtime_s "time.h" "time_t tm; localtime_s(NULL, &tm);" HAVE_LOCALTIME_S)
ENDIF(NOT HAVE_LOCALTIME_R)

# Other time functions.
CHECK_SYMBOL_EXISTS_OR_INLINE(timegm "time.h" "struct tm tm; time_t x = timegm(&tm);" HAVE_TIMEGM)
IF(NOT HAVE_TIMEGM)
# NOTE: MSVCRT's _mkgmtime64() has a range of [1970/01/01, 3000/12/31].
Expand Down
12 changes: 0 additions & 12 deletions src/config.libc.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@

/** Time functions **/

/* Define to 1 if you have the `gmtime_r` function. */
#cmakedefine HAVE_GMTIME_R 1

/* Define to 1 if you have the `gmtime_s` function. */
#cmakedefine HAVE_GMTIME_S 1

/* Define to 1 if you have the `localtime_r' function. */
#cmakedefine HAVE_LOCALTIME_R 1

/* Define to 1 if you have the `localtime_s' function. */
#cmakedefine HAVE_LOCALTIME_S 1

/* Define to 1 if you have the `timegm' function. */
#cmakedefine HAVE_TIMEGM 1

Expand Down
42 changes: 0 additions & 42 deletions src/time_r.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,6 @@
#endif /* _WIN32 */
#include <time.h>

#ifndef HAVE_GMTIME_R
# ifdef gmtime_r
// Old MinGW-w64 (3.1.0, Ubuntu 14.04) has incompatible *_r() macros.
# undef gmtime_r
# endif
static inline struct tm *gmtime_r(const time_t *timep, struct tm *result)
{
#ifdef HAVE_GMTIME_S
return (gmtime_s(result, timep) == 0 ? result : NULL);
#else /* !HAVE_GMTIME_S */
// cppcheck-suppress gmtimeCalled
struct tm *tm = gmtime(timep);
if (tm && result) {
*result = *tm;
return result;
}
return NULL;
#endif /* GMTIME_S */
}
#endif /* HAVE_GMTIME_R */

#ifndef HAVE_LOCALTIME_R
# ifdef localtime_r
// Old MinGW-w64 (3.1.0, Ubuntu 14.04) has incompatible *_r() macros.
# undef localtime_r
# endif
static inline struct tm *localtime_r(const time_t *timep, struct tm *result)
{
#ifdef HAVE_LOCALTIME_S
return (localtime_s(result, timep) == 0 ? result : NULL);
#else /* !HAVE_LOCALTIME_S */
// cppcheck-suppress localtimeCalled
struct tm *tm = localtime(timep);
if (tm && result) {
*result = *tm;
return result;
}
return NULL;
#endif /* HAVE_LOCALTIME_S */
}
#endif /* HAVE_LOCALTIME_R */

/** timegm() **/

/**
Expand Down

0 comments on commit 137a7c0

Please sign in to comment.