misc.c, priv.h: Add support for localtime_r() on Windows

Windows supports localtime_s() instead of POSIX's localtime_r()
and the function prototype of localtime_s() is different as compared
to localtime_r().

This commit introduces ssh_localtime() (having same prototype as localtime_r())
for Windows which acts as a wrapper for localtime_s(), and defines localtime_r
as a macro which expands to ssh_localtime for Windows.

As a result, libssh can now use localtime_r() on Windows in the same manner
as localtime_r() can be used on POSIX systems.

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Eshan Kelkar
2024-08-13 11:52:21 +05:30
committed by Jakub Jelen
parent 861590192f
commit b58cb9f72b
2 changed files with 33 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#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