mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-22 11:36:21 +00:00
Fix #1256
This commit is contained in:
1 parent
758572872d
commit
7851930ac3
5 files changed
+28
-4
No files matched your search
+3
-2
@@ -1070,6 +1070,7 @@ static void printdirentry(struct mg_connection *c, const char *name,
|
||||
char size[64], mod[64], path[MG_PATH_MAX];
|
||||
int is_dir = S_ISDIR(stp->st_mode), n = 0;
|
||||
const char *slash = is_dir ? "/" : "";
|
||||
struct tm t;
|
||||
|
||||
if (is_dir) {
|
||||
snprintf(size, sizeof(size), "%s", "[DIR]");
|
||||
@@ -1084,7 +1085,7 @@ static void printdirentry(struct mg_connection *c, const char *name,
|
||||
snprintf(size, sizeof(size), "%.1fG", (double) stp->st_size / 1073741824);
|
||||
}
|
||||
}
|
||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&stp->st_mtime));
|
||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&stp->st_mtime, &t));
|
||||
n = mg_url_encode(name, strlen(name), path, sizeof(path));
|
||||
mg_printf(c,
|
||||
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
||||
@@ -1543,7 +1544,7 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
if (level <= max) {
|
||||
char timebuf[21], buf[50] = "";
|
||||
time_t t = time(NULL);
|
||||
struct tm *tm = gmtime(&t);
|
||||
struct tm tmp, *tm = gmtime_r(&t, &tmp);
|
||||
int n, tag;
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm);
|
||||
tag = level == LL_ERROR ? 'E' : level == LL_INFO ? 'I' : ' ';
|
||||
|
||||
+11
@@ -335,6 +335,17 @@ typedef int socklen_t;
|
||||
|
||||
#define MG_INT64_FMT "%I64d"
|
||||
|
||||
// https://lgtm.com/rules/2154840805/ -gmtime, localtime, ctime and asctime
|
||||
static __inline struct tm *gmtime_r(time_t *t, struct tm *tm) {
|
||||
(void) tm;
|
||||
return gmtime(t);
|
||||
}
|
||||
|
||||
static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {
|
||||
(void) tm;
|
||||
return localtime(t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -67,4 +67,15 @@ typedef int socklen_t;
|
||||
|
||||
#define MG_INT64_FMT "%I64d"
|
||||
|
||||
// https://lgtm.com/rules/2154840805/ -gmtime, localtime, ctime and asctime
|
||||
static __inline struct tm *gmtime_r(time_t *t, struct tm *tm) {
|
||||
(void) tm;
|
||||
return gmtime(t);
|
||||
}
|
||||
|
||||
static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {
|
||||
(void) tm;
|
||||
return localtime(t);
|
||||
}
|
||||
|
||||
#endif
|
||||
+2
-1
@@ -648,6 +648,7 @@ static void printdirentry(struct mg_connection *c, const char *name,
|
||||
char size[64], mod[64], path[MG_PATH_MAX];
|
||||
int is_dir = S_ISDIR(stp->st_mode), n = 0;
|
||||
const char *slash = is_dir ? "/" : "";
|
||||
struct tm t;
|
||||
|
||||
if (is_dir) {
|
||||
snprintf(size, sizeof(size), "%s", "[DIR]");
|
||||
@@ -662,7 +663,7 @@ static void printdirentry(struct mg_connection *c, const char *name,
|
||||
snprintf(size, sizeof(size), "%.1fG", (double) stp->st_size / 1073741824);
|
||||
}
|
||||
}
|
||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&stp->st_mtime));
|
||||
strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime_r(&stp->st_mtime, &t));
|
||||
n = mg_url_encode(name, strlen(name), path, sizeof(path));
|
||||
mg_printf(c,
|
||||
" <tr><td><a href=\"%.*s%s\">%s%s</a></td>"
|
||||
|
||||
@@ -35,7 +35,7 @@ bool mg_log_prefix(int level, const char *file, int line, const char *fname) {
|
||||
if (level <= max) {
|
||||
char timebuf[21], buf[50] = "";
|
||||
time_t t = time(NULL);
|
||||
struct tm *tm = gmtime(&t);
|
||||
struct tm tmp, *tm = gmtime_r(&t, &tmp);
|
||||
int n, tag;
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm);
|
||||
tag = level == LL_ERROR ? 'E' : level == LL_INFO ? 'I' : ' ';
|
||||
|
||||
Reference in new issue
Block a user