comparison smpp-trx-sa/log.c @ 261:a375639e4190

smpp-trx-sa: refactor time formatting code
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 11 Oct 2023 17:34:45 -0800
parents 9d6e8d99d2b1
children f1c024b2b835
comparison
equal deleted inserted replaced
260:b997de027717 261:a375639e4190
9 #include <strings.h> 9 #include <strings.h>
10 #include <time.h> 10 #include <time.h>
11 11
12 extern FILE *logF; 12 extern FILE *logF;
13 extern time_t curtime; 13 extern time_t curtime;
14 extern char fmt_time[32];
14 extern int init_done; 15 extern int init_done;
15
16 static char fmt_time[32];
17
18 static void
19 format_time()
20 {
21 struct tm *tm;
22
23 tm = gmtime(&curtime);
24 sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ",
25 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
26 tm->tm_hour, tm->tm_min, tm->tm_sec);
27 }
28 16
29 void 17 void
30 log_fatal_error(cause) 18 log_fatal_error(cause)
31 char *cause; 19 char *cause;
32 { 20 {
33 if (!init_done) 21 if (!init_done)
34 return; 22 return;
35 format_time();
36 fprintf(logF, "\n%s %s\n", fmt_time, cause); 23 fprintf(logF, "\n%s %s\n", fmt_time, cause);
37 } 24 }
38 25
39 static void 26 static void
40 pdu_hexdump(pdu, pdulen) 27 pdu_hexdump(pdu, pdulen)
70 void 57 void
71 log_rx_pdu(pdu, pdulen) 58 log_rx_pdu(pdu, pdulen)
72 u_char *pdu; 59 u_char *pdu;
73 unsigned pdulen; 60 unsigned pdulen;
74 { 61 {
75 format_time();
76 fprintf(logF, "\n%s Received PDU:\n", fmt_time); 62 fprintf(logF, "\n%s Received PDU:\n", fmt_time);
77 pdu_hexdump(pdu, pdulen); 63 pdu_hexdump(pdu, pdulen);
78 } 64 }
79 65
80 void 66 void
81 log_sent_pdu(pdu, pdulen) 67 log_sent_pdu(pdu, pdulen)
82 u_char *pdu; 68 u_char *pdu;
83 unsigned pdulen; 69 unsigned pdulen;
84 { 70 {
85 format_time();
86 fprintf(logF, "\n%s Sent PDU:\n", fmt_time); 71 fprintf(logF, "\n%s Sent PDU:\n", fmt_time);
87 pdu_hexdump(pdu, pdulen); 72 pdu_hexdump(pdu, pdulen);
88 } 73 }