From 09f5e87ef04447a93f47c8d5d0cc820906d9188e Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 12 Jan 2019 08:11:13 +0000
Subject: [PATCH] Optimized getfiledat(): rather than calling both flength()
 and fdate() (which both call stat()), just call stat() once and use the
 result for both file size and date/time.

---
 src/sbbs3/filedat.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/sbbs3/filedat.c b/src/sbbs3/filedat.c
index 812ef8e2ec..b845a1e8b9 100644
--- a/src/sbbs3/filedat.c
+++ b/src/sbbs3/filedat.c
@@ -72,18 +72,15 @@ BOOL DLLCALL getfiledat(scfg_t* cfg, file_t* f)
 	getrec(buf,F_CDT,LEN_FCDT,str);
 	f->cdt=atol(str);
 
-	if(!f->size) {					/* only read disk if this is null */
-			getfilepath(cfg,f,str);
-			if((f->size=(long)flength(str))>=0)
-				f->date=(time32_t)fdate(str);
-	/*
-			}
-		else {
-			f->size=f->cdt;
-			f->date=0; 
-			}
-	*/
-			}
+	if(f->size == 0) {					// only read disk if f->size == 0
+		struct stat st;
+		getfilepath(cfg,f,str);
+		if(stat(str, &st) == 0) {
+			f->size = st.st_size;
+			f->date = (time32_t)st.st_mtime;
+		} else
+			f->size = -1;	// indicates file does not exist
+	}
 #if 0
 	if((f->size>0L) && cur_cps)
 		f->timetodl=(ushort)(f->size/(ulong)cur_cps);
-- 
GitLab