mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
New function ltime() returns a struct tm of the current local time.
Fixes crashes when time() returns (time_t)-1 on Windows by using the Win32 GetLocalTime() function. (The Unix implementation still just uses time() and localtime().) [originally from svn r5086]
This commit is contained in:
@ -661,7 +661,7 @@ int do_reconfig(HWND hwnd, int protcfginfo)
|
||||
void logevent(void *frontend, const char *string)
|
||||
{
|
||||
char timebuf[40];
|
||||
time_t t;
|
||||
struct tm tm;
|
||||
|
||||
log_eventlog(logctx, string);
|
||||
|
||||
@ -670,9 +670,8 @@ void logevent(void *frontend, const char *string)
|
||||
events = sresize(events, negsize, char *);
|
||||
}
|
||||
|
||||
time(&t);
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t",
|
||||
localtime(&t));
|
||||
tm=ltime();
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm);
|
||||
|
||||
events[nevents] = snewn(strlen(timebuf) + strlen(string) + 1, char);
|
||||
strcpy(events[nevents], timebuf);
|
||||
|
@ -1279,14 +1279,12 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
*/
|
||||
*state->commentptr = snewn(30, char);
|
||||
{
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
time(&t);
|
||||
tm = localtime(&t);
|
||||
struct tm tm;
|
||||
tm = ltime();
|
||||
if (state->is_dsa)
|
||||
strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", tm);
|
||||
strftime(*state->commentptr, 30, "dsa-key-%Y%m%d", &tm);
|
||||
else
|
||||
strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", tm);
|
||||
strftime(*state->commentptr, 30, "rsa-key-%Y%m%d", &tm);
|
||||
}
|
||||
|
||||
/*
|
||||
|
20
windows/wintime.c
Normal file
20
windows/wintime.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include "putty.h"
|
||||
#include <time.h>
|
||||
|
||||
struct tm ltime(void)
|
||||
{
|
||||
SYSTEMTIME st;
|
||||
struct tm tm;
|
||||
|
||||
GetLocalTime(&st);
|
||||
tm.tm_sec=st.wSecond;
|
||||
tm.tm_min=st.wMinute;
|
||||
tm.tm_hour=st.wHour;
|
||||
tm.tm_mday=st.wDay;
|
||||
tm.tm_mon=st.wMonth-1;
|
||||
tm.tm_year=(st.wYear>=1900?st.wYear-1900:0);
|
||||
tm.tm_wday=st.wDayOfWeek;
|
||||
tm.tm_yday=-1; /* GetLocalTime doesn't tell us */
|
||||
tm.tm_isdst=0; /* GetLocalTime doesn't tell us */
|
||||
return tm;
|
||||
}
|
Reference in New Issue
Block a user