/[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.9 by sysadm, Mon Apr 28 03:30:59 2025 UTC Revision 1.12 by sysadm, Fri May 2 03:32:19 2025 UTC
# Line 15  Line 15 
15   *                                                                         *   *                                                                         *
16   ***************************************************************************/   ***************************************************************************/
17    
18    #include "common.h"
19    #include "log.h"
20  #include "menu.h"  #include "menu.h"
21    #include <string.h>
22  #include <time.h>  #include <time.h>
23  #include <sys/types.h>  #include <sys/types.h>
24  #include <sys/wait.h>  #include <sys/wait.h>
# Line 35  char hostaddr_client[50]; Line 38  char hostaddr_client[50];
38  int port_server;  int port_server;
39  int port_client;  int port_client;
40    
 // Global declaration for database  
 char DB_host[256];  
 char DB_username[50];  
 char DB_password[50];  
 char DB_database[50];  
   
41  // Global declaration for system  // Global declaration for system
42  int SYS_exit;  int SYS_exit;
43  int SYS_child_process_count;  int SYS_child_process_count;
44    
45  // Common function  // Common function
46  const char *  const char *str_space(char *string, int length)
 str_space(char *string, int length)  
47  {  {
48          int i;          int i;
49          for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
# Line 58  str_space(char *string, int length) Line 54  str_space(char *string, int length)
54          return string;          return string;
55  }  }
56    
57  const char *  const char *get_time_str(char *string, size_t length)
 get_time_str(char *string, size_t length)  
58  {  {
59          char week[10], buffer[256];          char week[20];
60            char buffer[LINE_BUFFER_LEN];
61          time_t curtime;          time_t curtime;
62          struct tm *loctime;          struct tm *loctime;
63    
64          curtime = time(NULL);          curtime = time(NULL);
65          loctime = localtime(&curtime);          loctime = localtime(&curtime);
66    
67          strftime(buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          strftime(buffer, sizeof(buffer), "%Y年%m月%d日%H:%M:%S ", loctime);
68    
69          switch (loctime->tm_wday)          switch (loctime->tm_wday)
70          {          {
71          case 0:          case 0:
72                  strcpy(week, "星期天");                  strncpy(week, "星期天", sizeof(week));
73                  break;                  break;
74          case 1:          case 1:
75                  strcpy(week, "星期一");                  strncpy(week, "星期一", sizeof(week));
76                  break;                  break;
77          case 2:          case 2:
78                  strcpy(week, "星期二");                  strncpy(week, "星期二", sizeof(week));
79                  break;                  break;
80          case 3:          case 3:
81                  strcpy(week, "星期三");                  strncpy(week, "星期三", sizeof(week));
82                  break;                  break;
83          case 4:          case 4:
84                  strcpy(week, "星期四");                  strncpy(week, "星期四", sizeof(week));
85                  break;                  break;
86          case 5:          case 5:
87                  strcpy(week, "星期五");                  strncpy(week, "星期五", sizeof(week));
88                  break;                  break;
89          case 6:          case 6:
90                  strcpy(week, "星期六");                  strncpy(week, "星期六", sizeof(week));
91                  break;                  break;
92          }          }
93          strcat(buffer, week);          strncat(buffer, week, sizeof(week));
94    
95          strncpy(string, buffer, length);          strncpy(string, buffer, length);
96    


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

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