mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-09 15:41:10 +03:00
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:
committed by
Jakub Jelen
parent
861590192f
commit
b58cb9f72b
@@ -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
|
||||
|
||||
29
src/misc.c
29
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
|
||||
* <tt>result</tt> 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;
|
||||
|
||||
Reference in New Issue
Block a user