]> pd.if.org Git - pdclib/blobdiff - platform/example/functions/stdio/tmpfile.c
Whitespace cleanups.
[pdclib] / platform / example / functions / stdio / tmpfile.c
index 44b975d36b13a96f2bf8d63717cd680ec230201f..cb942ff345114d58680939725c8777cacf2d230b 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /* tmpfile( void )
 
    This file is part of the Public Domain C Library (PDCLib).
 
 #ifndef REGTEST
 
+#include "_PDCLIB_glue.h"
+
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include <_PDCLIB_glue.h>
-
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -49,7 +47,7 @@ struct _PDCLIB_file_t * tmpfile( void )
            generate the filename candidate, which is *also* platform-dependent.
         */
         unsigned int random;
-        fscanf( randomsource, "%u", &random ); 
+        fscanf( randomsource, "%u", &random );
         sprintf( filename, "/tmp/%u.tmp", random );
         /* Check if file of this name exists. Note that fopen() is a very weak
            check, which does not take e.g. access permissions into account
@@ -88,13 +86,29 @@ struct _PDCLIB_file_t * tmpfile( void )
 #endif
 
 #ifdef TEST
-#include <_PDCLIB_test.h>
 
-int main()
+#include "_PDCLIB_test.h"
+
+#include <string.h>
+
+int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    FILE * fh;
+#ifndef REGTEST
+    char filename[ L_tmpnam ];
+    FILE * fhtest;
+#endif
+    TESTCASE( ( fh = tmpfile() ) != NULL );
+    TESTCASE( fputc( 'x', fh ) == 'x' );
+    /* Checking that file is actually there */
+    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
+    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
+    TESTCASE_NOREG( fclose( fhtest ) == 0 );
+    /* Closing tmpfile */
+    TESTCASE( fclose( fh ) == 0 );
+    /* Checking that file was deleted */
+    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
     return TEST_RESULTS;
 }
 
 #endif
-