Message-Id: <3.0.1.32.19971201081956.007f8330@yacker.xiotech.com> Date: Mon, 01 Dec 1997 08:19:56 -0600 To: djgpp-workers AT delorie DOT com From: Randy Maas Subject: Patch to fsext.c to go with the exit.c patch Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_881007596==_" Precedence: bulk --=====================_881007596==_ Content-Type: text/plain; charset="us-ascii" This patch is relative the fsext.c patch posted 12/1/1997. It adds a simple function to be called during exit. Randy randym AT acm DOT org --=====================_881007596==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="fsext.dif" *** src/libc/fsext/fsext.c~1 Mon Dec 1 07:49:10 1997 --- src/libc/fsext/fsext.c Mon Dec 1 08:09:52 1997 *************** *** 30,33 **** --- 30,36 ---- static __FSEXT_func_rec *func_list; + extern void (*__FSEXT_exit_hook)(void); + static void __FSEXT_close_all(void); + static void init(void) *************** *** 39,42 **** --- 42,48 ---- num_fds = 0; func_list = 0; + + /* Attach our hook to close all of the remaining open extensions. */ + __FSEXT_exit_hook = __FSEXT_close_all; } *************** *** 104,105 **** --- 110,133 ---- return 1; } + + /* + This is an exit helper routine. This should be called *after* all of the + other IO in libc has been closed -- that is, so that anything will opened + with fopen can be fclose'd. + + Other note: *If* a fsext uses a fopen'd file, it gets in a race condition + at exit. That is, the file the fsext fopen'd may be closed before the + fsext. This is more of a bug with *bad* programs not good ones. + */ + + static void + __FSEXT_close_all (void) + { + int I; + + if (!func_list) return; + for (I = 0; I < num_fds; I++) + if (func_list[I].func) + close(I); + } + --=====================_881007596==_ Content-Type: text/plain; charset="us-ascii" --=====================_881007596==_--