mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
misc: replace gettimeofday() with ssh2_now() in ssh2_deb_low()
To de-duplicate current-time methods, to avoid relying on deprecated
`gettimeofday()` in core code, and to avoid an additional
Windows-specific retrieval method.
Also:
- add and use `SSH2_TIME_T_FORMAT` macro.
Follow-up to c97959e9b6 #2489
Cherry-picked from #2485
Closes #2490
This commit is contained in:
@@ -308,6 +308,7 @@ typedef enum {
|
||||
|
||||
#define ssh2_time_t libssh2_int64_t /* us */
|
||||
#define ssh2_timediff_t libssh2_int64_t /* us */
|
||||
#define SSH2_TIME_T_FORMAT SSH2_INT64_T_FORMAT
|
||||
#define ssh2_sec_to_timediff(sec) ((ssh2_time_t)(sec) * 1000000)
|
||||
#define ssh2_timediff_to_sec(td) ((td) / 1000000)
|
||||
#define ssh2_timediff_to_usec(td) ((td) % 1000000)
|
||||
|
||||
21
src/misc.c
21
src/misc.c
@@ -554,12 +554,12 @@ void ssh2_deb_low(LIBSSH2_SESSION *session, int context,
|
||||
"Publickey",
|
||||
"Socket",
|
||||
};
|
||||
static long firstsec;
|
||||
static ssh2_time_t firstnow;
|
||||
|
||||
char buffer[1536];
|
||||
int len, msglen, buflen = sizeof(buffer);
|
||||
va_list vargs;
|
||||
struct timeval now;
|
||||
ssh2_time_t now;
|
||||
const char *contexttext = contexts[0];
|
||||
unsigned int contextindex;
|
||||
|
||||
@@ -575,14 +575,17 @@ void ssh2_deb_low(LIBSSH2_SESSION *session, int context,
|
||||
}
|
||||
}
|
||||
|
||||
ssh2_gettimeofday(&now, NULL);
|
||||
if(!firstsec)
|
||||
firstsec = now.tv_sec;
|
||||
now.tv_sec -= firstsec;
|
||||
now = ssh2_now();
|
||||
if(!firstnow)
|
||||
firstnow = now;
|
||||
now -= firstnow;
|
||||
|
||||
/* '[libssh2] 9999999999.9999999999 Failure Event: ' */
|
||||
len = ssh2_snprintf(buffer, buflen, "[libssh2] %d.%06d %s: ",
|
||||
(int)now.tv_sec, (int)now.tv_usec, contexttext);
|
||||
/* '[libssh2] 99999999999999999999.99999999999999999999 Failure Event: ' */
|
||||
len = ssh2_snprintf(buffer, buflen, "[libssh2]"
|
||||
" %" SSH2_TIME_T_FORMAT ".%06" SSH2_TIME_T_FORMAT
|
||||
" %s: ",
|
||||
ssh2_timediff_to_sec(now),
|
||||
ssh2_timediff_to_usec(now), contexttext);
|
||||
if(len < 0 || len >= buflen) {
|
||||
msglen = len < 0 ? 0 : (buflen - 1);
|
||||
buffer[msglen] = '\0';
|
||||
|
||||
Reference in New Issue
Block a user