changeset 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 b997de027717
children f1c024b2b835
files smpp-trx-sa/log.c smpp-trx-sa/main.c
diffstat 2 files changed, 15 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/smpp-trx-sa/log.c	Tue Aug 15 23:23:57 2023 -0800
+++ b/smpp-trx-sa/log.c	Wed Oct 11 17:34:45 2023 -0800
@@ -11,28 +11,15 @@
 
 extern FILE *logF;
 extern time_t curtime;
+extern char fmt_time[32];
 extern int init_done;
 
-static char fmt_time[32];
-
-static void
-format_time()
-{
-	struct tm *tm;
-
-	tm = gmtime(&curtime);
-	sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ",
-		tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-		tm->tm_hour, tm->tm_min, tm->tm_sec);
-}
-
 void
 log_fatal_error(cause)
 	char *cause;
 {
 	if (!init_done)
 		return;
-	format_time();
 	fprintf(logF, "\n%s %s\n", fmt_time, cause);
 }
 
@@ -72,7 +59,6 @@
 	u_char *pdu;
 	unsigned pdulen;
 {
-	format_time();
 	fprintf(logF, "\n%s Received PDU:\n", fmt_time);
 	pdu_hexdump(pdu, pdulen);
 }
@@ -82,7 +68,6 @@
 	u_char *pdu;
 	unsigned pdulen;
 {
-	format_time();
 	fprintf(logF, "\n%s Sent PDU:\n", fmt_time);
 	pdu_hexdump(pdu, pdulen);
 }
--- a/smpp-trx-sa/main.c	Tue Aug 15 23:23:57 2023 -0800
+++ b/smpp-trx-sa/main.c	Wed Oct 11 17:34:45 2023 -0800
@@ -21,8 +21,20 @@
 
 FILE *logF;
 time_t curtime;
+char fmt_time[32];
 int init_done;
 
+static void
+format_time()
+{
+	struct tm *tm;
+
+	tm = gmtime(&curtime);
+	sprintf(fmt_time, "%d-%02d-%02dT%02d:%02d:%02dZ",
+		tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+		tm->tm_hour, tm->tm_min, tm->tm_sec);
+}
+
 main(argc, argv)
 	char **argv;
 {
@@ -63,6 +75,7 @@
 	if (tcpsock > max_fd)
 		max_fd = tcpsock;
 	time(&curtime);
+	format_time();
 	send_bind_req(argv[2], argv[3]);
 	init_done = 1;
 	/* main select loop */
@@ -79,6 +92,7 @@
 			exit(1);
 		}
 		time(&curtime);
+		format_time();
 		if (FD_ISSET(tcpsock, &fds))
 			tcpsock_select_handler();
 		if (FD_ISSET(localsock, &fds))