From 8776b5e99bd8b31fbb199a92ef4b1afb414ce890 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 21 Jan 2016 01:36:07 +0000
Subject: [PATCH] Attempt to addres Bill McGarrity's reported error: 2016-01-20
 06:06:39 ERROR line 1836 renaming c:\fd\outbound\20060640.pk_ to
 c:\fd\outbound\20060640.pkt I think this is because the file 200606040.pkt
 already existed when the .pk_ temp file was created and thus the rename will
 fail (can't rename over an existing file) and then the packet is sent to the
 wrong link. When generating a packet name, keep incrementing until both the
 .pkt and .pk_ variants do not already exist. This should fix this scenario.

---
 src/sbbs3/sbbsecho.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/sbbs3/sbbsecho.c b/src/sbbs3/sbbsecho.c
index 05355e00a5..1aedd751f0 100644
--- a/src/sbbs3/sbbsecho.c
+++ b/src/sbbs3/sbbsecho.c
@@ -2827,6 +2827,7 @@ void seektonull(FILE *stream)
 char *pktname(BOOL temp)
 {
 	static char str[128];
+	static char tmp[128];
 	int i;
     time_t now;
     struct tm *tm;
@@ -2835,10 +2836,12 @@ char *pktname(BOOL temp)
 	for(i=0;i>=0;i++) {
 		now++;
 		tm=localtime(&now);
-		sprintf(str,"%s%02u%02u%02u%02u.%s",cfg.outbound,tm->tm_mday,tm->tm_hour
-			,tm->tm_min,tm->tm_sec,temp ? "pk_" : "pkt");
-		if(!fexist(str))				/* Add 1 second if name exists */
-			return(str); 
+		sprintf(str,"%s%02u%02u%02u%02u.pkt",cfg.outbound,tm->tm_mday,tm->tm_hour
+			,tm->tm_min,tm->tm_sec);
+		sprintf(tmp,"%s%02u%02u%02u%02u.pk_",cfg.outbound,tm->tm_mday,tm->tm_hour
+			,tm->tm_min,tm->tm_sec);
+		if(!fexist(str) && !fexist(tmp))				/* Add 1 second if name exists */
+			return(temp ? tmp : str); 
 	}
 	return(NULL);	/* This should never happen */
 }
-- 
GitLab