]> pd.if.org Git - pdclib/commitdiff
Streams are now closed on program exit. (I hope; untested.)
authorsolar <unknown>
Sat, 19 Jun 2010 20:26:50 +0000 (20:26 +0000)
committersolar <unknown>
Sat, 19 Jun 2010 20:26:50 +0000 (20:26 +0000)
Makefile
functions/_PDCLIB/closeall.c [new file with mode: 0644]
functions/stdlib/exit.c
internals/_PDCLIB_int.h

index 3331fa51dac649988e8df5bc44009edd17e5d5ab..9894792dc3b028a35a74b0e50cc4c738254a9e67 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c")
 # All header files of the project
 HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h")
 # All .c files in functions/_PDCLIB that do not have a regression test driver
-INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename
+INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall
 # All object files in the library
 OBJFILES := $(patsubst %.c,%.o,$(SRCFILES))
 # All test drivers (.t)
diff --git a/functions/_PDCLIB/closeall.c b/functions/_PDCLIB/closeall.c
new file mode 100644 (file)
index 0000000..3523f8c
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/* _PDCLIB_closeall( void )
+
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
+
+#include <stdio.h>
+
+extern struct _PDCLIB_file_t * _PDCLIB_filelist;
+
+void _PDCLIB_closeall( void )
+{
+    struct _PDCLIB_file_t * stream = _PDCLIB_filelist;
+    struct _PDCLIB_file_t * next;
+    while ( stream != NULL )
+    {
+        next = stream->next;
+        fclose( stream );
+        stream = next;
+    }
+}
+
+#ifdef TEST
+#include <_PDCLIB_test.h>
+
+int main( void )
+{
+    TESTCASE( NO_TESTDRIVER );
+    return TEST_RESULTS;
+}
+
+#endif
+
index 8d5aa174bec08f901c1191390e9de3a6515adfd2..2dbb35c600f37c8f9ce846f8b761ef02065708d7 100644 (file)
@@ -19,7 +19,7 @@
 */
 #define NUMBER_OF_SLOTS 40
 
-void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void );
+void (*_PDCLIB_regstack[ NUMBER_OF_SLOTS ])( void ) = { _PDCLIB_closeall };
 size_t _PDCLIB_regptr = NUMBER_OF_SLOTS;
 
 void exit( int status )
index 9c67f277ee4fec47ba1abc2e46e4329fd55f4a8c..f6fedd16405b0090d351a81d5dab7da123d10a02 100644 (file)
@@ -382,6 +382,9 @@ int _PDCLIB_prepread( struct _PDCLIB_file_t * stream );
 */
 int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream );
 
+/* Closing all streams on program exit */
+void _PDCLIB_closeall( void );
+
 /* -------------------------------------------------------------------------- */
 /* errno                                                                      */
 /* -------------------------------------------------------------------------- */