ソースを参照

Update Session Manager

Rafal Kupiec 5年前
コミット
8d93137639
1個のファイルの変更6行の追加64行の削除
  1. 6
    64
      sessmgr.c

+ 6
- 64
sessmgr.c ファイルの表示

@@ -43,71 +43,11 @@ char* get_admin_hash(const char* username) {
43 43
 
44 44
 char* get_cookie_time(time_t t) {
45 45
 	struct tm* utc = gmtime(&t);
46
-	char wday[4];
47
-	char month[4];
48
-	switch(utc->tm_wday) {
49
-		case 0:
50
-			sprintf(wday, "Sun");
51
-			break;
52
-		case 1:
53
-			sprintf(wday, "Mon");
54
-			break;
55
-		case 2:
56
-			sprintf(wday, "Tue");
57
-			break;
58
-		case 3:
59
-			sprintf(wday, "Wed");
60
-			break;
61
-		case 4:
62
-			sprintf(wday, "Thu");
63
-			break;
64
-		case 5:
65
-			sprintf(wday, "Fri");
66
-			break;
67
-		case 6:
68
-			sprintf(wday, "Sat");
69
-			break;
70
-		}
71
-	switch(utc->tm_mon) {
72
-		case 0:
73
-			sprintf(month, "Jan");
74
-			break;
75
-		case 1:
76
-			sprintf(month, "Feb");
77
-			break;
78
-		case 2:
79
-			sprintf(month, "Mar");
80
-			break;
81
-		case 3:
82
-			sprintf(month, "Apr");
83
-			break;
84
-		case 4:
85
-			sprintf(month, "May");
86
-			break;
87
-		case 5:
88
-			sprintf(month, "Jun");
89
-			break;
90
-		case 6:
91
-			sprintf(month, "Jul");
92
-			break;
93
-		case 7:
94
-			sprintf(month, "Aug");
95
-			break;
96
-		case 8:
97
-			sprintf(month, "Sep");
98
-			break;
99
-		case 9:
100
-			sprintf(month, "Oct");
101
-			break;
102
-		case 10:
103
-			sprintf(month, "Nov");
104
-			break;
105
-		case 11:
106
-			sprintf(month, "Dec");
107
-			break;
108
-	}
46
+	char *wdays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
47
+	char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
109 48
 	char utc_str[200];
110
-	sprintf(utc_str, "%s, %d %s %d %02d:%02d:%02d UTC", wday, utc->tm_mday, month, (utc->tm_year + 1900), utc->tm_hour, utc->tm_min, utc->tm_sec);
49
+
50
+	sprintf(utc_str, "%s, %d %s %d %02d:%02d:%02d UTC", wdays[utc->tm_wday], utc->tm_mday, months[utc->tm_mon], (utc->tm_year + 1900), utc->tm_hour, utc->tm_min, utc->tm_sec);
111 51
 	return safe_strdup(utc_str);
112 52
 }
113 53
 
@@ -252,6 +192,7 @@ int main(int argc, char **argv) {
252 192
 
253 193
 void* safe_malloc(size_t size) {
254 194
 	void* val = malloc(size);
195
+
255 196
 	if(val == NULL) {
256 197
 		fprintf(stderr, "ERROR: MALLOC FAILURE!\n");
257 198
 		exit(1);
@@ -291,6 +232,7 @@ char* safe_strcat(int num_strs, ...) {
291 232
 
292 233
 char* safe_strdup(const char* str) {
293 234
 	char* new_str = NULL;
235
+
294 236
 	if(str != NULL) {
295 237
 		new_str = strdup(str);
296 238
 		if(new_str == NULL) {

読み込み中…
キャンセル
保存