windows doesnt have localtime_r
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
b33c72c770
commit
969212e1dd
2 changed files with 28 additions and 10 deletions
|
@ -923,24 +923,33 @@ lws_ensure_user_space(struct lws *wsi)
|
|||
LWS_VISIBLE void lwsl_emit_stderr(int level, const char *line)
|
||||
{
|
||||
time_t o_now = time(NULL);
|
||||
struct tm o_now_time;
|
||||
unsigned long long now;
|
||||
struct tm *ptm = NULL;
|
||||
char buf[300];
|
||||
int n, ok = localtime_r(&o_now, &o_now_time) != NULL;
|
||||
#ifndef WIN32
|
||||
struct tm tm;
|
||||
#endif
|
||||
int n;
|
||||
|
||||
#ifdef WIN32
|
||||
ptm = localtime(&o_now);
|
||||
#else
|
||||
if (localtime_r(&o_now, &tm))
|
||||
ptm = &tm;
|
||||
#endif
|
||||
buf[0] = '\0';
|
||||
for (n = 0; n < LLL_COUNT; n++) {
|
||||
if (level != (1 << n))
|
||||
continue;
|
||||
now = time_in_microseconds() / 100;
|
||||
if (ok)
|
||||
if (ptm)
|
||||
sprintf(buf, "[%04d/%02d/%02d %02d:%02d:%02d:%04d] %s: ",
|
||||
o_now_time.tm_year + 1900,
|
||||
o_now_time.tm_mon,
|
||||
o_now_time.tm_mday,
|
||||
o_now_time.tm_hour,
|
||||
o_now_time.tm_min,
|
||||
o_now_time.tm_sec,
|
||||
ptm->tm_year + 1900,
|
||||
ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
(int)(now % 10000), log_level_names[n]);
|
||||
else
|
||||
sprintf(buf, "[%llu:%04d] %s: ",
|
||||
|
|
|
@ -37,7 +37,10 @@ update_status(struct lws *wsi, struct per_session_data__lws_status *pss)
|
|||
char *p = cache;
|
||||
char date[128];
|
||||
time_t t;
|
||||
struct tm *ptm;
|
||||
#ifndef WIN32
|
||||
struct tm tm;
|
||||
#endif
|
||||
|
||||
p += snprintf(p, 512, " { %s, \"wsi\":\"%d\", \"conns\":[",
|
||||
server_info, live_wsi);
|
||||
|
@ -45,10 +48,16 @@ update_status(struct lws *wsi, struct per_session_data__lws_status *pss)
|
|||
/* render the list */
|
||||
while (*pp) {
|
||||
t = (*pp)->tv_established.tv_sec;
|
||||
#ifdef WIN32
|
||||
ptm = localtime(&t);
|
||||
if (!ptm)
|
||||
#else
|
||||
ptm = &tm;
|
||||
if (!localtime_r(&t, &tm))
|
||||
#endif
|
||||
strcpy(date, "unknown");
|
||||
else
|
||||
strftime(date, sizeof(date), "%F %H:%M %Z", &tm);
|
||||
strftime(date, sizeof(date), "%F %H:%M %Z", ptm);
|
||||
if ((p - cache) > (sizeof(cache) - 512))
|
||||
break;
|
||||
if (subsequent)
|
||||
|
|
Loading…
Add table
Reference in a new issue