Skip to content

Commit

Permalink
Handle platform differences in gmtime_s
Browse files Browse the repository at this point in the history
MSVC and C11 specify different arguments and return value
meaning for gmtime_s.

Signed-off-by: Dave Rodgman <[email protected]>
  • Loading branch information
daverodgman committed May 6, 2022
1 parent 489eb37 commit f74d2fa
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/platform_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void mbedtls_platform_zeroize( void *buf, size_t len )
#endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */

#if defined(MBEDTLS_HAVE_TIME_DATE) && !defined(MBEDTLS_PLATFORM_GMTIME_R_ALT)
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#if !defined(_WIN32) && (defined(unix) || \
defined(__unix) || defined(__unix__) || (defined(__APPLE__) && \
Expand Down Expand Up @@ -105,7 +106,12 @@ struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
struct tm *tm_buf )
{
#if defined(_WIN32) && !defined(PLATFORM_UTIL_USE_GMTIME)
#if defined(__STDC_LIB_EXT1__)
return( ( gmtime_s( tt, tm_buf ) == 0 ) ? NULL : tm_buf );
#else
/* MSVC and mingw64 argument order and return value are inconsistent with the C11 standard */
return( ( gmtime_s( tm_buf, tt ) == 0 ) ? tm_buf : NULL );
#endif
#elif !defined(PLATFORM_UTIL_USE_GMTIME)
return( gmtime_r( tt, tm_buf ) );
#else
Expand Down

0 comments on commit f74d2fa

Please sign in to comment.