/[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.13 by sysadm, Sun May 4 14:54:55 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 23  Line 26 
26  // Version information  // Version information
27  char app_version[256] = "LBBS-devel version 1.0";  char app_version[256] = "LBBS-devel version 1.0";
28    
 // Global declaration for enviroment  
 char app_home_dir[256];  
 char app_temp_dir[256];  
   
29  // Global declaration for sockets  // Global declaration for sockets
30  int socket_server;  int socket_server;
31  int socket_client;  int socket_client;
# Line 35  char hostaddr_client[50]; Line 34  char hostaddr_client[50];
34  int port_server;  int port_server;
35  int port_client;  int port_client;
36    
 // Global declaration for database  
 char DB_host[256];  
 char DB_username[50];  
 char DB_password[50];  
 char DB_database[50];  
   
37  // Global declaration for system  // Global declaration for system
38  int SYS_exit;  int SYS_exit;
39  int SYS_child_process_count;  int SYS_child_process_count;
40    
41  // Common function  // Common function
42  const char *  const char *str_space(char *string, int length)
 str_space(char *string, int length)  
43  {  {
44          int i;          int i;
45          for (i = 0; i < length; i++)          for (i = 0; i < length; i++)
# Line 58  str_space(char *string, int length) Line 50  str_space(char *string, int length)
50          return string;          return string;
51  }  }
52    
53  const char *  const char *get_time_str(char *string, size_t length)
 get_time_str(char *string, size_t length)  
54  {  {
55          char week[10], buffer[256];          char week[20];
56            char buffer[LINE_BUFFER_LEN];
57          time_t curtime;          time_t curtime;
58          struct tm *loctime;          struct tm *loctime;
59    
60          curtime = time(NULL);          curtime = time(NULL);
61          loctime = localtime(&curtime);          loctime = localtime(&curtime);
62    
63          strftime(buffer, 256, "%Y年%m月%d日%H:%M:%S ", loctime);          strftime(buffer, sizeof(buffer), "%Y年%m月%d日%H:%M:%S ", loctime);
64    
65          switch (loctime->tm_wday)          switch (loctime->tm_wday)
66          {          {
67          case 0:          case 0:
68                  strcpy(week, "星期天");                  strncpy(week, "星期天", sizeof(week));
69                  break;                  break;
70          case 1:          case 1:
71                  strcpy(week, "星期一");                  strncpy(week, "星期一", sizeof(week));
72                  break;                  break;
73          case 2:          case 2:
74                  strcpy(week, "星期二");                  strncpy(week, "星期二", sizeof(week));
75                  break;                  break;
76          case 3:          case 3:
77                  strcpy(week, "星期三");                  strncpy(week, "星期三", sizeof(week));
78                  break;                  break;
79          case 4:          case 4:
80                  strcpy(week, "星期四");                  strncpy(week, "星期四", sizeof(week));
81                  break;                  break;
82          case 5:          case 5:
83                  strcpy(week, "星期五");                  strncpy(week, "星期五", sizeof(week));
84                  break;                  break;
85          case 6:          case 6:
86                  strcpy(week, "星期六");                  strncpy(week, "星期六", sizeof(week));
87                  break;                  break;
88          }          }
89          strcat(buffer, week);          strncat(buffer, week, sizeof(buffer) - 1 - strnlen(buffer, sizeof(buffer)));
90    
91          strncpy(string, buffer, length);          strncpy(string, buffer, length);
92    


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

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