From 3b050126245408b7d9e30f638b5920388f5d4408 Mon Sep 17 00:00:00 2001 From: Ingo Paschke Date: Mon, 6 Jul 2026 08:09:12 +0200 Subject: [PATCH] sfstruct: buffered stdio writes on amiga and atari st Enable USE_BUFFERING for the structlevel savefile write path on AMIGA and TOS via a new SFSTRUCT_BUFFERING config define, with a 16 KB setvbuf on the fdopen'd write stream so many small bwrite()s coalesce into few dos.library Write() packets. Leaves mread() unbuffered. Mainline UNIX/WIN32 are unchanged (setvbuf is gated on the new define); MAC68K is not enabled, avoiding fdopen()/fclose() on its remapped non-libc file handles. --- include/amiconf.h | 1 + outdated/include/tosconf.h | 1 + src/sfstruct.c | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/amiconf.h b/include/amiconf.h index 593f3e470..51342e44f 100644 --- a/include/amiconf.h +++ b/include/amiconf.h @@ -73,6 +73,7 @@ extern void ami_wininit_data(int); #define HACKFONT /* Use special hack.font */ #define MAIL /* Get mail at unexpected occasions */ #define AMIFLUSH /* toss typeahead (select flush in .cnf) */ +#define SFSTRUCT_BUFFERING /* buffered stdio writes for structlevel files */ /* new window system options */ /* WRONG - AMIGA_INTUITION should go away */ diff --git a/outdated/include/tosconf.h b/outdated/include/tosconf.h index 1ea893f4d..90ffb4fcb 100644 --- a/outdated/include/tosconf.h +++ b/outdated/include/tosconf.h @@ -42,6 +42,7 @@ #ifdef MINT #define SUSPEND /* allow suspending the game */ #endif +#define SFSTRUCT_BUFFERING /* buffered stdio writes for structlevel files */ #ifndef TERMLIB #define ANSI_DEFAULT /* use vt52 by default */ diff --git a/src/sfstruct.c b/src/sfstruct.c index 00888d8d8..4eb9a8ed2 100644 --- a/src/sfstruct.c +++ b/src/sfstruct.c @@ -320,7 +320,7 @@ static long floc = 0L; staticfn int getidx(int, int); -#if defined(UNIX) || defined(WIN32) +#if defined(UNIX) || defined(WIN32) || defined(SFSTRUCT_BUFFERING) #define USE_BUFFERING #endif @@ -329,6 +329,9 @@ struct restore_info restoreinfo = { }; #define MAXFD 5 +#ifdef SFSTRUCT_BUFFERING +#define BWBUFSZ 16384 +#endif enum {NOFLG = 0, NOSLOT = 1}; static int bw_sticky[MAXFD] = {-1,-1,-1,-1,-1}; static int bw_buffered[MAXFD] = {0,0,0,0,0}; @@ -431,6 +434,10 @@ bufon(int fd) if (!bw_FILE[idx]) { if ((bw_FILE[idx] = fdopen(fd, "w")) == 0) panic("buffering of file %d failed", fd); +#ifdef SFSTRUCT_BUFFERING + (void) setvbuf(bw_FILE[idx], (char *) 0, _IOFBF, + (size_t) BWBUFSZ); +#endif } bw_buffered[idx] = (bw_FILE[idx] != 0); #else