summaryrefslogtreecommitdiff
path: root/src/MESA_field_stat.cpp
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2018-12-11 14:49:57 +0600
committerzhengchao <[email protected]>2018-12-11 14:49:57 +0600
commit23ae669c44584c8e64b555e243072567e595a708 (patch)
treea9c3847fbf036f25fe5af70cd55ded26804c0155 /src/MESA_field_stat.cpp
parent92761d171ee65f8999d1e8513c95d3801c2635d7 (diff)
使用线程安全的ctime_r输出时间。
Diffstat (limited to 'src/MESA_field_stat.cpp')
-rw-r--r--src/MESA_field_stat.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/MESA_field_stat.cpp b/src/MESA_field_stat.cpp
index 1fcc01e..6dbfe9b 100644
--- a/src/MESA_field_stat.cpp
+++ b/src/MESA_field_stat.cpp
@@ -1371,6 +1371,8 @@ void FS_passive_output(screen_stat_handle_t handle)
struct timespec now;
time_t current=0;
char date_buff[32];
+ //he reentrant version ctime_r() does the same, but stores the string in a user-supplied buffer which should have room for at least 26 bytes.
+ char ctime_buff[32]={0};
char* print_buf=NULL;
size_t print_buf_sz=_handle->display_cnt*1024;
char*pos=NULL;
@@ -1409,7 +1411,8 @@ void FS_passive_output(screen_stat_handle_t handle)
}
print_buf=(char*)calloc(sizeof(char), print_buf_sz);
pos=print_buf;
- pos+=snprintf(pos, print_buf_sz-(pos-print_buf), "%s%s", draw_boundary, ctime(&current));
+ ctime_r(&current, ctime_buff);
+ pos+=snprintf(pos, print_buf_sz-(pos-print_buf), "%s%s", draw_boundary, ctime_buff);
pos--;//jump '\n' generate by ctime()
pos+=snprintf(pos, print_buf_sz-(pos-print_buf),"%s\n",draw_boundary);