Mail Archives: djgpp-workers/1997/12/01/09:16:51
--=====================_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==_--
- Raw text -