mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 19:45:41 -04:00

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.
54 lines
1.7 KiB
C
54 lines
1.7 KiB
C
/***************************************************************************
|
|
* ROM Properties Page shell extension. *
|
|
* time_r.h: Workaround for missing time functions. *
|
|
* *
|
|
* Copyright (c) 2017-2023 by David Korth. *
|
|
* SPDX-License-Identifier: GPL-2.0-or-later *
|
|
***************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#include "config.libc.h"
|
|
|
|
// _POSIX_C_SOURCE is required for *_r() on MinGW-w64.
|
|
// However, this breaks snprintf() on FreeBSD when using clang/libc++,
|
|
// so only define it on Windows.
|
|
// Reference: https://github.com/pocoproject/poco/issues/1045#issuecomment-245987081
|
|
#ifdef _WIN32
|
|
# ifndef _POSIX_C_SOURCE
|
|
# define _POSIX_C_SOURCE 1
|
|
# endif
|
|
#endif /* _WIN32 */
|
|
#include <time.h>
|
|
|
|
/** timegm() **/
|
|
|
|
/**
|
|
* Linux, Mac OS X, and other Unix-like operating systems have a
|
|
* function timegm() that converts `struct tm` to `time_t`.
|
|
*
|
|
* MSVCRT's equivalent function is _mkgmtime(). Note that it might
|
|
* write to the original `struct tm`, so we'll need to make a copy.
|
|
*
|
|
* NOTE: timegm() is NOT part of *any* standard!
|
|
*/
|
|
#if !defined(HAVE_TIMEGM)
|
|
static inline time_t timegm(struct tm *tm)
|
|
{
|
|
struct tm my_tm;
|
|
my_tm = *tm;
|
|
#if defined(HAVE__MKGMTIME64)
|
|
# define USING_MSVCRT_MKGMTIME 1
|
|
return _mkgmtime64(&my_tm);
|
|
#elif defined(HAVE__MKGMTIME32)
|
|
# define USING_MSVCRT_MKGMTIME 1
|
|
return _mkgmtime32(&my_tm);
|
|
#elif defined(HAVE__MKGMTIME)
|
|
# define USING_MSVCRT_MKGMTIME 1
|
|
return _mkgmtime(&my_tm);
|
|
#else
|
|
# error timegm() or equivalent function not found.
|
|
#endif
|
|
}
|
|
#endif /* !HAVE_TIMEGM */
|