From f2c41eedc0c43f9ea65c8e0fac0b642cb7a74b68 Mon Sep 17 00:00:00 2001 From: solar Date: Wed, 1 Dec 2010 22:01:42 +0000 Subject: [PATCH] Switched to tmpfile() where appropriate. git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@473 546481bc-9713-0410-bf18-d3337bbf4a3e --- Makefile | 2 -- functions/stdio/clearerr.c | 4 +--- functions/stdio/fprintf.c | 3 +-- functions/stdio/fputs.c | 4 +--- functions/stdio/fread.c | 6 ++---- functions/stdio/ftell.c | 6 ++---- functions/stdio/fwrite.c | 6 ++---- functions/stdio/setbuf.c | 7 ++----- functions/stdio/setvbuf.c | 10 +++------- functions/stdio/vfprintf.c | 3 +-- 10 files changed, 15 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 2fbf9c7..1d90200 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,6 @@ links: @echo "Linking platform/$(PLATFORM)..." @cd internals && ln -s ../platform/$(PLATFORM)/internals/_PDCLIB_config.h @cd includes && ln -s ../platform/$(PLATFORM)/includes/float.h - @cd testing && ln -s ../platform/$(PLATFORM)/testing/printf_reference.txt @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ ! -f $$basfile ]; then ln -s `ls ../../$$file` .; fi; done @@ -105,7 +104,6 @@ unlink: @echo "Unlinking platform files..." @if [ -f internals/_PDCLIB_config.h ]; then rm internals/_PDCLIB_config.h; fi @if [ -f includes/float.h ]; then rm includes/float.h; fi - @if [ -f testing/printf_reference.txt ]; then rm testing/printf_reference.txt; fi @cd functions/_PDCLIB && for file in $(PATCHFILES1); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done @cd functions/stdlib && for file in $(PATCHFILES2); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done @cd functions/stdio && for file in $(PATCHFILES3); do basfile=`basename $$file`; if [ -f $$basfile ]; then rm $$basfile; fi; done diff --git a/functions/stdio/clearerr.c b/functions/stdio/clearerr.c index 810e62d..af25029 100644 --- a/functions/stdio/clearerr.c +++ b/functions/stdio/clearerr.c @@ -23,8 +23,7 @@ void clearerr( struct _PDCLIB_file_t * stream ) int main( void ) { FILE * fh; - remove( "testing/testfile" ); - TESTCASE( ( fh = fopen( "testing/testfile", "w+" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); /* Flags should be clear */ TESTCASE( ! ferror( fh ) ); TESTCASE( ! feof( fh ) ); @@ -46,7 +45,6 @@ int main( void ) TESTCASE( ! ferror( fh ) ); TESTCASE( ! feof( fh ) ); TESTCASE( fclose( fh ) == 0 ); - remove( "testing/testfile" ); return TEST_RESULTS; } diff --git a/functions/stdio/fprintf.c b/functions/stdio/fprintf.c index 38fb9b8..bac19bc 100644 --- a/functions/stdio/fprintf.c +++ b/functions/stdio/fprintf.c @@ -36,10 +36,9 @@ int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCL int main( void ) { FILE * target; - TESTCASE( ( target = fopen( "testing/testfile", "wb+" ) ) != NULL ); + TESTCASE( ( target = tmpfile() ) != NULL ); #include "printf_testcases.incl" TESTCASE( fclose( target ) == 0 ); - TESTCASE( remove( "testing/testfile" ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fputs.c b/functions/stdio/fputs.c index 1df0ebf..2c5e1fa 100644 --- a/functions/stdio/fputs.c +++ b/functions/stdio/fputs.c @@ -53,8 +53,7 @@ int main( void ) { char const * const message = "SUCCESS testing fputs()"; FILE * fh; - remove( testfile ); - TESTCASE( ( fh = fopen( testfile, "w+" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fputs( message, fh ) >= 0 ); rewind( fh ); for ( size_t i = 0; i < 23; ++i ) @@ -62,7 +61,6 @@ int main( void ) TESTCASE( fgetc( fh ) == message[i] ); } TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fread.c b/functions/stdio/fread.c index c457d48..51e6a7b 100644 --- a/functions/stdio/fread.c +++ b/functions/stdio/fread.c @@ -48,12 +48,10 @@ size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PD int main( void ) { FILE * fh; - remove( testfile ); - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 ); - TESTCASE( fclose( fh ) == 0 ); /* TODO: Add readback test. */ - TESTCASE( remove( testfile ) == 0 ); + TESTCASE( fclose( fh ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/ftell.c b/functions/stdio/ftell.c index 09dd17f..892c7b2 100644 --- a/functions/stdio/ftell.c +++ b/functions/stdio/ftell.c @@ -48,8 +48,7 @@ int main( void ) */ char * buffer = (char*)malloc( 4 ); FILE * fh; - remove( testfile ); - TESTCASE( ( fh = fopen( testfile, "w+" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 ); TESTCASE( fputc( '1', fh ) == '1' ); TESTCASE( fputc( '2', fh ) == '2' ); @@ -75,9 +74,8 @@ int main( void ) TESTCASE_NOREG( fh->bufidx == 0 ); /* Reading back first character after rewind for basic read check */ TESTCASE( fgetc( fh ) == '1' ); - TESTCASE( fclose( fh ) == 0 ); /* TODO: t.b.c. */ - remove( testfile ); + TESTCASE( fclose( fh ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fwrite.c b/functions/stdio/fwrite.c index ca43967..4eabd22 100644 --- a/functions/stdio/fwrite.c +++ b/functions/stdio/fwrite.c @@ -87,12 +87,10 @@ size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, str int main( void ) { FILE * fh; - remove( testfile ); - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fwrite( "SUCCESS testing fwrite()\n", 1, 25, fh ) == 25 ); - TESTCASE( fclose( fh ) == 0 ); /* TODO: Add readback test. */ - TESTCASE( remove( testfile ) == 0 ); + TESTCASE( fclose( fh ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/setbuf.c b/functions/stdio/setbuf.c index 46db8e3..fe83277 100644 --- a/functions/stdio/setbuf.c +++ b/functions/stdio/setbuf.c @@ -34,21 +34,18 @@ int main( void ) #ifndef REGTEST char buffer[ BUFSIZ + 1 ]; FILE * fh; - remove( testfile ); /* full buffered */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); setbuf( fh, buffer ); TESTCASE( fh->buffer == buffer ); TESTCASE( fh->bufsize == BUFSIZ ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF ); TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); /* not buffered */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); setbuf( fh, NULL ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF ); TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); #else puts( " NOTEST setbuf() test driver is PDCLib-specific." ); #endif diff --git a/functions/stdio/setvbuf.c b/functions/stdio/setvbuf.c index 2c33338..ecb0be5 100644 --- a/functions/stdio/setvbuf.c +++ b/functions/stdio/setvbuf.c @@ -82,29 +82,25 @@ int main( void ) #ifndef REGTEST char buffer[ BUFFERSIZE ]; FILE * fh; - remove( testfile ); /* full buffered, user-supplied buffer */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( setvbuf( fh, buffer, _IOFBF, BUFFERSIZE ) == 0 ); TESTCASE( fh->buffer == buffer ); TESTCASE( fh->bufsize == BUFFERSIZE ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF ); TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); /* line buffered, lib-supplied buffer */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( setvbuf( fh, NULL, _IOLBF, BUFFERSIZE ) == 0 ); TESTCASE( fh->buffer != NULL ); TESTCASE( fh->bufsize == BUFFERSIZE ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOLBF ); TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); /* not buffered, user-supplied buffer */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( setvbuf( fh, buffer, _IONBF, BUFFERSIZE ) == 0 ); TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF ); TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); #else puts( " NOTEST setvbuf() test driver is PDCLib-specific." ); #endif diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 7ab3167..44c8635 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -69,10 +69,9 @@ static int testprintf( FILE * stream, const char * format, ... ) int main( void ) { FILE * target; - TESTCASE( ( target = fopen( testfile, "wb+" ) ) != NULL ); + TESTCASE( ( target = tmpfile() ) != NULL ); #include "printf_testcases.incl" TESTCASE( fclose( target ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } -- 2.30.2