diff --git a/include/libssh/priv.h b/include/libssh/priv.h index 35fd8506..e164154b 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -34,6 +34,7 @@ #include #include #include +#include #if !defined(HAVE_STRTOULL) # if defined(HAVE___STRTOULL) @@ -164,6 +165,9 @@ int ssh_gettimeofday(struct timeval *__p, void *__t); #define gettimeofday ssh_gettimeofday +struct tm *ssh_localtime(const time_t *timer, struct tm *result); +# define localtime_r ssh_localtime + #define _XCLOSESOCKET closesocket # ifdef HAVE_IO_H diff --git a/src/misc.c b/src/misc.c index 7fe243f5..349f407a 100644 --- a/src/misc.c +++ b/src/misc.c @@ -178,6 +178,35 @@ int ssh_gettimeofday(struct timeval *__p, void *__t) return (0); } +/** + * @internal + * + * @brief Convert time in seconds since the Epoch to broken-down local time + * + * This is a helper used to provide localtime_r() like function interface + * on Windows. + * + * @param timer Pointer to a location storing the time_t which + * represents the time in seconds since the Epoch. + * + * @param result Pointer to a location where the broken-down time + * (expressed as local time) should be stored. + * + * @returns A pointer to the structure pointed to by the parameter + * result on success, NULL on error with the errno + * set to indicate the error. + */ +struct tm *ssh_localtime(const time_t *timer, struct tm *result) +{ + errno_t rc; + rc = localtime_s(result, timer); + if (rc != 0) { + return NULL; + } + + return result; +} + char *ssh_get_local_username(void) { DWORD size = 0;