/[LeafOK_CVS]/lbbs/src/common.c
ViewVC logotype

Diff of /lbbs/src/common.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.22 by sysadm, Sat May 17 11:30:09 2025 UTC Revision 1.23 by sysadm, Mon May 26 12:06:05 2025 UTC
# Line 14  Line 14 
14   *                                                                         *   *                                                                         *
15   ***************************************************************************/   ***************************************************************************/
16    
17    #define _POSIX_C_SOURCE 200112L
18    
19  #include "common.h"  #include "common.h"
20  #include "log.h"  #include "log.h"
21  #include "menu.h"  #include "menu.h"
# Line 62  static const char *weekday[] = { Line 64  static const char *weekday[] = {
64  // Common function  // Common function
65  const char *get_time_str(char *s, size_t len)  const char *get_time_str(char *s, size_t len)
66  {  {
67          time_t curtime = time(NULL);          time_t curtime;
68          struct tm *loctime;          struct tm local_tm;
         loctime = localtime(&curtime);  
69    
70          size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S 星期", loctime);          time(&curtime);
71            localtime_r(&curtime, &local_tm);
72            size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S 星期", &local_tm);
73    
74          if (j == 0 || j + strlen(weekday[loctime->tm_wday]) + 1 > len)          if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len)
75          {          {
76                  return NULL;                  return NULL;
77          }          }
78    
79          strncat(s, weekday[loctime->tm_wday], len - 1 - j);          strncat(s, weekday[local_tm.tm_wday], len - 1 - j);
80    
81          return s;          return s;
82  }  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1